Topic: Parametrized Typedefs
Author: e9426268@stud1.tuwien.ac.at (Mark Martin Probst)
Date: 16 Mar 1995 16:47:58 GMT Raw View
Timothy Murphy (tmurphy@panix.com) wrote:
: I propose a modest addition to the C++ language definition.
: I have often wished to have a parametrized typedef. For example, if
: ptr<T> was a smart pointer and list<T> was a list, one could say:
: template<class T> typedef list< ptr<T> > listP;
I agree wholeheartedly!
I am currently working on a container class library based on a set of list
classes. A list is a data structure which can be used just like an array. I
do have, however, different list implementations, like a linked list,
a static list or an AVL list. A set, for example, is based on a list in
that it uses the list in order to hold the data. Now the user should be able to
choose whether he wants a static set, a linked set or an AVL set. My solution
is to provide only one set class and give the list type as a template argument.
The problem is, however, that a direct declarion of a set of that type is
utterly long. For example:
Set<int, Ascending<int>, LinkedList<int, Ascending<int>, coNoDuplicates, Unmanaged> >
would be the type of a linked set of int s sorted in ascending order with the
standard memory manager. Now if I could say
template <class Item, class Comp, class Manager>
typedef Set<Item, Comp, LinkedList<Item, Comp, coNoDuplicates, Manager> > LinkedSet;
I could declare a linked set like this:
LinkedSet<int, Ascending<int>, Unmanaged>
Instead, I have to derive LinkedSet from Set, which means that I have
to write the constructors and the operator=. And since I currently
have three types of lists, I have to do this three times!
It would be great if a template typedef were allowed!!!
Author: Steve.J.G.Marx@inter.NL.net (Steve J. Marx)
Date: Thu, 16 Mar 1995 15:22:20 GMT Raw View
e9426268@stud1.tuwien.ac.at (Mark Martin Probst) wrote:
>I agree wholeheartedly!
>I am currently working on a container class library based on a set of list
>classes. A list is a data structure which can be used just like an array. I
>do have, however, different list implementations, like a linked list,
>a static list or an AVL list. A set, for example, is based on a list in
>that it uses the list in order to hold the data. Now the user should be able to
>choose whether he wants a static set, a linked set or an AVL set. My solution
>is to provide only one set class and give the list type as a template argument.
>The problem is, however, that a direct declarion of a set of that type is
>utterly long. For example:
>Set<int, Ascending<int>, LinkedList<int, Ascending<int>, coNoDuplicates, Unmanaged> >
>would be the type of a linked set of int s sorted in ascending order with the
>standard memory manager. Now if I could say
>template <class Item, class Comp, class Manager>
>typedef Set<Item, Comp, LinkedList<Item, Comp, coNoDuplicates, Manager> > LinkedSet;
>I could declare a linked set like this:
>LinkedSet<int, Ascending<int>, Unmanaged>
>Instead, I have to derive LinkedSet from Set, which means that I have
>to write the constructors and the operator=. And since I currently
>have three types of lists, I have to do this three times!
>It would be great if a template typedef were allowed!!!
First of all, I think you are right. It would be nice to have C++
support template typedefs. The List<ptr<T>> is a good example of its
usage.
However for your particular problem there is another solution as well.
The new standard defines two addition to templates.
1. default arguments
2. class templates as arguments
You could use these futures as follows:
template <class Item,
template <class I,class Co, D,class M> class ListType=LinkedList,
class Comp=Ascending<Item>,
class Manager=Unmanaged>
class Set {
....
private:
ListType<Item,Comp,coNoDuplicates,Manager> list_type;
};
The Set class could then be used as follows:
// default
Set<int> s1;
// different implementation
Set<int,AvlTree> s2
// different ordering and implementation
Set<int,AvlTree,Descending<int>> s3;
// different management
Set<int,AvlTree,Descending<int>,Managed> s4;
I will be posting a proposal for the STL, using this type of
representation parameterization in a week or so to comp.std.c++.
So if you are interest watch out for it.
Steve J. Marx
Author: mat@mole-end.matawan.nj.us
Date: Wed, 8 Mar 1995 07:26:20 GMT Raw View
In article <3jfip4$mcd@panix3.panix.com>, tmurphy@panix.com (Timothy Murphy) writes:
>
> Template Typedefs.
>
> I propose a modest addition to the C++ language definition.
> I have often wished to have a parametrized typedef. For example, if
> ptr<T> was a smart pointer and list<T> was a list, one could say:
>
> template<class T> typedef list< ptr<T> > listP;
>
> for a list of ptrs to T. I am certainly not the first person to make
> such a request. Stroustrup mentions it in section 15.8 of his book
> "The Design and Evolution of C++", and remarks that it is trivial to
> implement but questions the wisdom of introducing "yet another renaming
> feature".
>
> It seems to me that renaming is the heart and soul of programming
> in general and that useful means of renaming should be embraced rather
> than shunned. In this case, the meaning is obvious, the implementation
> is trivial, and its use could greatly clarify the use of heavily
> parametrized code (e.g. the use of STL). It should be supported.
>
>
> Please rip this apart, both with your editor and your words; I am
> very interested in feedback, particularly from members of the standards
> committee.
If you're asking some of the very busy people on that committee (people
far busier than me) to wade through the 52 megabytes of mail, the four-
foot-high stack of papers, and the thousands of subtle issues represented
therein to answer these points one by one, I'm afraid your request is far
less reasonable than it seems.
--
(This man's opinions are his own.)
From mole-end Mark Terribile
mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
(Training and consulting in C, C++, UNIX, etc.)
Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: Wed, 8 Mar 1995 20:51:55 GMT Raw View
In article <1995Mar8.072620.2935@mole-end.matawan.nj.us>,
<mat@mole-end.matawan.nj.us> wrote:
>In article <3jfip4$mcd@panix3.panix.com>, tmurphy@panix.com (Timothy Murphy) writes:
>>
>> Template Typedefs.
>>
>> I propose a modest addition to the C++ language definition.
[]
>> Please rip this apart, both with your editor and your words; I am
>> very interested in feedback, particularly from members of the standards
>> committee.
>
>If you're asking some of the very busy people on that committee (people
>far busier than me) to wade through the 52 megabytes of mail, the four-
>foot-high stack of papers, and the thousands of subtle issues represented
>therein to answer these points one by one, I'm afraid your request is far
>less reasonable than it seems.
You might have missed the point Mark. At this point
Timothy is politely asking for feedback on what may become
formal requests during the ANSI public review.
If such a request is made during the ANSI review,
I think you will find ANSI rules _require_ X3J16 to
consider it and reply to it.
So feedback now may _reduce_ the workload on the
committee. Perhaps if Timothy had read the minutes
of the meetings and the papers submitted in the mailings,
or even been able to read reflector email, he may well
have seen may of the issues he has raised discussed,
and not be raising them again.
Now imagine comments from people without Internet access. :-)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189
Author: tmurphy@panix.com (Timothy Murphy)
Date: 6 Mar 1995 13:03:16 -0500 Raw View
Template Typedefs.
I propose a modest addition to the C++ language definition.
I have often wished to have a parametrized typedef. For example, if
ptr<T> was a smart pointer and list<T> was a list, one could say:
template<class T> typedef list< ptr<T> > listP;
for a list of ptrs to T. I am certainly not the first person to make
such a request. Stroustrup mentions it in section 15.8 of his book
"The Design and Evolution of C++", and remarks that it is trivial to
implement but questions the wisdom of introducing "yet another renaming
feature".
It seems to me that renaming is the heart and soul of programming
in general and that useful means of renaming should be embraced rather
than shunned. In this case, the meaning is obvious, the implementation
is trivial, and its use could greatly clarify the use of heavily
parametrized code (e.g. the use of STL). It should be supported.
Please rip this apart, both with your editor and your words; I am
very interested in feedback, particularly from members of the standards
committee.
-- Timothy S. Murphy: A serious user and admirer of C++.
tmurphy@panix.com
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 7 Mar 1995 03:49:35 GMT Raw View
tmurphy@panix.com (Timothy Murphy) writes:
>Template Typedefs.
[...]
> It seems to me that renaming is the heart and soul of programming
>in general and that useful means of renaming should be embraced rather
>than shunned. In this case, the meaning is obvious, the implementation
>is trivial, and its use could greatly clarify the use of heavily
>parametrized code (e.g. the use of STL). It should be supported.
[...]
>I am very interested in feedback, particularly from members of the
>standards committee.
I strongly agree. In fact that issue was on Australia's comments
for the Committee Draft vote.
--
Fergus Henderson - fjh@munta.cs.mu.oz.au
Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: Tue, 7 Mar 1995 15:14:33 GMT Raw View
In article <3jfip4$mcd@panix3.panix.com>,
Timothy Murphy <tmurphy@panix.com> wrote:
>
>Template Typedefs.
No no. Typedef templates.
Consideration of which is on the list of Australian National Body
requirements. So you might get them after all :-)
Of course, except in the case of passing a template to
a template, you already have them:
template<class T> class X { typedef Y<T> X; };
X<int>::X x; // x is a Y<int>
This makes them less useful -- but also guarrantees the semantics
are sound.
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189