Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve type from the concept?

Say I have a concept:

template < typename Group  > concept bool GGroup =
    requires() { typename Group::Inner; };

How can I retrieve the type Inner when using the concept in the short form?

void doSomething(const GGroup& group)
{
    // an ugly alternative
    using Inner = typename std::decay_t<decltype(group)>::Inner;

    //// could be something like:
    // using Inner = GGroup::Inner;
    // or
    // using Inner = underlyingtype(GGroup)::Inner;
}
like image 685
Vahagn Avatar asked Nov 28 '16 08:11

Vahagn


1 Answers

The built-in downside of the short-form of Concepts TS is that you can't just name the typename of a conceptualized parameter. You have to use decltype to get it.

So you have a tradeoff: you can either avoid having an explicit template declaration at the expense of more decltype in your actual code, or you can avoid having decltype at the expense of an explicit template declaration.

like image 61
Nicol Bolas Avatar answered Oct 26 '22 13:10

Nicol Bolas