Approaches to function SFINAE in C++

I have seen method 2 used more often in stackoverflow, but I prefer method 1. Suggestion: prefer method 2. Both methods work with single functions. The problem arises when you have more than a function, with the same signature, and you want enable only one function of the set. Suppose that you want enable foo(), … Read more

Is the “lazy man’s enable_if” legal C++?

[temp.over.link]/6 specifies when two function template declarations are overloads. That is done by defining equivalency of two function templates as follows: Two function templates are equivalent if they [..] have return types [..] that are equivalent using the rules described above to compare expressions involving template parameters. The “rules described above” are Two expressions involving … Read more

Why do constant expressions have an exclusion for undefined behavior?

The wording is actually the subject of defect report #1313 which says: The requirements for constant expressions do not currently, but should, exclude expressions that have undefined behavior, such as pointer arithmetic when the pointers do not point to elements of the same array. The resolution being the current wording we have now, so this … Read more

How to check whether operator== exists?

C++03 The following trick works and it can be used for all such operators: namespace CHECK { class No { bool b[2]; }; template<typename T, typename Arg> No operator== (const T&, const Arg&); bool Check (…); No& Check (const No&); template <typename T, typename Arg = T> struct EqualExists { enum { value = (sizeof(Check(*(T*)(0) … Read more

How to detect whether there is a specific member variable in class?

Here is a solution simpler than Johannes Schaub – litb’s one. It requires C++11. #include <type_traits> template <typename T, typename = int> struct HasX : std::false_type { }; template <typename T> struct HasX <T, decltype((void) T::x, 0)> : std::true_type { }; Update: A quick example and the explanation on how this works. For these types: … Read more

How is std::is_function implemented?

Let’s go over the conditions as they appear: If const T isn’t const (const doesn’t really apply to function types since functions aren’t objects), and T isn’t a reference (const doesn’t apply to references either for the same reason), it’s a function type. int (or any other non-function-non-reference type) wouldn’t fit in because is_const<const int>::value … Read more

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