Date: Mon, 26 Aug 2013 09:00:40 -0700
The library's running into problems because < is unspecified on
pointers that don't point to the same object. (C++14CD[expr.rel]p4)
Naively, this restriction makes a bit of sense, since we can't give a
particular answer for any two pointers, but it's causing problems for
some generic library components. Specifically:
std::map<T*> works because std::less has a special case for pointers.
([comparisons]p14)
std::map<std::tuple<T*>> gives undefined behavior because
std::less<tuple> uses tuple's operator<, which uses T*'s operator<.
std::map<std::optional<T*>> goes back to defined behavior because we
special-cased optional's operator< to use std::less:
[optional.relops]p4
Could someone explain why we need to allow operator<(T*) to be a non-order?
Thanks,
Jeffrey
pointers that don't point to the same object. (C++14CD[expr.rel]p4)
Naively, this restriction makes a bit of sense, since we can't give a
particular answer for any two pointers, but it's causing problems for
some generic library components. Specifically:
std::map<T*> works because std::less has a special case for pointers.
([comparisons]p14)
std::map<std::tuple<T*>> gives undefined behavior because
std::less<tuple> uses tuple's operator<, which uses T*'s operator<.
std::map<std::optional<T*>> goes back to defined behavior because we
special-cased optional's operator< to use std::less:
[optional.relops]p4
Could someone explain why we need to allow operator<(T*) to be a non-order?
Thanks,
Jeffrey
Received on 2013-08-26 18:01:02