Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Off topic: out of interest, what's the use case for customizing std::less in preference to free operator<? You're right that it provides a customization point, but I think it's a pretty obscure one: you want your type to be comparable by algorithms and containers, but not by code that normal human beings write ;-) Is there some annoying consequence of partial specialization that means sometimes you have to put up with that? Commented Jan 21, 2014 at 13:15
  • @SteveJessop The most annoying thing with free functions I can think of would be the Pitfalls of ADL, i.e. that ADL can also easily DoTheWrongThing(TM). There's no way to "control" ADL (other than to prohibit it). Yes, library writers can (and should) be defensive about this (by using ADL barrier namespaces). But function objects have the distinct property that they don't participate in ADL by definition. (I know Eric Niebler has advocated this and used it as a principle in designing Proto0x). Commented Jan 21, 2014 at 14:50
  • I don't know whether this was the design principle for the standard library. Perhaps they just wanted the ability to e.g. instantiate container types with a concrete comparator type, as opposed to having to initialize some kind of "generic function type" with a specific instance object on construction always. Commented Jan 21, 2014 at 14:50
  • yes, I see reasons for std::less to exist. It's just using it as the customization point for a user-defined type that I'm puzzled by: it's allowed but I don't think I've ever done it. Commented Jan 21, 2014 at 15:29