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;
}

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.

链接地址: http://www.djcxy.com/p/37214.html

上一篇: 如何使用JQuery

下一篇: 如何从概念中检索类型?