brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 21d881c Raw
56 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// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <string_view>11 12//  template <contiguous_iterator _It, sized_sentinel_for<_It> _End>13//    basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;14 15#include <string_view>16#include <cassert>17 18#include "make_string.h"19#include "test_macros.h"20#include "test_iterators.h"21 22template <class It, class Sentinel, class CharT>23constexpr void test_ctad(std::basic_string_view<CharT> val) {24  auto sv = std::basic_string_view(It(val.data()), Sentinel(It(val.data() + val.size())));25  ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>);26  assert(sv.data() == val.data());27  assert(sv.size() == val.size());28}29 30template <class CharT>31constexpr void test_with_char() {32  const auto val = MAKE_STRING_VIEW(CharT, "test");33  test_ctad<CharT*, CharT*>(val);34  test_ctad<CharT*, const CharT*>(val);35  test_ctad<const CharT*, CharT*>(val);36  test_ctad<const CharT*, sized_sentinel<const CharT*>>(val);37  test_ctad<contiguous_iterator<const CharT*>, contiguous_iterator<const CharT*>>(val);38  test_ctad<contiguous_iterator<const CharT*>, sized_sentinel<contiguous_iterator<const CharT*>>>(val);39}40 41constexpr void test() {42  test_with_char<char>();43#ifndef TEST_HAS_NO_WIDE_CHARACTERS44  test_with_char<wchar_t>();45#endif46  test_with_char<char8_t>();47  test_with_char<char16_t>();48  test_with_char<char32_t>();49}50 51int main(int, char**) {52  test();53 54  return 0;55}56