1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++03
11 
12 // <experimental/string>
13 
14 // namespace std { namespace experimental { namespace pmr {
15 // template <class Char, class Traits = ...>
16 // using basic_string =
17 //     ::std::basic_string<Char, Traits, polymorphic_allocator<Char>>
18 //
19 // typedef ... string
20 // typedef ... u16string
21 // typedef ... u32string
22 // typedef ... wstring
23 //
24 // }}} // namespace std::experimental::pmr
25 
26 #include <experimental/string>
27 #include <experimental/memory_resource>
28 #include <type_traits>
29 #include <cassert>
30 
31 #include "constexpr_char_traits.h"
32 
33 #include "test_macros.h"
34 
35 namespace pmr = std::experimental::pmr;
36 
37 template <class Char, class PmrTypedef>
test_string_typedef()38 void test_string_typedef() {
39     using StdStr = std::basic_string<Char, std::char_traits<Char>,
40                                      pmr::polymorphic_allocator<Char>>;
41     using PmrStr = pmr::basic_string<Char>;
42     static_assert(std::is_same<StdStr, PmrStr>::value, "");
43     static_assert(std::is_same<PmrStr, PmrTypedef>::value, "");
44 }
45 
46 template <class Char, class Traits>
test_basic_string_alias()47 void test_basic_string_alias() {
48     using StdStr = std::basic_string<Char, Traits,
49                                      pmr::polymorphic_allocator<Char>>;
50     using PmrStr = pmr::basic_string<Char, Traits>;
51     static_assert(std::is_same<StdStr, PmrStr>::value, "");
52 }
53 
main(int,char **)54 int main(int, char**)
55 {
56     {
57         test_string_typedef<char,     pmr::string>();
58         test_string_typedef<wchar_t,  pmr::wstring>();
59         test_string_typedef<char16_t, pmr::u16string>();
60         test_string_typedef<char32_t, pmr::u32string>();
61     }
62     {
63         test_basic_string_alias<char,    constexpr_char_traits<char>>();
64         test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>();
65         test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>();
66         test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>();
67     }
68     {
69         // Check that std::basic_string has been included and is complete.
70         pmr::string s;
71         assert(s.get_allocator().resource() == pmr::get_default_resource());
72     }
73 
74   return 0;
75 }
76