在n4502中,作者描述了封装void_t技巧的检测习语的早期实现.这是它的定义以及用于定义特征的用法is_assignable(实际上它是is_copy_assignable)
template<class...>
using void_t = void;
// primary template handles all types not supporting the operation:
template< class, template<class> class, class = void_t< > >
struct
detect : std::false_type { };
// specialization recognizes/validates only types supporting the archetype:
template< class T, template<class> class Op >
struct
detect< T, Op, void_t<Op<T>> > : std::true_type { };
// archetypal expression for assignment operation:
template< class T >
using
assign_t = decltype( std::declval<T&>() = …Run Code Online (Sandbox Code Playgroud)