Topic: A more useful less
Author: "Sebastian Moleski" <smoleski@surakware.com>
Date: Wed, 1 Nov 2000 20:18:31 GMT Raw View
Specialize std::less.
Sebastian Moleski
SurakWare
http://www.surakware.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Michel Michaud <micm19@planet.cstjean.qc.ca>
Date: Mon, 30 Oct 2000 21:31:48 GMT Raw View
In the standard library, std::less::operator() will usually be
defined as returning something like param1<param2. I think it
could have been more useful to define it as
return (param1<param2)? true : false;
because the return type is bool, but we sometime have to deal
with pre ISO C++ classes* where < (and other operators) is
returning an int (used as a boolean such as BOOL/Bool/etc.).
In that case, the compiler will probably emit an annoying
warning...
I don't see if there would be any problem with having a better
(IMO) set of function objects in the next C++, although by
that time one would hope for all operator< to return a bool.
Do you see any problems ?
* for example CString from MFC...
--
Michel Michaud michel.michaud@planet.cstjean.qc.ca
http://www3.sympatico.ca/michel.michaud/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: Mon, 30 Oct 2000 21:46:37 GMT Raw View
"Michel Michaud" <micm19@planet.cstjean.qc.ca> wrote...
> In the standard library, std::less::operator() will usually be
> defined as returning something like param1<param2. I think it
> could have been more useful to define it as
>
> return (param1<param2)? true : false;
>
> because the return type is bool, but we sometime have to deal
> with pre ISO C++ classes* where < (and other operators) is
> returning an int (used as a boolean such as BOOL/Bool/etc.).
> In that case, the compiler will probably emit an annoying
> warning...
>
> I don't see if there would be any problem with having a better
> (IMO) set of function objects in the next C++, although by
> that time one would hope for all operator< to return a bool.
> Do you see any problems ?
>
> * for example CString from MFC...
The definition of the std::less::operator() is
bool operator()(const T&, const T&) const;
so, it already does the [implicit] conversion to bool (true
or false) in case your operator< returns something else. There
is no need in the explicit conversion, IMHO.
Victor
--
Please remove capital A's from my address when replying by mail
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Gabriel Dos Reis <gdr@merlin.codesourcery.com>
Date: Mon, 30 Oct 2000 22:19:10 GMT Raw View
Michel Michaud <micm19@planet.cstjean.qc.ca> writes:
| In the standard library, std::less::operator() will usually be
| defined as returning something like param1<param2. I think it
| could have been more useful to define it as
|
| return (param1<param2)? true : false;
|
| because the return type is bool, but we sometime have to deal
| with pre ISO C++ classes* where < (and other operators) is
| returning an int (used as a boolean such as BOOL/Bool/etc.).
| In that case, the compiler will probably emit an annoying
| warning...
Relevance of diagnostics and the code you showed above qualify as
QoI, and as such are out of scope of the standard.
An implementation which is unable to cope with its own runtime system
is broken and there is no point in requiring the Standard to fix it
:-).
--
Gabriel Dos Reis gdr@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
http://www.codesourcery.com/gcc-compile.shtml
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]