brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · e59e2b2 Raw
89 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//  constexpr basic_string_view(const _CharT* _s, size_type _len)14//      : __data (_s), __size(_len) {}15 16#include <string_view>17#include <string>18#include <cassert>19 20#include "test_macros.h"21 22template <typename CharT>23void test(const CharT* s, std::size_t sz) {24  {25    typedef std::basic_string_view<CharT> SV;26    LIBCPP_ASSERT_NOEXCEPT(SV(s, sz));27 28    SV sv1(s, sz);29    assert(sv1.size() == sz);30    assert(sv1.data() == s);31  }32}33 34int main(int, char**) {35  test("QBCDE", 5);36  test("QBCDE", 2);37  test("", 0);38#if TEST_STD_VER > 1139  {40    constexpr const char* s = "QBCDE";41    constexpr std::basic_string_view<char> sv1(s, 2);42    static_assert(sv1.size() == 2, "");43    static_assert(sv1.data() == s, "");44  }45#endif46 47#ifndef TEST_HAS_NO_WIDE_CHARACTERS48  test(L"QBCDE", 5);49  test(L"QBCDE", 2);50  test(L"", 0);51#  if TEST_STD_VER > 1152  {53    constexpr const wchar_t* s = L"QBCDE";54    constexpr std::basic_string_view<wchar_t> sv1(s, 2);55    static_assert(sv1.size() == 2, "");56    static_assert(sv1.data() == s, "");57  }58#  endif59#endif // TEST_HAS_NO_WIDE_CHARACTERS60 61#if TEST_STD_VER >= 1162  test(u"QBCDE", 5);63  test(u"QBCDE", 2);64  test(u"", 0);65#  if TEST_STD_VER > 1166  {67    constexpr const char16_t* s = u"QBCDE";68    constexpr std::basic_string_view<char16_t> sv1(s, 2);69    static_assert(sv1.size() == 2, "");70    static_assert(sv1.data() == s, "");71  }72#  endif73 74  test(U"QBCDE", 5);75  test(U"QBCDE", 2);76  test(U"", 0);77#  if TEST_STD_VER > 1178  {79    constexpr const char32_t* s = U"QBCDE";80    constexpr std::basic_string_view<char32_t> sv1(s, 2);81    static_assert(sv1.size() == 2, "");82    static_assert(sv1.data() == s, "");83  }84#  endif85#endif86 87  return 0;88}89