newbarker
11/11/2008 9:13:00 AM
Thanks both,
The secondary comparison of addresses and reverting to a std::set will
do the trick thanks.
I certainly don't want to invoke undefined behaviour. Surely it's fine
as I'm comparing pointers to the same base?
Regards,
Pete
On 11 Nov, 02:56, Jerry Coffin <jcof...@taeus.com> wrote:
> In article <579f1be7-53ad-4d8b-adfc-902233ca5413
> @b38g2000prf.googlegroups.com>, acehr...@gmail.com says...
>
> [ ... ]
>
> > Here, you still need to order the two objects. If you don't have any
> > members, maybe the addresses will do:
>
> > return a < b;
>
> > but that would be undefined behavior, because it is undefined to
> > compare the addresses of objects that are not members of the same
> > array. (I think equality comparison would work but not the ordering
> > comparison e.g. with operator<.)
>
> Sort of true. A least IIRC, doing the comparison only gives unspecified
> results rather than being undefined behavior. More importantly, even
> though the result from using operator< to compare such addresses isn't
> specified, the result from using std::less _is_, at least to some
> extent. Specifically, even though there's no attempt to specify what the
> ordering of unrelated objects will be, the result of such a comparison
> will be repeatable and have the transitive property (e.g. if a<b and b
> <c, then a<c).
>
> --
> Later,
> Jerry.
>
> The universe is a figment of its own imagination.