Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Andrew Sutton (asutton.list_at_[hidden])
Date: 2011-09-25 13:09:55


>> No, no, no.  Sorry to be so hard-line about this, but no.

> So the cost of the extra char*-to-string conversions with the 1-type version
> of clamp increases the execution time of that function by more than 3X.

> Personally, I value that performance benefit above the easier-to-describe
> semantics that you want.

I keep implying there's a middle ground. I guess I'll be more explicit.

Every example given in this thread where different types should be
comparable are related (or should be related) through common type:
- int and double
- types with different Allocators (should be)
- std::duration with different Periods
- const char* and string
You can map semantics of operations on these different types to their
common type, and still be able to reason about the correctness of the
algorithm.

That means you could have an algorithm that takes different types with
a requirement that they share a common type. You get the performance
gains from your previous example, and you get the correctness that we
should expect from Boost libraries.

If you want to compare unrelated types, use a version of the algorithm
not written in terms of <.


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