Title
pair<T,U> doesn't model LessThanComparable in unconstrained code even if T and U do.
Status
nad concepts
Section
[pairs]
Submitter
Dave Abrahams

Created on 2009-07-01.00:00:00 last changed 188 months ago

Messages

Date: 2009-07-01.00:00:00

LessThanComparable requires (and provides default implementations for) <=,>, and >=. However, the defaults don't take effect in unconstrained code.

Still, it's a problem to have types acting one way in constrained code and another in unconstrained code, except in cases of syntax adaptation. It's also inconsistent with the containers, which supply all those operators.

Totally Unbiased Suggested Resolution:

accept the exported concept maps proposal and change the way this stuff is handled to use an explicit exported concept map rather than nested function templates

e.g., remove from the body of std::list

template <LessThanComparable T, class Allocator> 
bool operator< (const list<T,Allocator>& x, const list<T,Allocator>& y); 
template <LessThanComparable T, class Allocator> 
bool operator> (const list<T,Allocator>& x, const list<T,Allocator>& y); 
template <LessThanComparable T, class Allocator> 
bool operator>=(const list<T,Allocator>& x, const list<T,Allocator>& y); 
template <LessThanComparable T, class Allocator> 
bool operator<=(const list<T,Allocator>& x, const list<T,Allocator>& y); 

and add this concept_map afterwards:

template <LessThanComparable T, class Allocator> 
export concept_map LessThanComparable<list<T,Allocator> >
{
    bool operator<(const list<T,Allocator>& x, const list<T,Allocator>& y);
}

do similarly for std::pair. While you're at it, do the same for operator== and != everywhere, and seek out other such opportunities.

Alternative Resolution: keep the ugly, complex specification and add the missing operators to std::pair.

History
Date User Action Args
2009-07-01 00:00:00admincreate