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! ]
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