How to test whether class B is derived from template family of classes

Try this: #include <type_traits> template <typename T, template <typename> class Tmpl> // #1 see note struct is_derived { typedef char yes[1]; typedef char no[2]; static no & test(…); template <typename U> static yes & test(Tmpl<U> const &); static bool const value = sizeof(test(std::declval<T>())) == sizeof(yes); }; Usage: #include <iostream> template<class T> struct X {}; struct … Read more

In which versions of the C++ standard does “(i+=10)+=10” have undefined behaviour?

tl;dr: The sequence of the modifications and reads performed in (i+=10)+=10 is well defined in both C++98 and C++11, however in C++98 this is not sufficient to make the behavior defined. In C++98 multiple modifications to the same object without an intervening sequence-point results in undefined behavior, even when the order of those modifications is … Read more

How to write `is_complete` template?

The answer given by Alexey Malistov can be used on MSVC with a minor modification: namespace { template<class T, int discriminator> struct is_complete { static T & getT(); static char (& pass(T))[2]; static char pass(…); static const bool value = sizeof(pass(getT()))==2; }; } #define IS_COMPLETE(X) is_complete<X,__COUNTER__>::value Unfortunately, the __COUNTER__ predefined macro is not part of … Read more

Purpose of Trigraph sequences in C++?

This question (about the closely related digraphs) has the answer. It boils down to the fact that the ISO 646 character set doesn’t have all the characters of the C syntax, so there are some systems with keyboards and displays that can’t deal with the characters (though I imagine that these are quite rare nowadays). … Read more

Do these members have unspecified ordering?

Your colleague is correct for C++03: [C++03: 9.2/12]: Nonstatic data members of a (non-union) class declared without an intervening access-specifier are allocated so that later members have higher addresses within a class object. The order of allocation of nonstatic data members separated by an access-specifier is unspecified (11.1). [..] But you are correct for C++11: … Read more