Topic: template typedef


Author: gdr@cs.tamu.edu (Gabriel Dos Reis)
Date: Sat, 23 Oct 2004 16:37:08 GMT
Raw View
kmarkw65@yahoo.com (Mark Williams) writes:

| gdr@cs.tamu.edu (Gabriel Dos Reis) wrote in message news:<m3655f6z5e.fsf@merlin.cs.tamu.edu>...
| > bloodymir.crap@gmx.net (Frank Birbacher) writes:
| >
| > | Hi!
| > |
| > | Ben Hutchings wrote:
| > | > Gabriel Dos Reis and Mat Marcus, Proposal to add template aliases to C++
| > | > <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf>
| > |
| > | Yes, it's what I mean. But I wonder why they prefer
| > |    template<typename T>
| > |    using Vec = MyVector<T, MyAlloc<T> >
| > | instead of the more intuitive (at least to me):
| > |    template<typename T>
| > |    typedef MyVector<T, MyAlloc<T> > Vec;
| > | Where 'typedef' usually introduces aliases for types. I couldn't
| > | understand the explanation in the proposal. Can anyone shed some light?
| >
| > Reasons are given in both papers.  For example, Vec is not a type so
| > using "typedef" in that context is misleading
|
| Im missing something.
|
| A function template is not a function; a class template is not a
| class; why would anyone expect a typedef template to be a type?

Because people are expecting class templates to work as classes?
And that leads to many confusions.

I do not want a new useful feature reinforces those confusions.
Plus, the "using" syntax, as extensively explained in the papers,
leads itself to more generality -- overloade set for example -- than
the "typedef" syntax.  Plus, again as explained in the papers, it
cleans up the typedef syntax.

--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Mon, 25 Oct 2004 18:21:58 GMT
Raw View
Frank Birbacher wrote:
>
> I agree, Mark. To me using 'template<...> typedef' seems most natural.
> Alberto Barbati said so, too.
>

I said so? Don't remember...

The "typedef" syntax leads naturally to the notion of template typedef,
while the "using" syntax leads also naturally to the notion of template
alias. I remember I said that those two notions are radically different.

> The word 'using' seems appropirate after reading the proposals. But writing
>
> struct Foo1
> {
>     template<typename T>
>     using ArrayType = std::vector<T>;
> //...
> };
>
> looks more like an implementation detail. And it has other semantics as:
>
> struct Foo2
> {
>     using std::vector;
> //...
> };
>
> because 'Foo1::ArrayType' may be used as a template template parameter,
> whereas 'Foo2::vector' may not. So instead of 'using' an existing type,
> you 'define' a new name for an existing type.

It's not that Foo2::vector may not be used as a template parameter. As
using-declarations at class-scope are member-declarations, it's more
correct to say that your second example is ill-formed. This particular
case is not being addressed in N1489, but, for consistency, I expect the
first example to be deemed ill-formed too. Maybe a clarification on this
topic should be included in the paper.

That's in fact a very interesting point, because if template aliases are
illegal at class scope it would mean that they can't be used to address
the "allocator rebind" pattern, thus severely limiting their usefulness.
On the other hand, I agree with you that allowing template aliases at
class scope but not "simple" aliases would be inconsistent.

> Therefore use 'typedef'.

Don't be so hasty. Both approaches have pros and cons. Personally, I
still haven't decided which one is better. Before writing this post I
would have favored aliases over typedefs, but the class-scope issue is
now giving me a headache. I'm starting to think that we should have
both... ;-)

Regards,

Alberto

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Tue, 26 Oct 2004 19:36:58 GMT
Raw View
Alberto Barbati wrote:
> Frank Birbacher wrote:
>
>> The word 'using' seems appropirate after reading the proposals. But
>> writing
>>
>> struct Foo1
>> {
>>     template<typename T>
>>     using ArrayType = std::vector<T>;
>> //...
>> };
>>
>> looks more like an implementation detail. And it has other semantics as:
>>
>> struct Foo2
>> {
>>     using std::vector;
>> //...
>> };
>>
>> because 'Foo1::ArrayType' may be used as a template template
>> parameter, whereas 'Foo2::vector' may not. So instead of 'using' an
>> existing type, you 'define' a new name for an existing type.
>
>
> It's not that Foo2::vector may not be used as a template parameter. As
> using-declarations at class-scope are member-declarations, it's more
> correct to say that your second example is ill-formed. This particular
> case is not being addressed in N1489, but, for consistency, I expect the
> first example to be deemed ill-formed too. Maybe a clarification on this
> topic should be included in the paper.
>
> That's in fact a very interesting point, because if template aliases are
> illegal at class scope it would mean that they can't be used to address
> the "allocator rebind" pattern, thus severely limiting their usefulness.
> On the other hand, I agree with you that allowing template aliases at
> class scope but not "simple" aliases would be inconsistent.

I just realized that the two syntaxes are completely different and so
they are not required to be consistent with each other. In particular:

    template<typename T>
    using ArrayType = std::vector<T>;

is a (templated) alias-declaration.  As clearly stated in N1489: "an
alias-declaration is acceptable anywhere a typedef declaration or a
namespace-alias-definition is acceptable." Therefore this example is
(proposed to be) perfectly legal.

On the other hand:

    using std::vector;

is a using-declaration, which is a completely different thing, so the
comparison is unfair. If there is an inconsistency issue, it is within
the notion of using-declaration itself as the semantic changes depending
on whether it's used at namespace scope or at class scope. However, I
don't think this issue is detrimental to the notion of alias-declaration.

To be fair, the comparison should have been with:

    using vector = std::vector;

Unfortunately this is not currently covered by N1489 because it defines
alias-declaration as:

  alias-declaration:
    using identifier = type-id
    using identifier = qualified-namespace-specified

However the section 2.3 of the paper seems to hint that a (possibly
qualified) template-name could also be used on the right side of '=', so
I believe that such syntax should be legal in the proposal's intentions.

Please notice that in the very same section it is stated that:

    using std::ostream;

would be just a short-hand for

    using ostream = std::ostream;

but we just saw that this is not going to be true in a class-scope and
the proposal should have warned about this difference.

>
>> Therefore use 'typedef'.
>
>
> Don't be so hasty. Both approaches have pros and cons. Personally, I
> still haven't decided which one is better. Before writing this post I
> would have favored aliases over typedefs, but the class-scope issue is
> now giving me a headache. I'm starting to think that we should have
> both... ;-)

Faith in using/alias restored. ;-)

Alberto

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gdr@cs.tamu.edu (Gabriel Dos Reis)
Date: Tue, 26 Oct 2004 21:13:04 GMT
Raw View
AlbertoBarbati@libero.it (Alberto Barbati) writes:

| Frank Birbacher wrote:
| > I agree, Mark. To me using 'template<...> typedef' seems most
| > natural. Alberto Barbati said so, too.
| >
|
| I said so? Don't remember...
|
| The "typedef" syntax leads naturally to the notion of template
| typedef, while the "using" syntax leads also naturally to the notion
| of template alias. I remember I said that those two notions are
| radically different.

Notice that you can express the "typedef template" part in the
template alias framework.  The papers contain examples of such.

| > The word 'using' seems appropirate after reading the proposals. But writing
| > struct Foo1
| > {
| >     template<typename T>
| >     using ArrayType = std::vector<T>;
| > //...
| > };
| > looks more like an implementation detail. And it has other semantics
| > as:
| > struct Foo2
| > {
| >     using std::vector;
| > //...
| > };
| > because 'Foo1::ArrayType' may be used as a template template
| > parameter, whereas 'Foo2::vector' may not. So instead of 'using' an
| > existing type, you 'define' a new name for an existing type.
|
| It's not that Foo2::vector may not be used as a template parameter. As
| using-declarations at class-scope are member-declarations, it's more
| correct to say that your second example is ill-formed. This particular
| case is not being addressed in N1489, but, for consistency, I expect
| the first example to be deemed ill-formed too. Maybe a clarification
| on this topic should be included in the paper.

Most certainly.

   The paper suggested an alternate syntax for typedefs:

       typedef int (*sig_t)(int);

could be written as

          using sig_t = int (*)(int);

which follows from the suggested production:

       alias-declaration:
           using identifier = type-id;

and the template alias declaration grammar follows from the general
(existing) template declaration

     export(opt) template< template-parameter-list(opt) > declaration


It is also explained, in the papers, that the existing using-declaration

  using-declaration:
    using typename(opt) ::(opt) nested-name-specified unqualified-id ;
    using :: unqualified-id ;


is an alias declaration where the syntax has been optimized in the
sense that the alias name is just the unqualified part of the aliasee.


So the syntax suggested in the papers is no way conflicting with
existing syntaxes; rather it generalizes them.

AS it currently stands, the declaration at Foo2 scope is ill-formed in
both C+03 and C++0x (assuming template aliases are adopted) for
various reasons:
  (1) in C++02, it is ill-formed because std::vector is not a base of
      Foo2;
  (2) in C++0x, it will be ill-formed because std::vector is not a type-id.


If a more general alias mechanism is adopted (something NOT proposed
by the papers), then it would make sense to remove the restrictions in
(2).

| That's in fact a very interesting point, because if template aliases
| are illegal at class scope it would mean that they can't be used to
| address the "allocator rebind" pattern, thus severely limiting their
| usefulness. On the other hand, I agree with you that allowing template
| aliases at class scope but not "simple" aliases would be inconsistent.

I see no reason why template aliases should be ill-formed at
class-scopes, given the connection between the alias-declaration and
using-declarations.

What you call "simple" aliases requires a much more general aliasing
mechanism and is not just that "simple" :-).

As a matter of fact, it could be expressed with the template alias
syntax.

| > Therefore use 'typedef'.
|
| Don't be so hasty. Both approaches have pros and cons. Personally, I
| still haven't decided which one is better. Before writing this post I
| would have favored aliases over typedefs, but the class-scope issue is
| now giving me a headache. I'm starting to think that we should have
| both... ;-)

The template alias framework already allows you to express typedef
templates.  In many cases, they seem to be same; they differ when it
comes to specializations.

--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bloodymir.crap@gmx.net (Frank Birbacher)
Date: Tue, 26 Oct 2004 22:21:50 GMT
Raw View
Hi!

Alberto Barbati wrote:
> Frank Birbacher wrote:
>
>>
>> I agree, Mark. To me using 'template<...> typedef' seems most natural.
>> Alberto Barbati said so, too.
>>
>
> I said so? Don't remember...

Hmm, I must have missed you point then.

> That's in fact a very interesting point, because if template aliases are
> illegal at class scope it would mean that they can't be used to address
> the "allocator rebind" pattern, thus severely limiting their usefulness.

Hmm, I will have to read over the proposals once again. I think I
have missed a major point.

> On the other hand, I agree with you that allowing template aliases at
> class scope but not "simple" aliases would be inconsistent.

I'm not aware of having made that point. But well, if it inspires
you... :)

> I'm starting to think that we should have
> both... ;-)

It's getting weird for me. You are starting to give me headaches.

Frank

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gdr@cs.tamu.edu (Gabriel Dos Reis)
Date: Wed, 27 Oct 2004 05:37:33 GMT
Raw View
AlbertoBarbati@libero.it (Alberto Barbati) writes:

[...]

| On the other hand:
|
|     using std::vector;
|
| is a using-declaration, which is a completely different thing, so the
| comparison is unfair. If there is an inconsistency issue, it is within
| the notion of using-declaration itself as the semantic changes depending
| on whether it's used at namespace scope or at class scope.

Indeed.

The apparant discrepency in the meaning of using-declaration at
class-scope or namespace-scope can be reconciled in the framework of
alias-declaration; we do not propose it because we do not believe at
this point that a general alias notion is needed.

Remember that it takes a special rule to ban a using-declaration at
class that does not refer to a base-class member. Such a delcaratin
does not introduce a new-data member nor does it introduce a new
member function.  Rather, it brings the name in scope, and optionally
adjust access control, as an alias (7.3.3/1).

At the intersection, at class-scope, of the new alias-declaration and
existing using-declaration lies using-declarations that nominates
type-names. Again, there is no conflict.

|                                                            However, I
| don't think this issue is detrimental to the notion of alias-declaration.
|
| To be fair, the comparison should have been with:
|
|     using vector = std::vector;
|
| Unfortunately this is not currently covered by N1489 because it defines
| alias-declaration as:
|
|   alias-declaration:
|     using identifier = type-id
|     using identifier = qualified-namespace-specified

Indeed.

| However the section 2.3 of the paper seems to hint that a (possibly
| qualified) template-name could also be used on the right side of '=', so
| I believe that such syntax should be legal in the proposal's intentions.

That is what I keep referring to as "a general notion of aliasing".
There is something to be said about it; D&E has a dicussion about that.

| Please notice that in the very same section it is stated that:
|
|     using std::ostream;
|
| would be just a short-hand for
|
|     using ostream = std::ostream;
|
| but we just saw that this is not going to be true in a class-scope and
| the proposal should have warned about this difference.

That will be made explicit in standardese for this fonctionality.

However, notice that you can't write, in current C++,

   using std::ostream;

at class-scope.  So it was implicitly assumed that the above rewrite
was for the case where the "optimized" version is already allowed.


--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: skaller@nospam.com.au ("John Max Skaller")
Date: Mon, 18 Oct 2004 22:23:38 GMT
Raw View
On Wed, 13 Oct 2004 05:12:04 +0000, Gabriel Dos Reis wrote:

> bloodymir.crap@gmx.net (Frank Birbacher) writes:

> | Yes, it's what I mean. But I wonder why they prefer
> |    template<typename T>
> |    using Vec = MyVector<T, MyAlloc<T> >
> | instead of the more intuitive (at least to me):
> |    template<typename T>
> |    typedef MyVector<T, MyAlloc<T> > Vec;
> | Where 'typedef' usually introduces aliases for types. I couldn't
> | understand the explanation in the proposal. Can anyone shed some light?
>
> Reasons are given in both papers.  For example, Vec is not a type so
> using "typedef" in that context is misleading (one could argue that
> "typedef" is already misnamed but we did not feel an urgent pressure
> to add more confusion).  Also "typedef" does not generalize to other
> aliasing constructs, as noted in the second paper.
>
> And the second paper discusses the choice of "using".

Another reason is new syntax can have new lookup rules,
in particular in the case

 using X = list<X>

can deem X comes into scope at the = sign.
That seems useful since C supports type recursion
easily .. but templates do not.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kmarkw65@yahoo.com (Mark Williams)
Date: Mon, 18 Oct 2004 17:25:22 CST
Raw View
gdr@cs.tamu.edu (Gabriel Dos Reis) wrote in message news:<m3655f6z5e.fsf@merlin.cs.tamu.edu>...
> bloodymir.crap@gmx.net (Frank Birbacher) writes:
>
> | Hi!
> |
> | Ben Hutchings wrote:
> | > Gabriel Dos Reis and Mat Marcus, Proposal to add template aliases to C++
> | > <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf>
> |
> | Yes, it's what I mean. But I wonder why they prefer
> |    template<typename T>
> |    using Vec = MyVector<T, MyAlloc<T> >
> | instead of the more intuitive (at least to me):
> |    template<typename T>
> |    typedef MyVector<T, MyAlloc<T> > Vec;
> | Where 'typedef' usually introduces aliases for types. I couldn't
> | understand the explanation in the proposal. Can anyone shed some light?
>
> Reasons are given in both papers.  For example, Vec is not a type so
> using "typedef" in that context is misleading

Im missing something.

A function template is not a function; a class template is not a
class; why would anyone expect a typedef template to be a type?

Mark Williams

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Tue, 19 Oct 2004 04:42:45 GMT
Raw View
Frank Birbacher wrote:
> Hi!
>
> Ben Hutchings wrote:
>
>> Gabriel Dos Reis and Mat Marcus, Proposal to add template aliases to C++
>> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf>
>
>
> Yes, it's what I mean. But I wonder why they prefer
>   template<typename T>
>   using Vec = MyVector<T, MyAlloc<T> >
> instead of the more intuitive (at least to me):
>   template<typename T>
>   typedef MyVector<T, MyAlloc<T> > Vec;
> Where 'typedef' usually introduces aliases for types. I couldn't
> understand the explanation in the proposal. Can anyone shed some light?
>

I think I understood the difference after reading the (real) typedef
template proposal:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1406.pdf

A typedef template is clearly not a typedef, as many have understood,
but its *instatiations* are typedefs. So a typedef template effectively
introduces a parametrized family of aliases each one representing a type.

OTOH, a template alias (notice that inversion: it's not "alias template"
intentionally!) introduce just *one* single alias that represents a
template.

The alias approach has a few advantages, clearly described in both
papers. In particular:

  * deduction works for template aliases
  * template aliases can be used as template template parameters

The cost is that a template alias cannot be specialized, but paper N1449
shows that this limitation is easily overcome using traits classes.

Hope I understood it correctly... ;-)

Alberto

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bloodymir.crap@gmx.net (Frank Birbacher)
Date: Thu, 21 Oct 2004 01:55:59 GMT
Raw View
Hi!

Mark Williams wrote:
>>Reasons are given in both papers.  For example, Vec is not a type so
>>using "typedef" in that context is misleading
>
>
> Im missing something.
>
> A function template is not a function; a class template is not a
> class; why would anyone expect a typedef template to be a type?

I agree, Mark. To me using 'template<...> typedef' seems most
natural. Alberto Barbati said so, too.

The word 'using' seems appropirate after reading the proposals.
But writing

struct Foo1
{
 template<typename T>
 using ArrayType = std::vector<T>;
//...
};

looks more like an implementation detail. And it has other
semantics as:

struct Foo2
{
 using std::vector;
//...
};

because 'Foo1::ArrayType' may be used as a template template
parameter, whereas 'Foo2::vector' may not. So instead of 'using'
an existing type, you 'define' a new name for an existing type.
Therefore use 'typedef'.

Frank

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bloodymir.crap@gmx.net (Frank Birbacher)
Date: Fri, 8 Oct 2004 17:37:53 GMT
Raw View
Hi!

Is there already a proposal for templated typedefs?

I thing it would be useful to do something like:

template<typename T1, typename T2>
struct Foo {};

template<typename T>
typedef Foo<T,T> Bar;

If this was allowed one could typedef a vector to vector1 and use
vector1 as a template<typename> parameter:

template<template<typename> Container>
struct WhatEver {...};

template<typename T>
typedef std::vector<T> vector1;

WhatEver<vector1> values;

Of course, there are ways to work around this problem:

struct container_function
{
   template<typename T>
   struct get_container
   {
 typedef std::vector<T> value;
   };
};

template<typename ContainerFunc>
struct WhatEver {...};

WhatEver<container_function> bar;

But that doesn't look nice.

So I'd like to have templated typedef added to the next standard.

Frank

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Date: Mon, 11 Oct 2004 16:12:06 GMT
Raw View
Frank Birbacher wrote:
> Hi!
>
> Is there already a proposal for templated typedefs?
<snip>

There has been a proposal for template aliases which could be used
for types, though using the "using" keyword rather than "typedef":

Gabriel Dos Reis and Mat Marcus, Proposal to add template aliases to C++
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf>

This was expanded in

Bjarne Stroustrup and Gabriel Dos Reis, Template aliases for C++
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1489.pdf>

--
Ben Hutchings
Lowery's Law:
             If it jams, force it. If it breaks, it needed replacing anyway.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bloodymir.crap@gmx.net (Frank Birbacher)
Date: Tue, 12 Oct 2004 21:57:20 GMT
Raw View
Hi!

Ben Hutchings wrote:
> Gabriel Dos Reis and Mat Marcus, Proposal to add template aliases to C++
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf>

Yes, it's what I mean. But I wonder why they prefer
   template<typename T>
   using Vec = MyVector<T, MyAlloc<T> >
instead of the more intuitive (at least to me):
   template<typename T>
   typedef MyVector<T, MyAlloc<T> > Vec;
Where 'typedef' usually introduces aliases for types. I couldn't
understand the explanation in the proposal. Can anyone shed some
light?

Frank

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gdr@cs.tamu.edu (Gabriel Dos Reis)
Date: Wed, 13 Oct 2004 05:12:04 GMT
Raw View
bloodymir.crap@gmx.net (Frank Birbacher) writes:

| Hi!
|
| Ben Hutchings wrote:
| > Gabriel Dos Reis and Mat Marcus, Proposal to add template aliases to C++
| > <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf>
|
| Yes, it's what I mean. But I wonder why they prefer
|    template<typename T>
|    using Vec = MyVector<T, MyAlloc<T> >
| instead of the more intuitive (at least to me):
|    template<typename T>
|    typedef MyVector<T, MyAlloc<T> > Vec;
| Where 'typedef' usually introduces aliases for types. I couldn't
| understand the explanation in the proposal. Can anyone shed some light?

Reasons are given in both papers.  For example, Vec is not a type so
using "typedef" in that context is misleading (one could argue that
"typedef" is already misnamed but we did not feel an urgent pressure
to add more confusion).  Also "typedef" does not generalize to other
aliasing constructs, as noted in the second paper.

And the second paper discusses the choice of "using".

--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jonathan.k.armstrong@cdev.com (J. Karl Armstrong)
Date: 1996/02/16
Raw View
Is there any reason why template typedefs are not allowed? Something like:

template <class T>
typedef T *GeneralPointer;

GeneralPointer<int> iptr;

Trivial example, I know, but there are reasons I would like this.

--
J. Karl Armstrong                            Computing Devices Int.
jonathan.k.armstrong@cdev.com                6041 S. Syracuse Way, Ste 300
(303) 779-7702                               Greenwood Villiage, CO, 80111
(303) 779-7704 (fax)
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]





Author: howlett@netcom.com (Scott Howlett)
Date: 1996/02/19
Raw View
jonathan.k.armstrong@cdev.com (J. Karl Armstrong) wrote:

> Is there any reason why template typedefs are not allowed? Something like:
>
> template <class T>
> typedef T *GeneralPointer;
>
> GeneralPointer<int> iptr;
>
> Trivial example, I know, but there are reasons I would like this.

I would find this convenient as well, but it's easy to get this
functionality in a slightly different way (and perhaps this is the reason
that it isn't supported directly?):

template <class T> struct foo {
    typedef T * GeneralPointer;
};

foo<T>::GeneralPointer iptr;

--
Scott Howlett, howlett@netcom.com
"Probably the earliest fly swatters were nothing more than some sort of
striking surface attached to the end of a long stick."
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]