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// <functional>
10
11// reference_wrapper
12
13// template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T> t);
14// LWG 3146 "Excessive unwrapping in std::ref/cref"
15
16#include <functional>
17#include <cassert>
18
19#include "test_macros.h"
20
21TEST_CONSTEXPR_CXX20 bool test()
22{
23 {
24 int i = 0;
25 std::reference_wrapper<int> ri(i);
26 std::reference_wrapper<std::reference_wrapper<int> > rri(ri);
27 auto rrj = std::ref(rri);
28 ASSERT_SAME_TYPE(decltype(rrj), std::reference_wrapper<std::reference_wrapper<int> >);
29 assert(&rrj.get() == &ri);
30 }
31 {
32 int i = 0;
33 std::reference_wrapper<int> ri(i);
34 std::reference_wrapper<const std::reference_wrapper<int> > rri(ri);
35 auto rrj = std::ref(rri);
36 ASSERT_SAME_TYPE(decltype(rrj), std::reference_wrapper<const std::reference_wrapper<int> >);
37 assert(&rrj.get() == &ri);
38 }
39 {
40 int i = 0;
41 std::reference_wrapper<int> ri(i);
42 std::reference_wrapper<std::reference_wrapper<int> > rri(ri);
43 auto rrj = std::cref(rri);
44 ASSERT_SAME_TYPE(decltype(rrj), std::reference_wrapper<const std::reference_wrapper<int> >);
45 assert(&rrj.get() == &ri);
46 }
47 {
48 int i = 0;
49 std::reference_wrapper<int> ri(i);
50 std::reference_wrapper<const std::reference_wrapper<int> > rri(ri);
51 auto rrj = std::cref(rri);
52 ASSERT_SAME_TYPE(decltype(rrj), std::reference_wrapper<const std::reference_wrapper<int> >);
53 assert(&rrj.get() == &ri);
54 }
55 return true;
56}
57
58int main(int, char**)
59{
60 test();
61#if TEST_STD_VER > 17
62 static_assert(test());
63#endif
64
65 return 0;
66}
67

source code of libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/lwg3146.pass.cpp