C ++ templated typedef

I have a template class

template <T>
class Example 
{
...
};

inside of which there are many methods of the following type:

template <class U> <class V> method(....)

Inside them, I use tr1 :: shared_ptr for U or V or T.

Its tiresome typing tr1::shared_ptr<const U>or tr1::shared_ptr<const V>.

The obvious thing:

template <typename U>
typedef tr1::shared_ptr<U> shptr<U>;

does not work.

What are you doing in this situation? Anything that can reduce verbosity?

+5
source share
3 answers

You can use the internal type:

template <typename U>
struct sptr {
    typedef tr1::shared_ptr<U> t;
};

Then say, sptr<U>::tor, unfortunately, often typename sptr<U>::t.

C ++ 0x has a typedefs pattern, you can check if you can convince your compiler to accept them:

template<typename U>
using sptr = tr1::shared_ptr<U>;

Then say sptr<U>

, , #define sptr ::tr1::shared_ptr, , ++ 0x . , , .

+9

, ( , ).

: Typedef.

, - , , typedef, (, result_t, !).

+2
using tr1::shared_ptr;

shared_ptr , , . .

+1

All Articles