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: |
29 | constexpr A(int i, char c) : i_(i), c_(c) {} |
30 | constexpr int get_i() const {return i_;} |
31 | constexpr char get_c() const {return c_;} |
32 | }; |
33 | |
34 | class B |
35 | { |
36 | double d_; |
37 | unsigned u1_; |
38 | unsigned u2_; |
39 | public: |
40 | constexpr explicit B(double d, unsigned u1, unsigned u2) : d_(d), u1_(u1), u2_(u2) {} |
41 | constexpr double get_d() const {return d_;} |
42 | constexpr unsigned get_u1() const {return u1_;} |
43 | constexpr unsigned get_u2() const {return u2_;} |
44 | }; |
45 | |
46 | TEST_CONSTEXPR_CXX20 |
47 | bool test() |
48 | { |
49 | std::pair<A, B> p(std::piecewise_construct, |
50 | std::make_tuple(args: 4, args: 'a'), |
51 | std::make_tuple(args: 3.5, args: 6u, args: 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 | |
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 | |