Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I typedef a template template parameter?

Tags:

c++

templates

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.
};
like image 544
GhostlyGhost Avatar asked May 01 '11 02:05

GhostlyGhost


2 Answers

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

like image 29
jwismar Avatar answered Oct 20 '22 01:10

jwismar


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.
};
like image 69
James McNellis Avatar answered Oct 20 '22 01:10

James McNellis