We have a fairly sized C++ code base which uses signed 32-bit int
as the default integer data type. Due to changing requirements, it is necessary that we switch to 64-bit long
integers for a particular data structure. Changing the default integer data type in the entire program is not viable due to the significant memory overhead. On the other hand, we need to avoid that unaware developers mix 64-bit and 32-bit integers and create problems that only occur when very large data sets are handled (and which are thus hard to detect and even harder to debug).
Question: How can I create a zero-overhead 64-bit integer type that does not implicitly convert to other types (specifically, 32-bit integers) that is still "convenient" to use?
Or - if the above is not possible or sensible - what would be a good alternative to my proposed approach?
Example I'm thinking about creating a data structure like this:
class Int64 {
long value;
};
And then add c'tors for implicit construction, assignment, and operator overloads for arithmetic operations etc. However, I was not able to find a good resource online that might explain how to go about something like this and what the caveats are. Any suggestions?