xref: /llvm-project/libcxx/test/std/utilities/utility/mem.res/mem.res.aliases/header_string_synop.pass.cpp (revision f0fc8c4878ed3ed60bd7536f97ef2673eb691ae7)
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 // XFAIL: availability-pmr-missing
11 
12 // <string>
13 
14 // namespace std::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::pmr
25 
26 #include <string>
27 #include <cassert>
28 #include <memory_resource>
29 #include <type_traits>
30 
31 #include "constexpr_char_traits.h"
32 #include "test_macros.h"
33 
34 template <class Char, class PmrTypedef>
35 void test_string_typedef() {
36   using StdStr = std::basic_string<Char, std::char_traits<Char>, std::pmr::polymorphic_allocator<Char>>;
37   using PmrStr = std::pmr::basic_string<Char>;
38   static_assert(std::is_same<StdStr, PmrStr>::value, "");
39   static_assert(std::is_same<PmrStr, PmrTypedef>::value, "");
40 }
41 
42 template <class Char, class Traits>
43 void test_basic_string_alias() {
44   using StdStr = std::basic_string<Char, Traits, std::pmr::polymorphic_allocator<Char>>;
45   using PmrStr = std::pmr::basic_string<Char, Traits>;
46   static_assert(std::is_same<StdStr, PmrStr>::value, "");
47 }
48 
49 int main(int, char**) {
50   {
51     test_string_typedef<char, std::pmr::string>();
52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
53     test_string_typedef<wchar_t, std::pmr::wstring>();
54 #endif
55     test_string_typedef<char16_t, std::pmr::u16string>();
56     test_string_typedef<char32_t, std::pmr::u32string>();
57   }
58   {
59     test_basic_string_alias<char, constexpr_char_traits<char>>();
60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
61     test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>();
62 #endif
63     test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>();
64     test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>();
65   }
66   {
67     // Check that std::basic_string has been included and is complete.
68     std::pmr::string s;
69     assert(s.get_allocator().resource() == std::pmr::get_default_resource());
70   }
71 
72   return 0;
73 }
74