Thread View: comp.std.c++
1 messages
1 total messages
Started by Brent McPherson
Mon, 21 Aug 1995 17:03
Template instantiation question
Author: Brent McPherson
Date: Mon, 21 Aug 1995 17:03
Date: Mon, 21 Aug 1995 17:03
53 lines
2223 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads