Article View: comp.std.c++
Article #1252Re: Pointer comparisons and templates
From: Dag Bruck
Date: Tue, 15 Dec 1992 22:29
Date: Tue, 15 Dec 1992 22:29
35 lines
1800 bytes
1800 bytes
In <comp.std.c++> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
> You could always write the progam in terms of cmp(T,T),
>not <. The it would work for pointers too, you would just
>have to define cmp(T,T) for each type, including pointers,
I think that would be a serious effort, considering how many different
types of pointers you have in an application.
> template<class T> int cmp(T a1, T a2){return a1<a2;}
> int cmp(void* a1, void* a2){return ptrcmp(a1,a2)<0;}
I don't think this one flies. For example,
int* p;
int* q;
cmp(p, q);
probably causes a template overloading ambiguity. You have to
explicitly define a cmp() for every type of pointer you have, I think.
> The real problem cannot be solved at all, namely, for
>a user define < or cmp, ensuring it is a total order.
That is true, of course, for many applications.
I would also like to point out a few errors in the code for class Tree
in an earlier posting. The specializations for void* in a few places
says "const void*&" which should be "void* const&". Another error is
that Insert() returns a T&, which should be a const T&.
The first error I made, and the fact that nobody found it, is a strong
indication that specialization of templates is a real complication.
-- Dag
Technical Details
Message-ID:
<1992Dec15.222952.17059@lth.se>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!news.lth.se!dagReferences:
<1992Dec9.075125.22405@lth.se> <1992Dec12.154918.2220@ucc.su.OZ.AU> <1992Dec14.075853.3399@lth.se> <1992Dec15.164854.13070@ucc.su.OZ.AU>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!news.lth.se!dag From: dag@bellman.control.lth.se (Dag Bruck) Subject: Re: Pointer comparisons and templates Message-ID: <1992Dec15.222952.17059@lth.se> Sender: news@lth.se Organization: Department of Automatic Control, Lund, Sweden References: <1992Dec9.075125.22405@lth.se> <1992Dec12.154918.2220@ucc.su.OZ.AU> <1992Dec14.075853.3399@lth.se> <1992Dec15.164854.13070@ucc.su.OZ.AU> Date: Tue, 15 Dec 1992 22:29:52 GMT Lines: 35