exactly how stinky is this......

Hi all, suppose I need to store n number of AGE RANGES.....

13-26

34-44

51-87

I know that maps are supposed to be KEY/VALUE motivated, but there is also the TWO AND ONLY TWO NUMBERS motivation also isn't there?

Bad idea to use maps to store these? thx
I would use a vector of pairs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <utility>
#include <vector>
using namespace std;

typedef vector <pair <int, int> > age_ranges_t;

int main()
  {
  age_ranges_t ages;

  ages.push_back( make_pair( 13, 26 ) );
  ages.push_back( make_pair( 34, 44 ) );
  ...

Hope this helps.
Excellent! thanks.
And depending upon what you are going to do with the ranges, you might also consider writing a Range class. I'm guessing you are going to want to do things like determine whether or not a given age is within the range.
Topic archived. No new replies allowed.