brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · f61f542 Raw
52 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 13#include <ranges>14 15#include "types.h"16#include <cassert>17#include "test_macros.h"18#include "test_iterators.h"19 20// convertible-to-non-slicing cases:21//   1. Not convertible (fail)22//   2. Only one is a pointer (succeed)23//   3. Both are not pointers (succeed)24//   4. Pointer elements are different types (fail)25//   5. Pointer elements are same type (succeed)26 27// !StoreSize ctor.28static_assert( std::is_constructible_v<ForwardSubrange, ForwardIter, ForwardIter>); // Default case.29static_assert(!std::is_constructible_v<ForwardSubrange, Empty, ForwardIter>); // 1.30static_assert( std::is_constructible_v<ConvertibleForwardSubrange, ConvertibleForwardIter, int*>); // 2.31static_assert( std::is_constructible_v<ForwardSubrange, ForwardIter, ForwardIter>); // 3. (Same as default case.)32// 4. and 5. must be sized.33 34constexpr bool test() {35  ForwardSubrange a(ForwardIter(globalBuff), ForwardIter(globalBuff + 8));36  assert(base(a.begin()) == globalBuff);37  assert(base(a.end()) == globalBuff + 8);38 39  ConvertibleForwardSubrange b(ConvertibleForwardIter(globalBuff), globalBuff + 8);40  assert(b.begin() == globalBuff);41  assert(b.end() == globalBuff + 8);42 43  return true;44}45 46int main(int, char**) {47  test();48  static_assert(test());49 50  return 0;51}52