Re: Generic compare function
How would you actually use such a function?
Like I am using any other functions or functors.
How would it be implemented more efficiently than we can do for ourselves?
This can be told just about every thing including entire STL for
example. So I do not consider it an argument.
How would you determine which ordering was to be
used (many types have more then one logical ordering, and often include
equivalence sets)?
Just like it is done with default comparison operators and
functors. I
don't see any problem here.
Even std::string has multiple orderings depending on the collation rules.
And yet somehow this does not prevent us from comparing
std::string with
operator < for example...
How would you deal with types that have no ordering?
What about types that have equivalence sets but no ordering?
Again just like with comparison operators and functors. There
would be
no overload/specialization/whatever dedicated for them and any use of
generic compare function for them would result in compilation error.
It may seem a very simple thing to do but in fact it is very complicated
and far from trivial to provide generically.
I don't think so. After all "red floyd" posted and example
implementation.
And that is just all. A good generic fallback. But types like
std::string might use a smarter code to prevent suboptimal double
comparison. Compiler might even use extra machine code to provide
faster
versions for arithmetic types for example. But the bright side is that
user
of "compare" no longer cares. Using "compare" you ask what you want
directly: "what is the order relation of those to objects from
totally
ordered space?". And asking questions directly is a great thing
because it
makes it easier to give decent replay as fast as possible.
Adam Badura
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]