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 

STL typedefs and incomplete types

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
John Grabner
Guest





PostPosted: Tue Sep 27, 2005 8:23 am    Post subject: STL typedefs and incomplete types Reply with quote



Given the following is it expected to compile. I need to use the
iterator definition in the actual definition of incomplete.

#include <map>

class incomplete;

typedef std::map<incomplete, int> myMap;
typedef myMap::iterator myMapIter;


John.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Maxim Yegorushkin
Guest





PostPosted: Tue Sep 27, 2005 2:32 pm    Post subject: Re: STL typedefs and incomplete types Reply with quote




John Grabner wrote:
Quote:
Given the following is it expected to compile.

No. The standard prohibits instantiating standard templates with
incomplete types.
http://devnet.developerpipeline.com/documents/s=9849/cujcexp2002austern/

I need to use the iterator definition in the actual definition of
incomplete.
Quote:

#include <map

class incomplete;

typedef std::map typedef myMap::iterator myMapIter;

You might like to redesign it. Provided information is not enough to
advise anything particular.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kanze
Guest





PostPosted: Tue Sep 27, 2005 2:33 pm    Post subject: Re: STL typedefs and incomplete types Reply with quote



John Grabner wrote:
Quote:
Given the following is it expected to compile. I need to use the
iterator definition in the actual definition of incomplete.

#include <map

class incomplete;

typedef std::map typedef myMap::iterator myMapIter;

No. The second typedef (if not the first) will provoke the
instantiation of the template, and the standard is clear:
instantiation of a template componant over an incomplete type is
undefined behavior.

--
James Kanze GABI Software mailto:james.kanze (AT) free (DOT) fr
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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
John Grabner
Guest





PostPosted: Wed Sep 28, 2005 10:13 am    Post subject: Re: STL typedefs and incomplete types Reply with quote

Quote:
#include <map

class incomplete;

typedef std::map typedef myMap::iterator myMapIter;


You might like to redesign it. Provided information is not enough to
advise anything particular.


Ok second try.

#include <map>
#include <vector>
#include <string>

class Incomplete;

typedef std::vector<incomplete> Incompletes;
typedef std::map<std::string, Incomplete> IncompleteDict;

class Incomplete
{
public:
explicit Incomplete(const Incompletes &incompletes);
explicit Incomplete(const IncompleteDict &dict);
};

Is this standards conforming?

John.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kanze
Guest





PostPosted: Thu Sep 29, 2005 8:15 pm    Post subject: Re: STL typedefs and incomplete types Reply with quote

John Grabner wrote:
Quote:
#include <map

class incomplete;

typedef std::map typedef myMap::iterator myMapIter;

You might like to redesign it. Provided information is not
enough to advise anything particular.

Ok second try.

#include <map
#include #include
class Incomplete;

typedef std::vector typedef std::map<std::string, Incomplete> IncompleteDict;

My current understanding is that the typedef's are legal. It is
undefined behavior to instantiate a template component of the
library with an incomplete type, but my understanding is that a
typedef does not trigger implicit instantiation.

I would really like it if someone who knows templates better
than I do would confirm this.

Quote:
class Incomplete
{
public:
explicit Incomplete(const Incompletes &incompletes);
explicit Incomplete(const IncompleteDict &dict);

Again, as long as only references to the standard classes are
used, there should be no problem. (In this case, there is an
explicit statement in the standard that declaring a reference or
a pointer to a template class does not trigger instantiation, so
I am pretty sure.)

Quote:
};

Is this standards conforming?

I think so. Note, however, that any code in the class
definition which uses the template class would not be; e.g. a
class member:
Incompletes children ;

--
James Kanze GABI Software
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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) 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.