File: value.cc

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (57 lines) | stat: -rw-r--r-- 2,075 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// { dg-do compile { target c++20 } }
// { dg-add-options no_pch }

#include <type_traits>

#ifndef __cpp_lib_is_layout_compatible
# error "Feature test macro for is_layout_compatible is missing in <type_traits>"
#elif __cpp_lib_is_layout_compatible < 201907L
# error "Feature test macro for is_layout_compatible has wrong value in <type_traits>"
#endif

template<typename T, typename U>
concept variable_template_is_correct
  = std::is_layout_compatible_v<T, U> == std::is_layout_compatible<T, U>::value;

template<typename T, typename U>
requires variable_template_is_correct<T, U>
constexpr bool is_layout_compatible = std::is_layout_compatible_v<T, U>;

static_assert( is_layout_compatible<void, void> );
static_assert( is_layout_compatible<int, int> );
static_assert( ! is_layout_compatible<int, int[]> );
static_assert( ! is_layout_compatible<int, int[1]> );
static_assert( is_layout_compatible<int[], int[]> );
static_assert( is_layout_compatible<int[1], int[1]> );
static_assert( ! is_layout_compatible<int[1], int[]> );
static_assert( ! is_layout_compatible<int[1], int[2]> );

struct Incomplete;
// The standard says these are undefined, but they should work really:
// static_assert( is_layout_compatible<Incomplete, Incomplete> );
// static_assert( ! is_layout_compatible<Incomplete[], Incomplete> );
static_assert( is_layout_compatible<Incomplete[], Incomplete[]> );

enum E1 : int { };
enum E2 : int;
static_assert( is_layout_compatible<E1, E2> );
enum E3 : unsigned int;
static_assert( ! is_layout_compatible<E1, E3> );
enum E4 : char { };
enum E5 : signed char { };
enum E6 : unsigned char { };
static_assert( ! is_layout_compatible<E4, E5> );
static_assert( ! is_layout_compatible<E4, E6> );
static_assert( ! is_layout_compatible<E5, E6> );

struct A { int a; };
struct B { const int b; };
static_assert( is_layout_compatible<A, B> );
static_assert( is_layout_compatible<B, A> );

struct C : A { };
struct D : B { };
static_assert( is_layout_compatible<C, D> );

struct E : A { int i; }; // not standard-layout
static_assert( ! is_layout_compatible<E, A> );