alloc_copy.pass.cpp 2.4 KB

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