
On Sep 23, 2011, at 12:01 PM, Jeffrey Lee Hellrung, Jr. wrote:
On Fri, Sep 23, 2011 at 9:34 AM, Marshall Clow <mclow.lists@gmail.com>wrote:
On Sep 23, 2011, at 9:21 AM, Phil Endecott wrote:
Dear All,
Some quick comments about the proposed clamp() function:
[...]
Like min & max, clamp has a single type template parameter; what are the implications of this? For example, if I pass a mixture of std::string and const char* arguments, what will happen? Ideally, (a) all combinations would compile, and (b) conversions from const char* to std::string will only happen when necessary, not unconditionally for all of the arguments. (Maybe that is asking too much, though.)
Dunno; I'll put it on the list of things to think about.
Isn't this *precisely* why we have common_type now? :)
I haven't actually looked at the documentation, but I'm gathering that std::less<T> is the default comparison function object, in which case I would suggest this should be replaced with some other function object with a templated operator() that wraps operator<; this should avoid unnecessary temporaries in more cases.
Are you talking about something like this? (typed w/o benefit of compiler) namespace boost { struct less { typedef bool result_type; template <typename T> // T models Regular bool operator()(const T& x, const T& y) const { return std::less<T>()(x, y); } template <typename T, typename U> bool operator ()(const T& x, const U&y) const { return std::less<boost::common_type<T, U>() ( x, y )); } }; } -- Marshall Marshall Clow Idio Software <mailto:mclow.lists@gmail.com> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki