| 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 | // TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed |
| 11 | // UNSUPPORTED: availability-pmr-missing |
| 12 | |
| 13 | // <string> |
| 14 | |
| 15 | // namespace std::pmr { |
| 16 | // template <class Char, class Traits = ...> |
| 17 | // using basic_string = |
| 18 | // ::std::basic_string<Char, Traits, polymorphic_allocator<Char>> |
| 19 | // |
| 20 | // typedef ... string |
| 21 | // typedef ... u16string |
| 22 | // typedef ... u32string |
| 23 | // typedef ... wstring |
| 24 | // |
| 25 | // } // namespace std::pmr |
| 26 | |
| 27 | #include <string> |
| 28 | #include <cassert> |
| 29 | #include <memory_resource> |
| 30 | #include <type_traits> |
| 31 | |
| 32 | #include "constexpr_char_traits.h" |
| 33 | #include "test_macros.h" |
| 34 | |
| 35 | template <class Char, class PmrTypedef> |
| 36 | void test_string_typedef() { |
| 37 | using StdStr = std::basic_string<Char, std::char_traits<Char>, std::pmr::polymorphic_allocator<Char>>; |
| 38 | using PmrStr = std::pmr::basic_string<Char>; |
| 39 | static_assert(std::is_same<StdStr, PmrStr>::value, "" ); |
| 40 | static_assert(std::is_same<PmrStr, PmrTypedef>::value, "" ); |
| 41 | } |
| 42 | |
| 43 | template <class Char, class Traits> |
| 44 | void test_basic_string_alias() { |
| 45 | using StdStr = std::basic_string<Char, Traits, std::pmr::polymorphic_allocator<Char>>; |
| 46 | using PmrStr = std::pmr::basic_string<Char, Traits>; |
| 47 | static_assert(std::is_same<StdStr, PmrStr>::value, "" ); |
| 48 | } |
| 49 | |
| 50 | int main(int, char**) { |
| 51 | { |
| 52 | test_string_typedef<char, std::pmr::string>(); |
| 53 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 54 | test_string_typedef<wchar_t, std::pmr::wstring>(); |
| 55 | #endif |
| 56 | test_string_typedef<char16_t, std::pmr::u16string>(); |
| 57 | test_string_typedef<char32_t, std::pmr::u32string>(); |
| 58 | } |
| 59 | { |
| 60 | test_basic_string_alias<char, constexpr_char_traits<char>>(); |
| 61 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 62 | test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>(); |
| 63 | #endif |
| 64 | test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>(); |
| 65 | test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>(); |
| 66 | } |
| 67 | { |
| 68 | // Check that std::basic_string has been included and is complete. |
| 69 | std::pmr::string s; |
| 70 | assert(s.get_allocator().resource() == std::pmr::get_default_resource()); |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |