auto lo = 0u;
auto hi = 1u;
auto combined = (((std::uint64_t)hi) << 32) | lo;
But if I do combined++ then lo and hi are not changed, because combined is a copy.
How do I make the lower bits of combined reference lo, and the upper bits reference hi, so when I do arithmetic on combined, lo and hi are also updated?
I would sidestep the whole issue by creating simple get_lo () and get_hi () accessor functions to extract the relevant halves of your int64 and call them when needed:
#include <cstdint>
std::uint32_t get_lo (std::uint64_t combined) { return static_cast <std::uint32_t> (combined); }
std::uint32_t get_hi (std::uint64_t combined) { return static_cast <std::uint32_t> (combined >> 32); }
I really don't see the need for anything more elaborate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With