alloc_move.pass.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // <tuple>
  9. // template <class... Types> class tuple;
  10. // template <class Alloc>
  11. // tuple(allocator_arg_t, const Alloc& a, tuple&&);
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "MoveOnly.h"
  17. #include "allocators.h"
  18. #include "../alloc_first.h"
  19. #include "../alloc_last.h"
  20. int main(int, char**)
  21. {
  22. {
  23. typedef std::tuple<> T;
  24. T t0;
  25. T t(std::allocator_arg, A1<int>(), std::move(t0));
  26. }
  27. {
  28. typedef std::tuple<MoveOnly> T;
  29. T t0(MoveOnly(0));
  30. T t(std::allocator_arg, A1<int>(), std::move(t0));
  31. assert(std::get<0>(t) == 0);
  32. }
  33. {
  34. typedef std::tuple<alloc_first> T;
  35. T t0(1);
  36. alloc_first::allocator_constructed = false;
  37. T t(std::allocator_arg, A1<int>(5), std::move(t0));
  38. assert(alloc_first::allocator_constructed);
  39. assert(std::get<0>(t) == 1);
  40. }
  41. {
  42. typedef std::tuple<alloc_last> T;
  43. T t0(1);
  44. alloc_last::allocator_constructed = false;
  45. T t(std::allocator_arg, A1<int>(5), std::move(t0));
  46. assert(alloc_last::allocator_constructed);
  47. assert(std::get<0>(t) == 1);
  48. }
  49. // testing extensions
  50. #ifdef _LIBCPP_VERSION
  51. {
  52. typedef std::tuple<MoveOnly, alloc_first> T;
  53. T t0(0 ,1);
  54. alloc_first::allocator_constructed = false;
  55. T t(std::allocator_arg, A1<int>(5), std::move(t0));
  56. assert(alloc_first::allocator_constructed);
  57. assert(std::get<0>(t) == 0);
  58. assert(std::get<1>(t) == 1);
  59. }
  60. {
  61. typedef std::tuple<MoveOnly, alloc_first, alloc_last> T;
  62. T t0(1, 2, 3);
  63. alloc_first::allocator_constructed = false;
  64. alloc_last::allocator_constructed = false;
  65. T t(std::allocator_arg, A1<int>(5), std::move(t0));
  66. assert(alloc_first::allocator_constructed);
  67. assert(alloc_last::allocator_constructed);
  68. assert(std::get<0>(t) == 1);
  69. assert(std::get<1>(t) == 2);
  70. assert(std::get<2>(t) == 3);
  71. }
  72. #endif
  73. return 0;
  74. }