Is there any guarantee on the size of an std::reference_wrapper?
The C++ standard does not pose any size requirements. Per [refwrap]
reference_wrapper<T>
is a Cpp17CopyConstructible and Cpp17CopyAssignable wrapper around a reference to an object or function of typeT
.reference_wrapper<T>
is a trivially copyable type.
All we know is that is copyable, and it is trivial. Other than that it it left up to the implementation. Typically it is just a wrapper for a T*
, but the implementation might have some other members in there for some reason
There is no guarantee in the standard.
No sensible implementation is going to use more than a pointer.
static_assert
it fits and you have enough alignment so your code is correct (and people can see it is correct). That static assert won't ever be hit.