Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: TONGARI (tongari95_at_[hidden])
Date: 2011-09-27 10:44:21


2011/9/27 Steven Watanabe <watanabesj_at_[hidden]>

> AMDG
>
> On 09/27/2011 07:23 AM, Gordon Woodhull wrote:
> >
> >
> > On Sep 26, 2011, at 2:17 PM, TONGARI <tongari95_at_[hidden]> wrote:
> >
> >> 2011/9/27 Peter Dimov <pdimov_at_[hidden]>
> >>
> >>> Then clamp should be
> >>>
> >>> template<class T> T clamp( T const & value,
> >>> typename identity<T>::type const & low,
> >>> typename identity<T>::type const & high );
> >>
> >>
> >> I second this. BTW, The return type could be T const&.
> >
> > Okay, I'll bite. Why identity and not just T?
> >
> > (I thought this might be a joke at first.)
> >
>
> Using identity means that T is deduced
> solely based on the first argument.
>

And thus has the benefit that low and high aren't necessary to be exactly T,
just some type that can be implicitly converted to T.


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