Suppose I'm writing C or C++ code which deals with... ok, let's make it citizens in a state. In this state, citizens have numeric id's (not strings - numbers); and for reasons of performance, or compatibility with other software, it is assumed there can be less than 2^32 citizens.
Now, in my code, I have a bunch of functions which take or return a citizen's numeric index; and other functions which take or return a number of citizens (e.g. number of people who were naturalized as citizens last year).
My dilemma regards the types. Do I:
- define a size-type, and use it for both student indices and numbers-of-students?
- define an index-type, and use it for both student indices and numbers-of-students?
- Define both, despite them actually being just aliases of each other?
I'm also not sure what name to use for them. It wouldn't be
citizen, as that would be a data type describing a student. Should it be something like
citizen_index_t? But then, what about the size type? It's not
citizen_size, after all... so -
I want to do this in a consistent, convincing and non-contrived way, but it seems like I only have bad options. Am I missing something?
Note: I can't just use
std::size_t due to the constraint I mentioned earlier, in case you were thinking of suggesting that.