Here is simple example,
We can define a low level union
like this :
static union
{
uint64_t a;
uint8_t b[8];
};
but we cannot declare std::variant
like this(please do not care about syntax,correct me if I am wrong!, just grab the idea)
std::variant<uint64_t, uint8_t[8]> v
cppReference stated clearly that,
Template parameters
Types - the types that may be stored in this variant. All types must be (possibly cv-qualified) non-array object type
also,MSVC-v141(C++17) compiler has given a compilation error:
Error C2338 variant requires all of the Ts to be non-array object types ([variant.variant]/2).
std::variant
is primarily a class template hence,
Problem is it unable to deduce array type storage, since it requires only data layout/representation ?