开发者

Can I typedef a template template parameter?

开发者 https://www.devze.com 2023-03-01 15:38 出处:网络
In C++ library headers, we\'ll sometimes see the following to improve legibility of the code inside a class:

In C++ library headers, we'll sometimes see the following to improve legibility of the code inside a class:

template<typename MyExplicitelyLongTemplateParameter>
class C
{
public:
    typedef MyExplicitelyLongTemplateParameter P;

    // Use "P" and keep your sanity.
};

My question is, can one do the same with template template parameter?

template<template<typename> typename MyExplicitelyLongTemplateParameter>
class C
{
public:
    typedef /* ???开发者_运维知识库 */ P;

    // Use "P" and keep your sanity.
};


You can't create a typedef, no, but you can shorten the name:

template <template <typename> typename MyExplicitlyLongTemplateParameter>
class C
{
public:

    template <typename T>
    struct P 
    {
        typedef MyExplicitlyLongTemplateParameter<T> Type;
    };

    // Use "P<T>::Type" and keep your sanity.
};


In the current standard, you can't typedef a template. In the new, upcoming standard, you will be able to....

0

精彩评论

暂无评论...
验证码 换一张
取 消