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