4

I am guessing this is not possible, but I am really hoping it is. An example:

template<class T> concept bool Dereferencable() { return requires(T t){ *t }; } template<class T> concept bool Incrementable() { return requires(T t){ ++t }; } template<class T, ??? X, ??? Y> concept bool And() { return X<T>() && Y<T>(); } static_assert( And<int*, Dereferencable, Incrementable>() ); 

Is there a way to do something like this?

If not, is there a hack to achieve the same functionality?

Ultimately I'd like to use compound concepts as placeholder constraints.

1 Answer 1

3

Concepts can really only be used in limited ways (as of this writing). As a consequence, it is not possible to achieve what you want.

A workaround would be to associate to each concept a particular (meta)function in order to enable higher-order use:

// this is just one way of doing it... template<typename Arg> struct is_dereferencable_f { static constexpr bool value = Dereferencable<Arg>; }; // ...via template template parameters template<typename Arg, template<typename> typename... Conjuncts> concept bool SatisfiesAll = (... && Conjuncts<Arg>::value); 
Sign up to request clarification or add additional context in comments.

1 Comment

I might revisit this answer as the Concepts-Lite spec as well as its GCC implementation evolve, there are other ideas up in the air which I can't quite test yet.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.