alloc_move_pair.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, class U1, class U2>
  11. // tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <utility>
  15. #include <memory>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #include "allocators.h"
  19. #include "../alloc_first.h"
  20. #include "../alloc_last.h"
  21. struct B
  22. {
  23. int id_;
  24. explicit B(int i) : id_(i) {}
  25. virtual ~B() {}
  26. };
  27. struct D
  28. : B
  29. {
  30. explicit D(int i) : B(i) {}
  31. };
  32. int main(int, char**)
  33. {
  34. {
  35. typedef std::pair<int, std::unique_ptr<D>> T0;
  36. typedef std::tuple<alloc_first, std::unique_ptr<B>> T1;
  37. T0 t0(2, std::unique_ptr<D>(new D(3)));
  38. alloc_first::allocator_constructed = false;
  39. T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
  40. assert(alloc_first::allocator_constructed);
  41. assert(std::get<0>(t1) == 2);
  42. assert(std::get<1>(t1)->id_ == 3);
  43. }
  44. return 0;
  45. }