May 2017
Intermediate to advanced
590 pages
17h 18m
English
The following list shows various situations where type traits are used to achieve various design goals:
template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value>::type> T multiply(T const t1, T const t2) { return t1 * t2; } auto v1 = multiply(42.0, 1.5); // OK auto v2 = multiply("42"s, "1.5"s); // error
template <typename T> struct pod_wrapper { static_assert(std::is_pod<T>::value, "Type is not a POD!"); T value; }; pod_wrapper<int> i{ 42 }; // OK pod_wrapper<std::string> s{ "42"s }; // error
Read now
Unlock full access