How does the N4502 offer work? ("Idiom of Discovery")

I looked at the N4502 proposal and tried to wrap my head around it. I'm happy up to section 5, but then what I thought I understood fell away. Perhaps this is how I look at it. Considering 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 metafunction detection, we supply it with another metafile (i.e., a meta callback) that populates the archetypal expression role. For example, here's the implementation is_assignable

:

// 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 need to check if a type can be assigned. There is no example of how it is used, so I guess it should be as simple as:

static_assert(is_assignable<int>::value, "Not assignable.");

      

Now just looking at it doesn't look right. I don't see any way that assign_t

would interact with the type T

.

As it reads to me:

is_assignable <int>
-> detect <void, assign_t, int>

Which would then not match any specialization and would go to the base case that inherits from std::false_type

.

Compiling this here seems to agree with my understanding.

So what am I missing? How is it supposed to be used?

+3


source to share


1 answer


There is a typo, it must be

template< class T >
using is_assignable = detect<T, assign_t>;

      



Demo

0


source







All Articles