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.
};
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....
精彩评论