fork download
  1. #include <assert.h>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. template< class BaseObjectId >
  6. class Check
  7. {
  8. protected:
  9. Check( function<bool()> const f ) { assert( f() ); }
  10. };
  11.  
  12. template< int tpMinValue, int tpMaxValue >
  13. class IntegerSubrange
  14. : private Check< IntegerSubrange< tpMinValue, tpMaxValue > >
  15. {
  16. private:
  17. int value_;
  18.  
  19. public:
  20. enum :int { minValue = tpMinValue, maxValue = tpMaxValue };
  21.  
  22. static bool rangeContains( int const x )
  23. {
  24. return (minValue <= x && x <= maxValue);
  25. }
  26.  
  27. operator int() const
  28. {
  29. return value_;
  30. }
  31.  
  32. void operator/=( int const rhs )
  33. {
  34. value_ /= rhs;
  35. assert( rangeContains( value_ ) );
  36. }
  37.  
  38. explicit IntegerSubrange( int const value )
  39. : Check< IntegerSubrange< tpMinValue, tpMaxValue > >(
  40. [=]() -> bool { return rangeContains( value ); }
  41. )
  42. , value_( value )
  43. {}
  44. };
  45.  
  46. int main() {}
Success #stdin #stdout 0s 2880KB
stdin
Standard input is empty
stdout
Standard output is empty