49 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// class std::ranges::subrange;12// Test the example from LWG 3470,13// qualification conversions in __convertible_to_non_slicing14 15#include <ranges>16 17#include <cassert>18 19#include "test_macros.h"20 21constexpr bool test()22{23 // The example from LWG3470, using implicit conversion.24 int a[3] = { 1, 2, 3 };25 int* b[3] = { &a[2], &a[0], &a[1] };26 std::ranges::subrange<const int* const*> c = b;27 assert(c.begin() == b + 0);28 assert(c.end() == b + 3);29 30 // Also test CTAD and a subrange-to-subrange conversion.31 std::same_as<std::ranges::subrange<int**>> auto d = std::ranges::subrange(b);32 assert(d.begin() == b + 0);33 assert(d.end() == b + 3);34 35 std::ranges::subrange<const int* const*> e = d;36 assert(e.begin() == b + 0);37 assert(e.end() == b + 3);38 39 return true;40}41 42int main(int, char**)43{44 test();45 static_assert(test());46 47 return 0;48}49