Debian Codegraph @

gcc/testsuite/g++.dg/cpp1z/constexpr-array1.C

raw
1 // PR c++/71504
2 // { dg-do compile { target c++17 } }
3
4 typedef __SIZE_TYPE__ size_t;
5 template <typename T, T v>
6 struct integral_constant
7 {
8 static constexpr T value = v;
9 typedef T value_type;
10 typedef integral_constant<T, v> type;
11 constexpr operator value_type () const noexcept { return value; }
12 constexpr value_type operator() () const noexcept { return value; }
13 };
14 template <typename T, T v>
15 constexpr T integral_constant<T, v>::value;
16 typedef integral_constant<bool, true> true_type;
17 typedef integral_constant<bool, false> false_type;
18 template <typename>
19 struct is_array : public false_type { };
20 template <typename T, size_t s>
21 struct is_array<T[s]> : public true_type { };
22 template <typename T>
23 struct is_array<T[]> : public true_type { };
24 template <bool, typename, typename>
25 struct conditional;
26 template <bool C, typename T, typename F>
27 struct conditional { typedef T type; };
28 template <typename T, typename F>
29 struct conditional<false, T, F> { typedef F type; };
30 template <typename T>
31 struct array_ref;
32 template <typename T>
33 using ref_t = typename conditional<is_array<T>::value, array_ref<T>, T&>::type;
34 template <typename T, unsigned N>
35 struct array_ref<T[N]>
36 {
37 T *a;
38 using const_reference = const ref_t<T>;
39 constexpr const_reference operator[] (unsigned I) const { return {a[I]}; }
40 };
41 template <typename A>
42 array_ref (A&) -> array_ref<A>;
43 constexpr int a2[2] = {1,2};
44 static_assert (array_ref{a2}[0] == 1);
45 constexpr int a22[2][2] = {{1,2},{3,4}};
46 static_assert (array_ref{a22}[0][0] == 1);