implicit_deduction_guides.pass.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // UNSUPPORTED: libcpp-no-deduction-guides
  11. // <string>
  12. // Test that the constructors offered by std::basic_string are formulated
  13. // so they're compatible with implicit deduction guides.
  14. #include <tuple>
  15. #include <memory>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #include "archetypes.hpp"
  19. // Overloads
  20. // using A = Allocator
  21. // using AT = std::allocator_arg_t
  22. // ---------------
  23. // (1) tuple(const Types&...) -> tuple<Types...>
  24. // (2) explicit tuple(const Types&...) -> tuple<Types...>
  25. // (3) tuple(AT, A const&, Types const&...) -> tuple<Types...>
  26. // (4) explicit tuple(AT, A const&, Types const&...) -> tuple<Types...>
  27. // (5) tuple(tuple const& t) -> decltype(t)
  28. // (6) tuple(tuple&& t) -> decltype(t)
  29. // (7) tuple(AT, A const&, tuple const& t) -> decltype(t)
  30. // (8) tuple(AT, A const&, tuple&& t) -> decltype(t)
  31. void test_primary_template()
  32. {
  33. const std::allocator<int> A;
  34. const auto AT = std::allocator_arg;
  35. { // Testing (1)
  36. int x = 101;
  37. std::tuple t1(42);
  38. ASSERT_SAME_TYPE(decltype(t1), std::tuple<int>);
  39. std::tuple t2(x, 0.0, nullptr);
  40. ASSERT_SAME_TYPE(decltype(t2), std::tuple<int, double, decltype(nullptr)>);
  41. }
  42. { // Testing (2)
  43. using T = ExplicitTestTypes::TestType;
  44. static_assert(!std::is_convertible<T const&, T>::value, "");
  45. std::tuple t1(T{});
  46. ASSERT_SAME_TYPE(decltype(t1), std::tuple<T>);
  47. const T v{};
  48. std::tuple t2(T{}, 101l, v);
  49. ASSERT_SAME_TYPE(decltype(t2), std::tuple<T, long, T>);
  50. }
  51. { // Testing (3)
  52. int x = 101;
  53. std::tuple t1(AT, A, 42);
  54. ASSERT_SAME_TYPE(decltype(t1), std::tuple<int>);
  55. std::tuple t2(AT, A, 42, 0.0, x);
  56. ASSERT_SAME_TYPE(decltype(t2), std::tuple<int, double, int>);
  57. }
  58. { // Testing (4)
  59. using T = ExplicitTestTypes::TestType;
  60. static_assert(!std::is_convertible<T const&, T>::value, "");
  61. std::tuple t1(AT, A, T{});
  62. ASSERT_SAME_TYPE(decltype(t1), std::tuple<T>);
  63. const T v{};
  64. std::tuple t2(AT, A, T{}, 101l, v);
  65. ASSERT_SAME_TYPE(decltype(t2), std::tuple<T, long, T>);
  66. }
  67. { // Testing (5)
  68. using Tup = std::tuple<int, decltype(nullptr)>;
  69. const Tup t(42, nullptr);
  70. std::tuple t1(t);
  71. ASSERT_SAME_TYPE(decltype(t1), Tup);
  72. }
  73. { // Testing (6)
  74. using Tup = std::tuple<void*, unsigned, char>;
  75. std::tuple t1(Tup(nullptr, 42, 'a'));
  76. ASSERT_SAME_TYPE(decltype(t1), Tup);
  77. }
  78. { // Testing (7)
  79. using Tup = std::tuple<int, decltype(nullptr)>;
  80. const Tup t(42, nullptr);
  81. std::tuple t1(AT, A, t);
  82. ASSERT_SAME_TYPE(decltype(t1), Tup);
  83. }
  84. { // Testing (8)
  85. using Tup = std::tuple<void*, unsigned, char>;
  86. std::tuple t1(AT, A, Tup(nullptr, 42, 'a'));
  87. ASSERT_SAME_TYPE(decltype(t1), Tup);
  88. }
  89. }
  90. // Overloads
  91. // using A = Allocator
  92. // using AT = std::allocator_arg_t
  93. // ---------------
  94. // (1) tuple() -> tuple<>
  95. // (2) tuple(AT, A const&) -> tuple<>
  96. // (3) tuple(tuple const&) -> tuple<>
  97. // (4) tuple(tuple&&) -> tuple<>
  98. // (5) tuple(AT, A const&, tuple const&) -> tuple<>
  99. // (6) tuple(AT, A const&, tuple&&) -> tuple<>
  100. void test_empty_specialization()
  101. {
  102. std::allocator<int> A;
  103. const auto AT = std::allocator_arg;
  104. { // Testing (1)
  105. std::tuple t1{};
  106. ASSERT_SAME_TYPE(decltype(t1), std::tuple<>);
  107. }
  108. { // Testing (2)
  109. std::tuple t1{AT, A};
  110. ASSERT_SAME_TYPE(decltype(t1), std::tuple<>);
  111. }
  112. { // Testing (3)
  113. const std::tuple<> t{};
  114. std::tuple t1(t);
  115. ASSERT_SAME_TYPE(decltype(t1), std::tuple<>);
  116. }
  117. { // Testing (4)
  118. std::tuple t1(std::tuple<>{});
  119. ASSERT_SAME_TYPE(decltype(t1), std::tuple<>);
  120. }
  121. { // Testing (5)
  122. const std::tuple<> t{};
  123. std::tuple t1(AT, A, t);
  124. ASSERT_SAME_TYPE(decltype(t1), std::tuple<>);
  125. }
  126. { // Testing (6)
  127. std::tuple t1(AT, A, std::tuple<>{});
  128. ASSERT_SAME_TYPE(decltype(t1), std::tuple<>);
  129. }
  130. }
  131. int main() {
  132. test_primary_template();
  133. test_empty_specialization();
  134. }