vector<int> l;
for(int i=0;i<10;i++){
l.push_back(i);
}
I want the vector to only be able to store numbers from a specified range (or set). How can that be done, in general?
In particular, I want to restrict the vector to beonly be able to store single digits.
So, if I do a l[9]++
(in this case l[9]
is 9
), it should give me an error or warn me. (because 10
is not a single digit number). Similarly, l[0]--
should warn me.
Is there a way to do this using C++ STL vector
?