473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

aliasing a class

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

So that then I can write,
index_type<std::size_tindex_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

May 14 '07 #1
9 1679
toton wrote:
Hi,
Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<Tindex_type<T;

So that then I can write,
index_type<std::size_tindex_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
May 14 '07 #2
toton wrote:
Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<Tindex_type<T;

So that then I can write,
index_type<std::size_tindex_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)
May 14 '07 #3
Pete Becker wrote:
toton wrote:
> Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<Tindex_type<T;

So that then I can write,
index_type<std::size_tindex_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.
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
May 14 '07 #4
On 14 Maj, 15:33, Zeppe <zeppe@.remove.all.this.long.comment.email.it>
wrote:
Pete Becker wrote:
toton wrote:
Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<Tindex_type<T;
So that then I can write,
index_type<std::size_tindex_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.

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 :-)

--
Erik Wikström

May 14 '07 #5
On May 14, 3:33 pm, Zeppe
<zeppe@.remove.all.this.long.comment.email.itwrote :
Pete Becker wrote:
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.
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.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 15 '07 #6
James Kanze wrote:
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.)
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
May 15 '07 #7
Zeppe wrote:
Pete Becker wrote:
>toton wrote:
>> Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<Tindex_type<T;

So that then I can write,
index_type<std::size_tindex_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.

To be accurate, it's a template class.
To be accurate, it's a class template.
Template and template classes are
rather different things, too.
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)
May 15 '07 #8
James Kanze wrote:
>
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)
May 15 '07 #9
On May 15, 6:07 pm, Pete Becker <p...@versatilecoding.comwrote:
Zeppe wrote:
Pete Becker wrote:
toton wrote:
Is it possible to alias a class with a different name ?
something like
typedef template<class T>std::vector<Tindex_type<T;
>So that then I can write,
index_type<std::size_tindex_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.
To be accurate, it's a template class.

To be accurate, it's a class template.
Template and template classes are
rather different things, too.

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

May 21 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical...
4
by: Yuri Victorovich | last post by:
In short my question is: If I overload "operator new" for class A and return from it instance of struct B (unrelated with A) as allocated memory area for A should aliasing rules work and allow...
2
by: Bryan Parkoff | last post by:
I create one 32 Bits variable and four pointer variables. Four pointer variables link or point to one 32 Bits variable. Each pointer variable is 8 Bits. Look at my example below. unsigned int...
5
by: Mathieu Benoit | last post by:
(I'm having trouble to post this, sorry if this mail comes several times) I'm trying to optimize the use of an integer array class, and I found that one major problem is pointer aliasing. I...
9
by: liljencrantz | last post by:
Hi, I have a piece of code that uses hashtables to store pointers to various bits of data. The hashtable sees all pointers as const void *, while the application obviously uses various other...
3
by: Hallvard B Furuseth | last post by:
I'm getting horribly lost in the strict aliasing rules. Is this code correct? struct A { int x; }; struct B { int x, y; }; int foo( struct A *a ) { struct B *b = (struct B *) a; return b->x...
1
by: Ray | last post by:
Hello, I'm reading Mr. Flanagan's JS Definitive Guide 5th edition. I was wondering about a point he make in section 10.2 of the book: "Importing Symbols from Namespaces". He mentions in there...
13
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
6
by: Roderik | last post by:
Hi, On my website I implemented tooltip alike layers when you hover the category items in the sidebar on the right. See: http://www.roderik.net/ The layers that become visible have a...
4
by: Paul Brettschneider | last post by:
Hello all, consider the following code: typedef char T; class test { T *data; public: void f(T, T, T); void f2(T, T, T);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.