1b6741d96SEric Fiselier //===----------------------------------------------------------------------===//
2b6741d96SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b6741d96SEric Fiselier //
7b6741d96SEric Fiselier //===----------------------------------------------------------------------===//
8b6741d96SEric Fiselier
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10b6741d96SEric Fiselier
11b6741d96SEric Fiselier // <string_view>
12b6741d96SEric Fiselier
13b6741d96SEric Fiselier // Test that the constructors offered by std::basic_string_view are formulated
14b6741d96SEric Fiselier // so they're compatible with implicit deduction guides.
15b6741d96SEric Fiselier
16b6741d96SEric Fiselier #include <string_view>
17b6741d96SEric Fiselier #include <cassert>
18b6741d96SEric Fiselier
19b6741d96SEric Fiselier #include "test_macros.h"
20cc89063bSNico Weber #include "constexpr_char_traits.h"
21b6741d96SEric Fiselier
22b6741d96SEric Fiselier // Overloads
23b6741d96SEric Fiselier // ---------------
24b6741d96SEric Fiselier // (1) basic_string_view() - NOT TESTED
25b6741d96SEric Fiselier // (2) basic_string_view(const basic_string_view&)
26b6741d96SEric Fiselier // (3) basic_string_view(const CharT*, size_type)
27b6741d96SEric Fiselier // (4) basic_string_view(const CharT*)
main(int,char **)282df59c50SJF Bastien int main(int, char**)
29b6741d96SEric Fiselier {
30b6741d96SEric Fiselier { // Testing (1)
319ff51bf9SLouis Dionne // Nothing to do. Cannot deduce without any arguments.
32b6741d96SEric Fiselier }
33b6741d96SEric Fiselier { // Testing (2)
34b6741d96SEric Fiselier const std::string_view sin("abc");
35b6741d96SEric Fiselier std::basic_string_view s(sin);
36b6741d96SEric Fiselier ASSERT_SAME_TYPE(decltype(s), std::string_view);
37b6741d96SEric Fiselier assert(s == "abc");
38b6741d96SEric Fiselier
39*f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
40b6741d96SEric Fiselier using WSV = std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>>;
41b6741d96SEric Fiselier const WSV win(L"abcdef");
42b6741d96SEric Fiselier std::basic_string_view w(win);
43b6741d96SEric Fiselier ASSERT_SAME_TYPE(decltype(w), WSV);
44b6741d96SEric Fiselier assert(w == L"abcdef");
45*f4c1258dSLouis Dionne #endif
46b6741d96SEric Fiselier }
47b6741d96SEric Fiselier { // Testing (3)
48b6741d96SEric Fiselier std::basic_string_view s("abc", 2);
49b6741d96SEric Fiselier ASSERT_SAME_TYPE(decltype(s), std::string_view);
50b6741d96SEric Fiselier assert(s == "ab");
51b6741d96SEric Fiselier
52*f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
53b6741d96SEric Fiselier std::basic_string_view w(L"abcdef", 4);
54b6741d96SEric Fiselier ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
55b6741d96SEric Fiselier assert(w == L"abcd");
56*f4c1258dSLouis Dionne #endif
57b6741d96SEric Fiselier }
58b6741d96SEric Fiselier { // Testing (4)
59b6741d96SEric Fiselier std::basic_string_view s("abc");
60b6741d96SEric Fiselier ASSERT_SAME_TYPE(decltype(s), std::string_view);
61b6741d96SEric Fiselier assert(s == "abc");
62b6741d96SEric Fiselier
63*f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
64b6741d96SEric Fiselier std::basic_string_view w(L"abcdef");
65b6741d96SEric Fiselier ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
66b6741d96SEric Fiselier assert(w == L"abcdef");
67*f4c1258dSLouis Dionne #endif
68b6741d96SEric Fiselier }
692df59c50SJF Bastien
702df59c50SJF Bastien return 0;
71b6741d96SEric Fiselier }
72