GhostlyGhost
GhostlyGhost

Reputation: 523

Can I typedef a template template parameter?

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

Upvotes: 9

Views: 3375

Answers (2)

James McNellis
James McNellis

Reputation: 355069

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

Upvotes: 8

jwismar
jwismar

Reputation: 12258

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

Upvotes: 3

Related Questions