I'm trying to learn C++ by doing everything "the C++ way". I'm writing a program where I have all of these known values (at compile time). Here is my problem:
In my constructor I want to check to see if a passed value(an int) is one of 2,4,8,16 or 32 and throw an error elsewise. I've though about:
- making a C style array or ints
- creating a vector before by hand and interating through it to check
- making a list? I've never used lists before though.
What I really want to do is make a const vector in a separate header file, this doesn't seem possible though.
What is the most elegant way to do this check?
Also, similarly is there any way to make a vector with a set number of known values (at compile time) in a header? If I can do const std::string a_str("a string");
I don't see why I can't use a similar technique for vectors.