move_pair.pass.cpp 1.1 KB

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