piecewise_construct.pass.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // UNSUPPORTED: c++98, c++03
  9. // <utility>
  10. // template <class T1, class T2> struct pair
  11. // struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
  12. // constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
  13. #include <utility>
  14. #include <tuple>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. class A
  18. {
  19. int i_;
  20. char c_;
  21. public:
  22. A(int i, char c) : i_(i), c_(c) {}
  23. int get_i() const {return i_;}
  24. char get_c() const {return c_;}
  25. };
  26. class B
  27. {
  28. double d_;
  29. unsigned u1_;
  30. unsigned u2_;
  31. public:
  32. B(double d, unsigned u1, unsigned u2) : d_(d), u1_(u1), u2_(u2) {}
  33. double get_d() const {return d_;}
  34. unsigned get_u1() const {return u1_;}
  35. unsigned get_u2() const {return u2_;}
  36. };
  37. int main(int, char**)
  38. {
  39. std::pair<A, B> p(std::piecewise_construct,
  40. std::make_tuple(4, 'a'),
  41. std::make_tuple(3.5, 6u, 2u));
  42. assert(p.first.get_i() == 4);
  43. assert(p.first.get_c() == 'a');
  44. assert(p.second.get_d() == 3.5);
  45. assert(p.second.get_u1() == 6u);
  46. assert(p.second.get_u2() == 2u);
  47. return 0;
  48. }