xref: /llvm-project/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp (revision 7abade37699ebd471baca54715e6e3511533ef5f)
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 // <utility>
11 
12 // template <class T1, class T2> struct pair
13 
14 // template<size_t I, class T1, class T2>
15 //     const typename tuple_element<I, std::pair<T1, T2> >::type&&
16 //     get(const pair<T1, T2>&&);
17 
18 // UNSUPPORTED: c++98, c++03
19 
20 #include <utility>
21 #include <memory>
22 #include <type_traits>
23 #include <cassert>
24 
25 #include "test_macros.h"
26 
27 int main()
28 {
29     {
30     typedef std::pair<std::unique_ptr<int>, short> P;
31     const P p(std::unique_ptr<int>(new int(3)), static_cast<short>(4));
32     static_assert(std::is_same<const std::unique_ptr<int>&&, decltype(std::get<0>(std::move(p)))>::value, "");
33     static_assert(noexcept(std::get<0>(std::move(p))), "");
34     const std::unique_ptr<int>&& ptr = std::get<0>(std::move(p));
35     assert(*ptr == 3);
36     }
37 
38     {
39     int x = 42;
40     int const y = 43;
41     std::pair<int&, int const&> const p(x, y);
42     static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "");
43     static_assert(noexcept(std::get<0>(std::move(p))), "");
44     static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");
45     static_assert(noexcept(std::get<1>(std::move(p))), "");
46     }
47 
48     {
49     int x = 42;
50     int const y = 43;
51     std::pair<int&&, int const&&> const p(std::move(x), std::move(y));
52     static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, "");
53     static_assert(noexcept(std::get<0>(std::move(p))), "");
54     static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, "");
55     static_assert(noexcept(std::get<1>(std::move(p))), "");
56     }
57 
58 #if TEST_STD_VER > 11
59     {
60     typedef std::pair<int, short> P;
61     constexpr const P p1(3, static_cast<short>(4));
62     static_assert(std::get<0>(std::move(p1)) == 3, "");
63     static_assert(std::get<1>(std::move(p1)) == 4, "");
64     }
65 #endif
66 }
67