C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

point of declaration regarding template aliases

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sun May 20, 2007 4:00 am    Post subject: point of declaration regarding template aliases Reply with quote



Why should the following declaration fail:

using cell = pair<int, cell*>;

I mean, after all wasn't it just like:

struct cell
{
int val;
cell* next;
};

?

The rationale given in N1489 seems to me like a circular proof:

template<class T>
using List = std::pair<T, List<T>*>; // ill-formed
The reason is that std::pair<T, List<T>*>is not an existing type since
there is no declaration for List.

The reason there is no declaration for List at the point is because
the rules said there shouldn't be.
But, using the above analogy, doesn't it make perfect sense that this
is just equal to:

template<typename T>
struct List
{
T t;
List<T>* next;
};

huh?

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Alberto Ganesh Barbati
Guest





PostPosted: Sun May 20, 2007 10:48 pm    Post subject: Re: point of declaration regarding template aliases Reply with quote



pongba (AT) gmail (DOT) com ha scritto:
Quote:
Why should the following declaration fail:

using cell = pair<int, cell*>;

I mean, after all wasn't it just like:

struct cell
{
int val;
cell* next;
};

?

The rationale given in N1489 seems to me like a circular proof:

template<class T
using List = std::pair<T, List<T>*>; // ill-formed
The reason is that std::pair<T, List<T>*>is not an existing type since
there is no declaration for List.

Paper N1489 is obsolete. The most recent revision of the proposal is
N2258 and says (added to 7.1.3/2 in the latest draft of the standard):

"A typedef-name can also be introduced by an alias-declaration. The
identifier following the using keyword becomes a typedef-name. It has
the same semantics as if it were introduced by the typedef specifier. In
particular, it does not define a new type and it cannot appear in the
type-id."

This statement seems defective to me. The problem here is the point of
declaration of cell in:

using cell = pair<int, cell*>;

If the statement had the same semantic as the typedef declaration

typedef pair<int, cell*> cell;

the code would be ill-formed because "cell" is undefined while parsing
the right hand side of "=". If this is the case, then the phrase "... it
cannot appear in the type-id" is pointless, because it can never occur.

However, if the point of declaration is just before "=", then the
statement would be no longer equivalent to the typedef:

typedef int T1;
typedef int T2;
void foo()
{
typedef std::pair<int, T1*> T1; // ok: T1 is pair<int, int*>
using T2 = std::pair<int, T2*>; // ill-formed
}

I believe the intent was to have this second interpretation. In this
case, it seems to me that: 1) a clarification about the point of
declaration should be added, 2) the "as-if a typedef" part might use
some rewording.

Notice that N2258 added this statement to 3.3.1/1: "The point of
declaration of a template alias immediately follows the identifier for
the alias being declared."

Why only "template" aliases are mentioned and not "generic" aliases?

As we are here, here's one more question, is the code

template <class T>
using cell = std::pair<int, cell<T>*>;

ill-formed or not? I could not find a statement as precise as 7.1.3/2
that says it's ill-formed and 3.3.1/1 makes me think it might be
well-formed.

I'm confused,

Ganesh

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
James Dennett
Guest





PostPosted: Mon May 21, 2007 2:21 am    Post subject: Re: point of declaration regarding template aliases Reply with quote



pongba (AT) gmail (DOT) com wrote:
Quote:
Why should the following declaration fail:

using cell = pair<int, cell*>;

I mean, after all wasn't it just like:

struct cell
{
int val;
cell* next;
};

?

It's much more like

typedef std::pair<int, cell*> cell;

in that it gives a new name to an existing construct,
whereas a class definition can create a new type as
well as giving it a name. C++ doesn't allow
self-referential typedefs, and I can't see that the
generalization to templates should allow it either.

-- James

---
[ 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.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.