aliasing a class

T

toton

Hi,
Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<T> index_type<T> ;

So that then I can write,
index_type<std::size_t> index_t;
The main aim is that, at present I am using index_type same as
std::vector , but later I want to switch to a more specific class.
I can do the same with #define, but looking for a c++ solution .

thanks
abir
 
Z

Zeppe

toton said:
> Hi,
> Is it possible to alias a class with a different name ?
> something like
> typedef template<class T>std::vector<T> index_type<T> ;
>
> So that then I can write,
> index_type<std::size_t> index_t;

It's currently not possible to have template typedef. There are some
ugly workarounds, and this feature is likely to be included in the next
c++ standard.

Here there is a discussion about this topic by Herb Sutter
(http://www.ddj.com/dept/cpp/184403850) that covers some of the
currently available alternatives.


Regards,

Zeppe
 
P

Pete Becker

toton said:
Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<T> index_type<T> ;

So that then I can write,
index_type<std::size_t> index_t;
The main aim is that, at present I am using index_type same as
std::vector , but later I want to switch to a more specific class.

Please note that std::vector is not a class. It's a template. Classes
and templates are rather different things.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
Z

Zeppe

Pete said:
Please note that std::vector is not a class. It's a template. Classes
and templates are rather different things.

To be accurate, it's a template class. Template and template classes are
rather different things, too. Anyway, you are right, but the typedef of
a template class is quite a natural request, and it's disappointing that
this functionality is not provided.

I hope in the next standard it will be included.

Regards,

Zeppe
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

To be accurate, it's a template class. Template and template classes are
rather different things, too. Anyway, you are right, but the typedef of
a template class is quite a natural request, and it's disappointing that
this functionality is not provided.

I hope in the next standard it will be included.

It's already in the working paper, so if you can just till 2009~2010
you'll be fine :)
 
J

James Kanze

Pete Becker wrote:
To be accurate, it's a template class.

You mean a class template. In English, the modifier preceded
the modified noun. (The original version of the standard was
somewhat careless about this, I think, which occasionally caused
some confusion. Is a "template class" a class template, or the
instantiation of a class template?)
Template and template classes are
rather different things, too.

A class template is a template. A template may be a class
template, but it could also be a function template.

(I don't mean to pick on you, but these things are confusing
enough even without using imprecise vocabulary.)
 
Z

Zeppe

James said:
You mean a class template. In English, the modifier preceded
the modified noun. (The original version of the standard was
somewhat careless about this, I think, which occasionally caused
some confusion. Is a "template class" a class template, or the
instantiation of a class template?)


A class template is a template. A template may be a class
template, but it could also be a function template.

(I don't mean to pick on you, but these things are confusing
enough even without using imprecise vocabulary.)

Fair enough, I just wanted to point out the same that you said: "A class
template is a template. A template may be a class template", but not
necessarily. I'm not disappointed, it is a discussion group, so we are
free to discuss :) (and I'm really happy when somebody points out my
English mistakes, because I can correct them).

Regards,

Zeppe
 
P

Pete Becker

James said:
You mean a class template. In English, the modifier preceded
the modified noun. (The original version of the standard was
somewhat careless about this, I think, which occasionally caused
some confusion. Is a "template class" a class template, or the
instantiation of a class template?)

It wasn't actually careless, it was a deliberate distinction that was
very confusing. A class template is a template that can be used to
define a class. A template class was such a class (i.e. a class created
from a template). Now we call it a specialization of the template.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
T

toton

To be accurate, it's a class template.


A class template is a template, and it is not a class.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)

The class template generates a class, and that end product is the
interest of the programmer.
And all these doesn't matter, if it carries the meaning.
I hope I had conveyed the problem clearly which I wanted the answer.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top