Typedef std containers?

I wanted to do

typedef deque type; //error, use of class template requires template argument list
type<int> container_;

But this mistake bothers me. How to do it?

+3
source share
5 answers

You cannot (before C ++ 0x). But it can be emulated with:

template<typename T>
struct ContainerOf
{
  typedef std::deque<T> type;
};

used as:

ContainerOf<int>::type container_;
+15
source

deque is not a type. This is the pattern used to generate the type when specifying the argument.

 deque<int> 

- type, so you can do

 typedef deque<int> container_
+8
source

, ++ typedef. , , :

typedef std::deque <int> IntDeque;
+2

, , int deque.

: typedef ++ 0x. g++

+1

:

#define type deque

But this is due to several drawbacks.

0
source

All Articles