The following is a not-really-portable, but working solution:
static_assert(sizeof(uint_fast64_t) == sizeof(unsigned long long), "This code relies on equivalence of uint_fast64_t and unsigned long long");
std::vector<uint_fast64_t, std::allocator<uint_fast64_t>> src;
std::vector<unsigned long long, std::allocator<unsigned long long>> &after_cast =
*reinterpret_cast<std::vector<unsigned long long, std::allocator<unsigned long long>> *>(&src);
You have to compile this with strict type aliasing turned off (such as Clang's -fno-strict-aliasing
).
It relies on behaviour which is undefined in the standard, but by passing the appropriate compiler flag(s), you can actually make your compiler provide a consistent definition.