Checking for existence of C++ member function, possibly protected

I’ve put some thoughts on how to implement the things you requested and came to a totally different conclusion. The problem at hand is very interesting: How do I check whether a class implements a hidden interface. Unfortunately the problem is a contradiction to the liskov substitution principle; one of the core object oriented principles. … Read more

How to write a type trait `is_container` or `is_vector`?

Look, another SFINAE-based solution for detecting STL-like containers: template<typename T, typename _ = void> struct is_container : std::false_type {}; template<typename… Ts> struct is_container_helper {}; template<typename T> struct is_container< T, std::conditional_t< false, is_container_helper< typename T::value_type, typename T::size_type, typename T::allocator_type, typename T::iterator, typename T::const_iterator, decltype(std::declval<T>().size()), decltype(std::declval<T>().begin()), decltype(std::declval<T>().end()), decltype(std::declval<T>().cbegin()), decltype(std::declval<T>().cend()) >, void > > : public std::true_type {}; … Read more

How do we use void_t for SFINAE?

1. Primary Class Template When you write has_member<A>::value, the compiler looks up the name has_member and finds the primary class template, that is, this declaration: template< class , class = void > struct has_member; (In the OP, that’s written as a definition.) The template argument list <A> is compared to the template parameter list of … Read more

SFINAE working in return type but not as template parameter

You should take a look at 14.5.6.1 Function template overloading (C++11 standard) where function templates equivalency is defined. In short, default template arguments are not considered, so in the 1st case you have the same function template defined twice. In the 2nd case you have expression referring template parameters used in the return type (again … Read more

using SFINAE for template class specialisation

IF the original declaration of User<> can be adapted to template<typename, typename=std::true_type> class User; then we can find a solution (following Luc Danton’s comment, instead of using std::enable_if) template<typename> struct is_Data : std::false_type {}; template<typename T> struct is_Data<Data<T>> : std::true_type {}; template<typename T> class User<T, typename is_Data<T>::type > { /* … */ }; However, this … Read more

Why does enable_if_t in template arguments complains about redefinitions?

Let’s remove some code. template< class T, class U/* = std::enable_if_t<std::is_same<int, T>::value>*/ > void g() { } template< class T, class U/* = std::enable_if_t<std::is_same<double, T>::value>*/ > void g() { } would you be surprised if the compiler rejected the two above templates? They are both template functions of “type” template<class,class>void(). The fact that the 2nd … Read more

What exactly is the “immediate context” mentioned in the C++11 Standard for which SFINAE applies?

If you consider all the templates and implicitly-defined functions that are needed to determine the result of the template argument substitution, and imagine they are generated first, before substitution starts, then any errors occurring in that first step are not in the immediate context, and result in hard errors. If all those instantiations and implicitly-definitions … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)