std::map
Reading through your question again, I think you're saying that you have only 20 numbers to map (you said 20 digits, which made me think of very large numbers). If these are all in a fairly small range, you might be better off just using an array. You need an array of string pointers as large as largestIndex - smallestIndex + 1
. Then to get the string associated with a certain number, you'd do something like:
std::string GetStatus(int statusID){
return statusArray[statusID - smallestIndex];
}
The statusArray
variable is initialized with something like:
void SetStatus(int statusID, std::string description){
statusArray[statusID - smallestIndex] = description;
}
void InitStatuses(){
statusArray = new std::string[largestIndex - smallestIndex + 1];
SetStatus(1, "Request System Info");
SetStatus(2, "Change System Info");
SetStatus(10, "Unknown Error");
}
This would be faster than a map
, and pretty easy to use. It's just not appropriate if your IDs vary widely.