55 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++17, c++209 10// <string_view>11 12// template<class Range>13// basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++2314 15#include <string_view>16#include <cassert>17 18#include "make_string.h"19#include "test_iterators.h"20#include "test_macros.h"21 22template <class CharT>23void test() {24 auto val = MAKE_STRING(CharT, "test");25 auto sv = std::basic_string_view(val);26 ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>);27 assert(sv.size() == val.size());28 assert(sv.data() == val.data());29}30 31void test() {32 test<char>();33#ifndef TEST_HAS_NO_WIDE_CHARACTERS34 test<wchar_t>();35#endif36 test<char8_t>();37 test<char16_t>();38 test<char32_t>();39 test<char>();40 41 struct Widget {42 const char16_t* data_ = u"foo";43 contiguous_iterator<const char16_t*> begin() const { return contiguous_iterator<const char16_t*>(data_); }44 contiguous_iterator<const char16_t*> end() const { return contiguous_iterator<const char16_t*>(data_ + 3); }45 };46 std::basic_string_view bsv = std::basic_string_view(Widget());47 ASSERT_SAME_TYPE(decltype(bsv), std::basic_string_view<char16_t>);48}49 50int main(int, char**) {51 test();52 53 return 0;54}55