// PR c++/87748 // { dg-do compile { target c++11 } } template T&& declval(); template struct enable_if; template struct enable_if { typedef T type; }; struct true_type { static const bool value = true; }; struct false_type { static const bool value = false; }; struct string { string (const char *p); }; /// Template to map all type arguments to void, useful for SFINAE, see also WG21 N3911. template using void_t = void; /// REQUIRES - Simplified version of enable_if<> to use SFINAE in function templates. template using REQUIRES = typename ::enable_if::type; /// DerivesString - Check if @a T is of type 'string'. template struct DerivesString { static const int value = __is_same_as (T, string); }; /// Has__aida_visit__ - Check if @a T provides a member template __aida_visit__<>(Visitor). template struct Has__aida_visit__ : false_type {}; template struct Has__aida_visit__().template __aida_visit__ (*(V*) 0)) >> : true_type {}; struct Foo { template void __accept__ (V*); }; /// Base template for Visitor classes, dispatches operator() to visit_() methods. template class VisitorDispatcher { DerivedVisitor* derived () { return static_cast (this); } protected: typedef const char* Name; ///< Member name argument type for visit() methods. public: // dispatch for calls like: visitor (field, "field"); template::value) > = true> void operator() (A &a, Name n) { return derived()->visit_string (a, n); } }; class PspecVisitor : public VisitorDispatcher { public: void visit_string (::string &a, Name name); }; int main (int argc, char *argv[]) { #ifdef WITHASSERT // define this to fix g++-8.1.1 static_assert (Has__aida_visit__::value == false, ""); #endif PspecVisitor v; string str ("A string"); v (str, "some_string"); static_assert (Has__aida_visit__::value == false, ""); return 0; } // g++ -std=gnu++14 -Wall -O2 aidavisit.cc && ./a.out