| 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, c++11, c++14 |
| 10 | |
| 11 | // <utility> |
| 12 | |
| 13 | // Test that the constructors offered by std::pair are formulated |
| 14 | // so they're compatible with implicit deduction guides, or if that's not |
| 15 | // possible that they provide explicit guides to make it work. |
| 16 | |
| 17 | #include <utility> |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 | #include <cassert> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | #include "archetypes.h" |
| 24 | |
| 25 | |
| 26 | // Overloads |
| 27 | // --------------- |
| 28 | // (1) pair(const T1&, const T2&) -> pair<T1, T2> |
| 29 | // (2) explicit pair(const T1&, const T2&) -> pair<T1, T2> |
| 30 | // (3) pair(pair const& t) -> decltype(t) |
| 31 | // (4) pair(pair&& t) -> decltype(t) |
| 32 | // (5) pair(pair<U1, U2> const&) -> pair<U1, U2> |
| 33 | // (6) explicit pair(pair<U1, U2> const&) -> pair<U1, U2> |
| 34 | // (7) pair(pair<U1, U2> &&) -> pair<U1, U2> |
| 35 | // (8) explicit pair(pair<U1, U2> &&) -> pair<U1, U2> |
| 36 | int main(int, char**) |
| 37 | { |
| 38 | using E = ExplicitTestTypes::TestType; |
| 39 | static_assert(!std::is_convertible<E const&, E>::value, "" ); |
| 40 | { // Testing (1) |
| 41 | int const x = 42; |
| 42 | std::pair t1("abc" , x); |
| 43 | ASSERT_SAME_TYPE(decltype(t1), std::pair<const char*, int>); |
| 44 | } |
| 45 | { // Testing (2) |
| 46 | std::pair p1(E{}, 42); |
| 47 | ASSERT_SAME_TYPE(decltype(p1), std::pair<E, int>); |
| 48 | |
| 49 | const E t{}; |
| 50 | std::pair p2(t, E{}); |
| 51 | ASSERT_SAME_TYPE(decltype(p2), std::pair<E, E>); |
| 52 | } |
| 53 | { // Testing (3, 5) |
| 54 | std::pair<double, decltype(nullptr)> const p(0.0, nullptr); |
| 55 | std::pair p1(p); |
| 56 | ASSERT_SAME_TYPE(decltype(p1), std::pair<double, decltype(nullptr)>); |
| 57 | } |
| 58 | { // Testing (3, 6) |
| 59 | std::pair<E, decltype(nullptr)> const p(E{}, nullptr); |
| 60 | std::pair p1(p); |
| 61 | ASSERT_SAME_TYPE(decltype(p1), std::pair<E, decltype(nullptr)>); |
| 62 | } |
| 63 | { // Testing (4, 7) |
| 64 | std::pair<std::string, void*> p("abc" , nullptr); |
| 65 | std::pair p1(std::move(p)); |
| 66 | ASSERT_SAME_TYPE(decltype(p1), std::pair<std::string, void*>); |
| 67 | } |
| 68 | { // Testing (4, 8) |
| 69 | std::pair<std::string, E> p("abc" , E{}); |
| 70 | std::pair p1(std::move(p)); |
| 71 | ASSERT_SAME_TYPE(decltype(p1), std::pair<std::string, E>); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |