1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-deduction-guides
12
13 // <string_view>
14
15 // Test that the constructors offered by std::basic_string_view are formulated
16 // so they're compatible with implicit deduction guides.
17
18 #include <string_view>
19 #include <cassert>
20
21 #include "test_macros.h"
22 #include "constexpr_char_traits.hpp"
23
24 // Overloads
25 // ---------------
26 // (1) basic_string_view() - NOT TESTED
27 // (2) basic_string_view(const basic_string_view&)
28 // (3) basic_string_view(const CharT*, size_type)
29 // (4) basic_string_view(const CharT*)
main()30 int main()
31 {
32 { // Testing (1)
33 // Nothing TODO. Cannot deduce without any arguments.
34 }
35 { // Testing (2)
36 const std::string_view sin("abc");
37 std::basic_string_view s(sin);
38 ASSERT_SAME_TYPE(decltype(s), std::string_view);
39 assert(s == "abc");
40
41 using WSV = std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>>;
42 const WSV win(L"abcdef");
43 std::basic_string_view w(win);
44 ASSERT_SAME_TYPE(decltype(w), WSV);
45 assert(w == L"abcdef");
46 }
47 { // Testing (3)
48 std::basic_string_view s("abc", 2);
49 ASSERT_SAME_TYPE(decltype(s), std::string_view);
50 assert(s == "ab");
51
52 std::basic_string_view w(L"abcdef", 4);
53 ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
54 assert(w == L"abcd");
55 }
56 { // Testing (4)
57 std::basic_string_view s("abc");
58 ASSERT_SAME_TYPE(decltype(s), std::string_view);
59 assert(s == "abc");
60
61 std::basic_string_view w(L"abcdef");
62 ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
63 assert(w == L"abcdef");
64 }
65 }
66