🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Template instantiation question

#1762
From: Brent McPherson
Date: Mon, 21 Aug 1995 17:03
53 lines
2223 bytes
Distribution:
I've got a question regarding template instantiation and was wondering
if any of this behaviour is covered under the emerging C++ draft standard.

I have seen template classes that define methods that will only *work*
if the instantiation type provides certain methods/functionality.

ie.

  template<class T>
  class Foo {
  public:
     Foo (const T &t) : myT(T) {}
     // etc...
     int compare (const T &otherT) 
     { 
       return (myT < otherT ? -1 : myT > otherT ? 1 : 0);
     }
     // etc...
  };

In this example the "compare" method relies on the object of type T
having comparison operators.

Is it legal to allow Foo to be instantiated with an object that does
not support comparison as long as the compare method is never called
for that particular instantiation?

Compilers with "demand-only" instantiation seem to allow this (as well
as not catching many syntax errors in template code but that is another
problem).

So, what is the verdict on this type of template usage?

Note: please provide supporting arguments relating to the emerging draft
standard instead of providing "I think..."-type reponses. (since I already
have my own theories on whether this *should* be legal)

Also, does anyone know if any template libraries like STL rely on this type
of template instantiation behaviour?

Thanks in advance!
--
Brent McPherson                 |   Alias | Wavefront Inc.
Senior Software Engineer        |   110 Richmond St. E.
E-Mail: bmcphers@aw.sgi.com     |   Toronto, CANADA  M5C 1P1
Phone: (416) 362-8558 ext.212   |   http://www.aw.sgi.com
-- 

---
[ 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: <MATT.95Aug21100336@physics10.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: bmcphers@alias.com (Brent McPherson)
Newsgroups: comp.std.c++
Subject: Template instantiation question
Date: 21 Aug 1995 17:03:36 GMT
Organization: R+D Alias Research
Approved: matt@physics10.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Aug21100336@physics10.Berkeley.EDU>
NNTP-Posting-Host: physics10.berkeley.edu