🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2335

Template Instantiation

#2335
From: Michael Rice
Date: Sun, 29 Oct 1995 04:14
77 lines
2688 bytes
I have a question concerning class template instantitation, as described
in section 14.3.2 on the Sep 1995 WP.  

Paragraph 6 says:

An implementation shall not instantiate a function, nonvirtual member
function, class or member class that does not require instantiation.

The section goes on the give examples of a few cases that do require
instantiation and a few that do not require instantiation.  It seems
to me, that it should state EXACTLY when they are required and it 
doesn't seem to in this section.  Does it anywhere?  If it is not
stated implementations could decide anything in a requirement. Couldn't
they?  Take this example:

struct incomplete;

template<class T>
struct reverse_iterator {
  reverse_iterator ( );
  incomplete i;
};

typedef reverse_iterator<long> reverse_iterator1 ;

template < class T >
struct vector {
  vector ( );
};

main()
{
  vector < int > i ;
  return 0;
}
 
If an implementation decides the typedef above makes the instantiation
of reverse_iterator<long> required this code is ill-formed as the struct
incomplete is incomplete.

On the other hand, the implementation could say it is not required due to
this typedef (which seems correct to me.)  Now the code is well formed?

What about this:

template<class T>
struct reverse_iterator {
  reverse_iterator ( );
};

typedef reverse_iterator<long> reverse_iterator1 ;

template < class T >
struct vector {
  reverse_iterator1 rbegin ( ) { return reverse_iterator1 ( ) ; }
  vector ( );
};

main()
{
  vector < int > i ;
  return 0;
}

Is reverse_iterator<long> required to be instantiated here even though
the inline function is never called?  

Can someone point me in the right direction on when instantiations are
required?  Thanks.

-- 
Mike Rice                                                   Absoft Corporation
mpr@absoft.com                                                  (810) 853-0050
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9510272025.AA09665@absoft.absoft.com>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 29 Oct 95 04:14:28 GMT
Approved: fjh@cs.mu.oz.au
Organization: -
Newsgroups: comp.std.c++
Message-ID: <9510272025.AA09665@absoft.absoft.com>
Subject: Template Instantiation
X-Original-Date: Fri, 27 Oct 1995 16:25:38 +0000 (EDT)
From: "Michael Rice" <mpr@absoft.com>
X-Mailer: ELM [version 2.4 PL22]
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJMADeEDnX0m9pzZAQGEAAF/aa1Y+yZx3X98VE6a1ztKWNXAkYj1K/lT
 SN4kBg2LIvIprB6xq/F+k+U0/SS+FUEQ
 =Y3CY