/cp
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / constexpr-array3.C
blob8cea41a1cb7184c8ce40bace983e9d679f49deda
1 // PR c++/69995
2 // { dg-do compile { target c++14 } }
4 #define assert(X) static_assert((X),#X)
6 #define CONSTEXPR constexpr
8 template <typename T, unsigned long Size>
9 struct array {
10     T elems_[Size];
12     constexpr T const& operator[](unsigned long n) const
13     { return elems_[n]; }
15     constexpr T& operator[](unsigned long n)
16     { return elems_[n]; }
19 template <typename T>
20 CONSTEXPR void my_swap(T& a, T& b) {
21     T tmp = a;
22     a = b;
23     b = tmp;
26 CONSTEXPR auto rotate2() {
27     array<array<int, 2>, 2> result{};
28     array<int, 2> a{{0, 1}};
30     result[0] = a;
31     my_swap(a[0], a[1]);
32     result[1] = a;
34     return result;
37 int main() {
38     CONSTEXPR auto indices = rotate2();
39     assert(indices[0][0] == 0);
40     assert(indices[0][1] == 1);
41     assert(indices[1][0] == 1);
42     assert(indices[1][1] == 0);