template<typename T>
void f()
{
if constexpr (std::is_trivial_v<T>)
{
// Does the following line never fail?
static_assert(std::is_standard_layout_v<T>);
}
}
是否 std::is_standard_layout_v<T>
始终为真,如果 std::is_trivial_v<T>
是真的吗?
如果不是,有没有反例?
#include <type_traits>
class type
{
public: int x;
private: int y;
};
static_assert(std::is_trivial_v< type >);
// not standard layout because different access level of x and y
static_assert(not std::is_standard_layout_v< type >);