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 // This feature is not yet ready in clang
14 // http://b/36401676
15 // XFAIL: *
16
17 // <string_view>
18
19 // Test that the constructors offered by std::basic_string_view are formulated
20 // so they're compatible with implicit deduction guides.
21
22 #include <string_view>
23 #include <cassert>
24
25 #include "test_macros.h"
26 #include "constexpr_char_traits.hpp"
27
28 // Overloads
29 // ---------------
30 // (1) basic_string_view() - NOT TESTED
31 // (2) basic_string_view(const basic_string_view&)
32 // (3) basic_string_view(const CharT*, size_type)
33 // (4) basic_string_view(const CharT*)
main()34 int main()
35 {
36 { // Testing (1)
37 // Nothing TODO. Cannot deduce without any arguments.
38 }
39 { // Testing (2)
40 const std::string_view sin("abc");
41 std::basic_string_view s(sin);
42 ASSERT_SAME_TYPE(decltype(s), std::string_view);
43 assert(s == "abc");
44
45 using WSV = std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>>;
46 const WSV win(L"abcdef");
47 std::basic_string_view w(win);
48 ASSERT_SAME_TYPE(decltype(w), WSV);
49 assert(w == L"abcdef");
50 }
51 { // Testing (3)
52 std::basic_string_view s("abc", 2);
53 ASSERT_SAME_TYPE(decltype(s), std::string_view);
54 assert(s == "ab");
55
56 std::basic_string_view w(L"abcdef", 4);
57 ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
58 assert(w == L"abcd");
59 }
60 { // Testing (4)
61 std::basic_string_view s("abc");
62 ASSERT_SAME_TYPE(decltype(s), std::string_view);
63 assert(s == "abc");
64
65 std::basic_string_view w(L"abcdef");
66 ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
67 assert(w == L"abcdef");
68 }
69 }
70