...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template<bool B, class T = void> struct enable_if_; template<bool B, class T = void> using enable_if_t = typename enable_if_<B, T>::type;
type: If B
is true, then the member type
is defined to be T
. Otherwise
there is no member type
.
Header: #include
<boost/type_traits/enable_if.hpp>
Note | |
---|---|
The trait has the name |
Examples:
The following function can be used to destroy each element of an array and specially handle arrays of trivially destructible types.
template<class T> typename boost::enable_if_<!boost::has_trivial_destructor<T>::value>::type destroy(T* ptr, std::size_t size) { while (size > 0) { ptr[--size].~T(); } } template<class T> typename boost::enable_if_<boost::has_trivial_destructor<T>::value>::type destroy(T*, std::size_t) { }
Compiler Compatibility: All current compilers
are supported by this trait. The type alias enable_if_t
is only available if the compiler supports template aliases.