home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1796 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.7 KB  |  47 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!sunic!news.lth.se!dag
  3. From: dag@bellman.control.lth.se (Dag Bruck)
  4. Subject: Re: Pointer comparisons and templates
  5. Message-ID: <1992Dec15.222952.17059@lth.se>
  6. Sender: news@lth.se
  7. Organization: Department of Automatic Control, Lund, Sweden
  8. 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>
  9. Date: Tue, 15 Dec 1992 22:29:52 GMT
  10. Lines: 35
  11.  
  12. In <comp.std.c++> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  13. >    You could always write the progam in terms of cmp(T,T),
  14. >not <. The it would work for pointers too, you would just
  15. >have to define cmp(T,T) for each type, including pointers,
  16.  
  17. I think that would be a serious effort, considering how many different
  18. types of pointers you have in an application.
  19.  
  20. >    template<class T> int cmp(T a1, T a2){return a1<a2;}
  21. >    int cmp(void* a1, void* a2){return ptrcmp(a1,a2)<0;}
  22.  
  23. I don't think this one flies.  For example,
  24.  
  25.     int* p;
  26.     int* q;
  27.     cmp(p, q);
  28.  
  29. probably causes a template overloading ambiguity.  You have to
  30. explicitly define a cmp() for every type of pointer you have, I think.
  31.  
  32. >    The real problem cannot be solved at all, namely, for
  33. >a user define < or cmp, ensuring it is a total order.
  34.  
  35. That is true, of course, for many applications.
  36.  
  37. I would also like to point out a few errors in the code for class Tree
  38. in an earlier posting.  The specializations for void* in a few places
  39. says "const void*&" which should be "void* const&".  Another error is
  40. that Insert() returns a T&, which should be a const T&.
  41.  
  42. The first error I made, and the fact that nobody found it, is a strong
  43. indication that specialization of templates is a real complication.
  44.  
  45.  
  46.                 -- Dag
  47.