1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11 
12 // class std::ranges::subrange;
13 //   Test the example from LWG 3470,
14 //   qualification conversions in __convertible_to_non_slicing
15 
16 #include <ranges>
17 
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
test()22 constexpr bool test()
23 {
24   // The example from LWG3470, using implicit conversion.
25   int a[3] = { 1, 2, 3 };
26   int* b[3] = { &a[2], &a[0], &a[1] };
27   std::ranges::subrange<const int* const*> c = b;
28   assert(c.begin() == b + 0);
29   assert(c.end() == b + 3);
30 
31   // Also test CTAD and a subrange-to-subrange conversion.
32   std::same_as<std::ranges::subrange<int**>> auto d = std::ranges::subrange(b);
33   assert(d.begin() == b + 0);
34   assert(d.end() == b + 3);
35 
36   std::ranges::subrange<const int* const*> e = d;
37   assert(e.begin() == b + 0);
38   assert(e.end() == b + 3);
39 
40   return true;
41 }
42 
main(int,char **)43 int main(int, char**)
44 {
45   test();
46   static_assert(test());
47 
48   return 0;
49 }
50