FreeBSD Manual Pages
std::is_layout_compatible(3) C++ Standard Libary std::is_layout_compatible(3) NAME std::is_layout_compatible - std::is_layout_compatible Synopsis Defined in header <type_traits> template< class T, class U > (since C++20) struct is_layout_compatible; If T and U are layout-compatible types, provides the member constant value equal to true. Otherwise value is false. Every type is layout-compatible with its any cv-qualified versions, even if it is not an object type. If T or U is not a complete type, (possibly cv-qualified) void, or an array of unknown bound, the behavior is undefined. If an instantiation of a template above depends, directly or indi- rectly, on an incomplete type, and that instantiation could yield a different re- sult if that type were hypothetically completed, the behavior is undefined. If the program adds specializations for std::is_layout_compatible or std::is_layout_compatible_v, the behavior is undefined. Member constants value true if T and U are layout-compatible, false otherwise [static] (public static member constant) Member functions operator bool converts the object to bool, returns value (public member function) operator() returns value (C++14) (public member function) Member types Type Definition value_type bool type std::integral_constant<bool, value> Notes A signed integer type and its unsigned counterpart are not layout- compatible. char is layout-compatible with neither signed char nor unsigned char. Similar types are not layout-compatible if they are not the same type after ignoring top-level cv-qualification. An enumeration type and its underlying type are not layout-compati- ble. Array types of layout-compatible but different element types (ignor- ing cv-qualification) are not layout-compatible, even if they are of equal length. Feature-test macro Value Std Feature __cpp_lib_is_layout_compatible 201907L (C++20) std::is_layout_com- patible Example // Run this code #include <iomanip> #include <iostream> #include <type_traits> struct Foo { int x; char y; }; struct FooNua { int x; [[no_unique_address]] char y; }; class Bar { const int u = 42; volatile char v = '*'; }; enum E0 : int {}; enum class E1 : int {}; static_assert ( std::is_layout_compatible_v<const void, volatile void> == true and std::is_layout_compatible_v<Foo, Bar> == true and std::is_layout_compatible_v<Foo[2], Bar[2]> == false and std::is_layout_compatible_v<int, E0> == false and std::is_layout_compatible_v<E0, E1> == true and std::is_layout_compatible_v<long, unsigned long> == false and std::is_layout_compatible_v<char*, const char*> == false and std::is_layout_compatible_v<char*, char* const> == true and std::is_layout_compatible_v<Foo, FooNua> == false // Note [1] ); // [1] MSVC erroneously fails this assert int main() {} See also is_standard_layout checks if a type is a standard-layout type (C++11) (class template) http://cppreference.com 2024.06.10 std::is_layout_compatible(3)
NAME | Synopsis | Member constants | Member functions | Member types | Notes | Example | See also
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::is_layout_compatible&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>
