Boost logo

Boost :

From: John E. Potter (jpotter_at_[hidden])
Date: 2000-11-28 00:31:17


On Mon, 27 Nov 2000, Matthew Austern wrote:

> See the writeup for library issue 270, in
> http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#270.
>
> There was some discussion of both options. There's a
> preliminary suggestion for what a relaxed requirement
> (in #2) might look like.
>
> However, when this issue was discussed in Toronto, there
> was some opposition to having this sort of relaxed requirement.
> Most people seemed to think it was inappropriate to allow a
> function object that had an operator()(value_type, T) and
> that didn't have an operator()(value_type, value_type).
> There was more discussion of what the requirements for a
> function object with both overloads might look like.
>
> Among other things, note that the standard talks about
> 'value_type < T' for lower_bound, 'T < value_type' for
> upper_bound, and both expressions for equal_range.

Yes. And, of course, binary_search requires both.

Thanks for the issue and the pointer. Note that this issue applies
equally to the functions without a compare object.

struct S { int a; int b; };
struct CompS {
   bool operator() (S lhs, S rhs) {
      return lhs.a < rhs.a;
      }
   };
bool operator< (S lhs, int rhs) { return lhs.a < rhs; }

vector<S> v;
// fill v
sort(v.begin(), v.end(), CompS());
cout << lower_bound(v.begin(), v.end(), 42)->b << endl;

Is this program ill-formed because there is no operator<(S, S)?

John


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk