May 2017
Intermediate to advanced
590 pages
17h 18m
English
std::conditional is a class template that defines a member called type as either one or the other of its two type template parameters. The selection is done based on a compile-time constant Boolean expression provided as an argument for a non-type template parameter. Its implementation looks like this:
template<bool Test, class T1, class T2> struct conditional { typedef T2 type; }; template<class T1, class T2> struct conditional<true, T1, T2> { typedef T1 type; };
To help simplify the use of std::conditional, C++14 provides an alias template called std::conditional_t, that we have seen in the third example above, and that is defined as follows:
template<bool Test, class T1, class T2> using conditional_t = typename conditional<Test,T1,T2>::type; ...Read now
Unlock full access