xref: /llvm-project/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp (revision 06e2b737aa0347b42e8bf37cb00a053eab0a9393)
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 
9 // UNSUPPORTED: c++03
10 
11 // <utility>
12 
13 // template <class T1, class T2> struct pair
14 
15 // struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
16 // constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
17 
18 #include <utility>
19 #include <tuple>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
24 class A
25 {
26     int i_;
27     char c_;
28 public:
A(int i,char c)29     constexpr A(int i, char c) : i_(i), c_(c) {}
get_i() const30     constexpr int get_i() const {return i_;}
get_c() const31     constexpr char get_c() const {return c_;}
32 };
33 
34 class B
35 {
36     double d_;
37     unsigned u1_;
38     unsigned u2_;
39 public:
B(double d,unsigned u1,unsigned u2)40     constexpr explicit B(double d, unsigned u1, unsigned u2) : d_(d), u1_(u1), u2_(u2) {}
get_d() const41     constexpr double get_d() const {return d_;}
get_u1() const42     constexpr unsigned get_u1() const {return u1_;}
get_u2() const43     constexpr unsigned get_u2() const {return u2_;}
44 };
45 
46 TEST_CONSTEXPR_CXX20
test()47 bool test()
48 {
49     std::pair<A, B> p(std::piecewise_construct,
50                       std::make_tuple(4, 'a'),
51                       std::make_tuple(3.5, 6u, 2u));
52     assert(p.first.get_i() == 4);
53     assert(p.first.get_c() == 'a');
54     assert(p.second.get_d() == 3.5);
55     assert(p.second.get_u1() == 6u);
56     assert(p.second.get_u2() == 2u);
57 
58     return true;
59 }
60 
main(int,char **)61 int main(int, char**)
62 {
63     test();
64 #if TEST_STD_VER >= 20
65     static_assert(test());
66 #endif
67 
68     return 0;
69 }
70