brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 75d492b Raw
86 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: !stdlib=libc++ && (c++03 || c++11 || c++14)10 11// <string_view>12 13// class iterator14 15#include <cassert>16#include <concepts>17#include <iterator>18#include <string_view>19 20#include "test_macros.h"21#include "make_string.h"22 23template <class CharT>24TEST_CONSTEXPR_CXX14 void test_type() {25  using C                  = std::basic_string_view<CharT>;26  typename C::iterator ii1 = typename C::iterator(), ii2 = typename C::iterator();27  typename C::iterator ii4       = ii1;28  typename C::const_iterator cii = typename C::const_iterator();29  assert(ii1 == ii2);30  assert(ii1 == ii4);31  assert(ii1 == cii);32 33  assert(!(ii1 != ii2));34  assert(!(ii1 != cii));35 36#if TEST_STD_VER >= 1737  C c = MAKE_STRING_VIEW(CharT, "abc");38  assert(c.begin() == std::begin(c));39  assert(c.rbegin() == std::rbegin(c));40  assert(c.cbegin() == std::cbegin(c));41  assert(c.crbegin() == std::crbegin(c));42 43  assert(c.end() == std::end(c));44  assert(c.rend() == std::rend(c));45  assert(c.cend() == std::cend(c));46  assert(c.crend() == std::crend(c));47 48  assert(std::begin(c) != std::end(c));49  assert(std::rbegin(c) != std::rend(c));50  assert(std::cbegin(c) != std::cend(c));51  assert(std::crbegin(c) != std::crend(c));52#endif53 54#if TEST_STD_VER >= 2055  // P1614 + LWG335256  std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;57  assert(r1 == std::strong_ordering::equal);58 59  std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;60  assert(r2 == std::strong_ordering::equal);61#endif62}63 64TEST_CONSTEXPR_CXX14 bool test() {65  test_type<char>();66#ifndef TEST_HAS_NO_WIDE_CHARACTERS67  test_type<wchar_t>();68#endif69#ifndef TEST_HAS_NO_CHAR8_T70  test_type<char8_t>();71#endif72  test_type<char16_t>();73  test_type<char32_t>();74 75  return true;76}77 78int main(int, char**) {79  test();80#if TEST_STD_VER >= 1481  static_assert(test(), "");82#endif83 84  return 0;85}86