alloc_move.pass.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // <tuple>
  10. // template <class... Types> class tuple;
  11. // template <class Alloc>
  12. // tuple(allocator_arg_t, const Alloc& a, tuple&&);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <cassert>
  16. #include "MoveOnly.h"
  17. #include "allocators.h"
  18. #include "../alloc_first.h"
  19. #include "../alloc_last.h"
  20. int main()
  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. }