I'm writing C++ code, where the standard library has an idiomatic type for representing sizes:
Now, I'm writing a function which counts certain kinds of objects; and these objects have indices, used as their id's, which start from 0, with some indices in the middle possibly skipped due to device issues - although in practice they are never missing. Say these objects's index type is
idx_t. Also, to make this question non-trivial,
id_t is typically different, smaller than than
std::size_t. It is guaranteed that the number of objects isn't 2^
sizeof(idx_t), i.e. there are
idx_t values to spare.
My "philosophical" design question: Which type should a
count_objects() function return:
std::size_t, the standard size type, or
idx_t, the objects' numeric index type?
Please argue in favor of your choice.
- The objects' index type is a constraint, and cannot be altered, e.g. due to interaction with a device driver or third-party library.
- I believe this question isn't really C++ specific, but I wanted to make it less vague, so I didn't generalize much.
std::uint32_t, or or