title: Map from integer ranges to arbitrary single integers
body: <p>Working in C++ in a Linux environment, I have a situation where a number of integer ranges are defined, and integer inputs  map to different arbitrary integers based on which range they fall into.  None of the ranges overlap, and they aren't always contiguous. </p>
  
  <p>The "simplest" way to solve this problem is with a bunch of if-statements for each range, but the number of ranges, their bounds, and the target values can all vary, so if-statements aren't maintainable.</p>
  
  <p>For example, the ranges might be [0, 70], called r_a, [101, 150], call it r_b, and [201, 400], call it r_c.  Inputs in r_a map to 1, in r_b map to 2, and r_c map to 3.  Anything not in r_a, r_b, r_c maps to 0.  </p>
  
  <p>I can come up with a data structure &amp; algorithm that stores tuples of (bounds, map target) and iterates through them, so finding the target value takes linear time in the number of bounds pairs.  I can also imagine a scheme that keeps the pairs ordered and uses a binary sort-ish algorithm against all the lower bounds (or upper bounds), finds the closest to the input, then compares against the opposing bound.  </p>
  
  <p>Is there a better way to accomplish the mapping than a binary-search based algorithm?  Even better, is there some C++ library out that does this already?</p>