title: Limiting range of value types in C++
body: <p>Suppose I have a LimitedValue class which holds a value, and is parameterized on int types 'min' and 'max'.  You'd use it as a container for holding values which can only be in a certain range.  You could use it such:</p>
  
  <pre><code>LimitedValue&lt; float, 0, 360 &gt; someAngle( 45.0 );
  someTrigFunction( someAngle );
  </code></pre>
  
  <p>so that 'someTrigFunction' knows that it is guaranteed to be supplied a valid input (The constructor would throw an exception if the parameter is invalid).</p>
  
  <p>Copy-construction and assignment are limited to exactly equal types, though.  I'd like to be able to do:</p>
  
  <pre><code>LimitedValue&lt; float, 0, 90 &gt; smallAngle( 45.0 );
  LimitedValue&lt; float, 0, 360 &gt; anyAngle( smallAngle );
  </code></pre>
  
  <p>and have that operation checked at compile-time, so this next example gives an error:</p>
  
  <pre><code>LimitedValue&lt; float, -90, 0 &gt; negativeAngle( -45.0 );
  LimitedValue&lt; float, 0, 360 &gt; postiveAngle( negativeAngle ); // ERROR!
  </code></pre>
  
  <p>Is this possible?  Is there some practical way of doing this, or any examples out there which approach this?</p>