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. // UNSUPPORTED: c++98, c++03
  10. // <utility>
  11. // template <class T1, class T2> struct pair
  12. // struct piecewise_construct_t { };
  13. // constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
  14. #include <utility>
  15. #include <tuple>
  16. #include <cassert>
  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()
  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. }