Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there std function that calculates a bounded value?

4 views
Skip to first unread message

itaj sherman

unread,
Aug 9, 2010, 10:51:29 AM8/9/10
to
Is there a boost/std equivalent to:

template< typename rc >
rc Bounded( rc const& rValue, rc const& rLowest, rc const& rHighest )
{
assert( !( rHighest < rLowest ) );
if( rLowest < rValue ) {
if( rValue < rHighest ) {
return rValue;
} else {
return rHighest;
}
} else {
return rLowest;
}
}

For strictly ordered types: if ( a<=b ) then ( Bounded( x, a, b ) ==
min( max( x, a ), b ) )
Also the deduction might be fixed to be based only on the first
argument (but it's not crucial for me).

itaj

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Dan McLeran

unread,
Aug 12, 2010, 3:15:28 AM8/12/10
to
On Aug 9, 8:51 am, itaj sherman <itajsher...@gmail.com> wrote:
> Is there a boost/std equivalent to:
>
> template< typename rc >
> rc Bounded( rc const& rValue, rc const& rLowest, rc const& rHighest )
> {
> assert( !( rHighest < rLowest ) );
> if( rLowest < rValue ) {
> if( rValue < rHighest ) {
> return rValue;
> } else {
> return rHighest;
> }
> } else {
> return rLowest;
> }
>
> }

Not yet but I assisted in the creation of a library that is pending
Boost approval and inclusion:
http://student.agh.edu.pl/~kawulak/constrained_value/constrained_value/introduction.html

0 new messages