header_string_synop.pass.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. // UNSUPPORTED: c++98, c++03
  10. // <experimental/string>
  11. // namespace std { namespace experimental { namespace pmr {
  12. // template <class Char, class Traits = ...>
  13. // using basic_string =
  14. // ::std::basic_string<Char, Traits, polymorphic_allocator<Char>>
  15. //
  16. // typedef ... string
  17. // typedef ... u16string
  18. // typedef ... u32string
  19. // typedef ... wstring
  20. //
  21. // }}} // namespace std::experimental::pmr
  22. #include <experimental/string>
  23. #include <experimental/memory_resource>
  24. #include <type_traits>
  25. #include <cassert>
  26. #include "constexpr_char_traits.h"
  27. #include "test_macros.h"
  28. namespace pmr = std::experimental::pmr;
  29. template <class Char, class PmrTypedef>
  30. void test_string_typedef() {
  31. using StdStr = std::basic_string<Char, std::char_traits<Char>,
  32. pmr::polymorphic_allocator<Char>>;
  33. using PmrStr = pmr::basic_string<Char>;
  34. static_assert(std::is_same<StdStr, PmrStr>::value, "");
  35. static_assert(std::is_same<PmrStr, PmrTypedef>::value, "");
  36. }
  37. template <class Char, class Traits>
  38. void test_basic_string_alias() {
  39. using StdStr = std::basic_string<Char, Traits,
  40. pmr::polymorphic_allocator<Char>>;
  41. using PmrStr = pmr::basic_string<Char, Traits>;
  42. static_assert(std::is_same<StdStr, PmrStr>::value, "");
  43. }
  44. int main(int, char**)
  45. {
  46. {
  47. test_string_typedef<char, pmr::string>();
  48. test_string_typedef<wchar_t, pmr::wstring>();
  49. test_string_typedef<char16_t, pmr::u16string>();
  50. test_string_typedef<char32_t, pmr::u32string>();
  51. }
  52. {
  53. test_basic_string_alias<char, constexpr_char_traits<char>>();
  54. test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>();
  55. test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>();
  56. test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>();
  57. }
  58. {
  59. // Check that std::basic_string has been included and is complete.
  60. pmr::string s;
  61. assert(s.get_allocator().resource() == pmr::get_default_resource());
  62. }
  63. return 0;
  64. }