Re: STL map question : directed to stl map expert(s)....
Craig Scott ha scritto:
Alberto Ganesh Barbati wrote:
Right in 5.9. Actually, the result of the comparison of *valid* pointers
pointing to element not in the same array is unspecified. It does not
lead to undefined behaviour.
Maybe this is dabbling in grey areas of the language, but what
does "unspecified" mean, strictly speaking? That *a* result can be
calculated safely, but that this result could be anything? Does unspecified
also mean not necessarily a repeatable result (which would be far more
problematic than simply unpredictable)?
Undefined and unspecified behavior are clearly defined in 1.3.12 and 1.3.13.
Although less<> is defined in terms of operator<, there is an additional
requriement for pointer types in 20.3.3/8: "For templates greater, less,
greater_equal, and less_equal, the specializations for any pointer type
yield a total order, even if the built-in operators <, >, <=, >= do not."
If less<T*> requires a total order, why then doesn't operator< also require
a total order for pointer types? This seems to be an omission from 5.9,
since less is defined in terms of operator<.
less<T*> does not _require_ a total order. less<T*> _provides_ a total
order, even if operator< may fail to provide it. Obviously, for pointer
types some magic (which might or might not involve operator<) might be
necessary to compute the result.
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]