Default comparisons - open-std

5 downloads 229 Views 228KB Size Report
Oct 11, 2014 - auto q = find_if(vr,[](Rec& a, Rec& b) { return a.name==b.name && a.id==b.id; }); ... exp
Stroustrup

Default comparisons

N4175 WG21-N4175 2014-10-11

Default comparisons Bjarne Stroustrup ([email protected])

Abstract Defining comparison operators (==, !=, =) for simple classes is tedious, repetitive, slightly error-prone, and easily automated. I propose to (implicitly) supply default versions of these operations, if needed. The semantics of = is equality of every member. The meaning of < is a lexicographical order of elements. If the simple defaults are unsuitable for a class, a programmer can, as ever, define more suitable ones or suppress the defaults.

1 The problem (status quo) Many algorithms require that an argument type supply comparison operations (e.g., == or