Is it possible to create a template alias?

后端 未结 1 1163
北海茫月
北海茫月 2021-02-19 11:08

Consider the following code:

template< template< typename ... > class ... Ts >
struct unite
{
    template< typename ... T >
    struct type
           


        
1条回答
  •  一整个雨季
    2021-02-19 11:11

    No, you cannot.

    using can "return" a type, or a variable. It cannot "return" a template. There are no similar mechanisms elsewhere.

    You can do something vaguely useful by taking the convention that all templates are not templates, but rather classes with a templateusing apply=?; alias inside them (and while we are at it, constants are std::integral_constants, and pointers are pointer_constant).

    Now everything is a class. templates become just kinds of classes (with a ::apply.

    Applying a bundle of types to such a template would be done via:

    template
    using apply_t = Z::template apply;
    

    So with a "native" template Z, you'd do Z. With these "indirect" templates, you'd do apply_t.

    With this convention, a template using alias can return an indirect template. If the rest of your code follows the convention of always calling apply_t to apply a template, and you indirect-ize all other templates you write, we are done.

    This is ugly.

    0 讨论(0)
提交回复
热议问题