piecewise_construct.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // <utility>
  10. // template <class T1, class T2> struct pair
  11. // struct piecewise_construct_t { };
  12. // constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
  13. #include <utility>
  14. #include <tuple>
  15. #include <cassert>
  16. class A
  17. {
  18. int i_;
  19. char c_;
  20. public:
  21. A(int i, char c) : i_(i), c_(c) {}
  22. int get_i() const {return i_;}
  23. char get_c() const {return c_;}
  24. };
  25. class B
  26. {
  27. double d_;
  28. unsigned u1_;
  29. unsigned u2_;
  30. public:
  31. B(double d, unsigned u1, unsigned u2) : d_(d), u1_(u1), u2_(u2) {}
  32. double get_d() const {return d_;}
  33. unsigned get_u1() const {return u1_;}
  34. unsigned get_u2() const {return u2_;}
  35. };
  36. int main()
  37. {
  38. #ifndef _LIBCPP_HAS_NO_VARIADICS
  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. #endif
  48. }