...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template<class Default, template<class...> class Op, class... Args>
using detected_or = see-below
;
template<class Default, template<class...> class Op, class... Args>
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
Aliases: An unspecified type with two public member type definitions:
value_t
is true_type
if Op<Args...>
is a valid template-id, otherwise false_type
type
is Op<Args...>
if it is a valid template-id, otherwise Default
C++ Standard Paper: N4502
Compiler Compatibility: Requires C++11 variadic templates and C++11 template aliases.
Header: #include
<boost/type_traits/detected_or.hpp>
Examples:
Suppose we wish to declare a type that represents the difference between two values of type T, it should be T::difference_type if such a type exists, or std::ptrdiff_t otherwise:
template<class T> using difference_t = typename T::difference_type; template<class T> using difference_type = boost::detected_or_t<std::ptrdiff_t, difference_t, T>;
Now the type difference_type<T>
gives us what we need.
See also: is_detected, is_detected_convertible, is_detected_exact.