From: itaj sherman on 8 Aug 2010 23:51 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! ]
From: Dan McLeran on 11 Aug 2010 16:15 On Aug 9, 8:51 am, itaj sherman <itajsher...(a)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 -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: Shallow copy Next: why template version is prefered in this case |