I was looking at the proposal N4502, and have been trying to wrap my head around it. I'm good up to section 5, but then what I thought I understood falls away. Perhaps it is just how I'm looking at it. Given the following:
// primary template handles all types not supporting the operation: template< class, template<class> class, class = void_t< > > struct detect : 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>> > : true_type { };
To use this detect metafunction, we supply it with another metafunction (i.e., a meta-callback) that fills the role of the archetypal expression. For example, here is an implementation of the
is_assignable
type trait:// archetypal expression for assignment operation: template< class T > using assign_t = decltype( declval<T&>() = declval<T const &>() ) // trait corresponding to that archetype: template< class T > using is_assignable = detect<void, assign_t, T>;
I should be able to check if a type is assignable. No example of how it is use is given, so I'm assuming that it should be as easy as:
static_assert(is_assignable<int>::value, "Not assignable.");
Now just looking at this, doesn't look right. I don't see any way that assign_t
is going to interact with the type T
.
How this reads to me is:
is_assignable<int> -> detect<void, assign_t, int>
Which will then fail to match any specialization and go to the base case which inherits from std::false_type
.
Compiling this here agrees with my understanding.
So, what am I missing? How is this supposed to be used?
Aucun commentaire:
Enregistrer un commentaire