user34537
user34537

Reputation:

typedef std containers?

I wanted to do

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

But that error is preventing me. How do I do this?

Upvotes: 3

Views: 2600

Answers (5)

&#201;ric Malenfant
&#201;ric Malenfant

Reputation: 14148

You can't (until C++0x). But it could be emulated with:

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

used as:

ContainerOf<int>::type container_;

Upvotes: 16

Greg Rogers
Greg Rogers

Reputation: 36429

The way you could do this is:

#define type deque

But that comes with several disadvantages.

Upvotes: 0

dirkgently
dirkgently

Reputation: 111130

You hit an error because you missed to specify int in deque.

But note that: Template typedef's are an accepted C++0x feature. Try with the latest g++

Upvotes: 1

Doug T.
Doug T.

Reputation: 65599

deque is not a type. It is a template, used to generate a type when given an argument.

 deque<int> 

is a type, so you could do

 typedef deque<int> container_

Upvotes: 8

anon
anon

Reputation:

You don't, C++ does not yet support this kind of typedef. You can of course say;

typedef std::deque <int> IntDeque;

Upvotes: 2

Related Questions