std::void_t
From cppreference.com
Defined in header <type_traits>
|
||
template< class... > using void_t = void; |
(since C++17) | |
Utility metafunction that maps a sequence of any types to the type void
Notes
This metafunction is used in template metaprogramming to detect ill-formed types in SFINAE context:
// primary template handles types that have no nested ::type member: template< class, class = std::void_t<> > struct has_type_member : std::false_type { }; // specialization recognizes types that do have a nested ::type member: template< class T > struct has_type_member<T, std::void_t<typename T::type>> : std::true_type { };
It can also be used to detect validity of an expression:
// primary template handles types that do not support pre-increment: template< class, class = std::void_t<> > struct has_pre_increment_member : std::false_type { }; // specialization recognizes types that do support pre-increment: template< class T > struct has_pre_increment_member<T, std::void_t<decltype( ++std::declval<T&>() )> > : std::true_type { };
Examples
This section is incomplete Reason: no example |
See also
(C++11) |
conditionally removes a function overload or template specialization from overload resolution (class template) |