I’m trying to understand why standard_layout does not apply to ref types?
#include <type_traits>
struct X {
int y;
};
static_assert(std::is_standard_layout_v<X>);
static_assert(std::is_standard_layout_v<X&>); // does not compile
>Solution :
As you’ve found, is_standard_layout only works with an object type, not a reference.
As such, if you want either a type or a reference to a type, you could use:
static_assert(std::is_standard_layout_v<std::remove_reference_t<X>>);
remove_reference_t will yield the referred-to type for a reference, or the type itself if what you pass isn’t a reference (note: for older compilers, you can use std::remove_reference<T>::type).