]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/meta/meta.trans/meta.trans.ref/add_rvalue_ref.pass.cpp
Vendor import of libc++ release_39 branch r276489:
[FreeBSD/FreeBSD.git] / test / std / utilities / meta / meta.trans / meta.trans.ref / add_rvalue_ref.pass.cpp
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 // type_traits
11
12 // add_rvalue_reference
13 // If T names a referenceable type then the member typedef type
14 //   shall name T&&; otherwise, type shall name T.
15
16 #include <type_traits>
17 #include "test_macros.h"
18
19 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
20
21 template <class T, class U>
22 void test_add_rvalue_reference()
23 {
24     static_assert((std::is_same<typename std::add_rvalue_reference<T>::type, U>::value), "");
25 #if TEST_STD_VER > 11
26     static_assert((std::is_same<std::add_rvalue_reference_t<T>, U>::value), "");
27 #endif
28 }
29
30 template <class F>
31 void test_function0()
32 {
33     static_assert((std::is_same<typename std::add_rvalue_reference<F>::type, F&&>::value), "");
34 #if TEST_STD_VER > 11
35     static_assert((std::is_same<std::add_rvalue_reference_t<F>, F&&>::value), "");
36 #endif
37 }
38
39 template <class F>
40 void test_function1()
41 {
42     static_assert((std::is_same<typename std::add_rvalue_reference<F>::type, F>::value), "");
43 #if TEST_STD_VER > 11
44     static_assert((std::is_same<std::add_rvalue_reference_t<F>, F>::value), "");
45 #endif
46 }
47 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
48
49 struct Foo {};
50
51 int main()
52 {
53 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
54     test_add_rvalue_reference<void, void>();
55     test_add_rvalue_reference<int, int&&>();
56     test_add_rvalue_reference<int[3], int(&&)[3]>();
57     test_add_rvalue_reference<int&, int&>();
58     test_add_rvalue_reference<const int&, const int&>();
59     test_add_rvalue_reference<int*, int*&&>();
60     test_add_rvalue_reference<const int*, const int*&&>();
61     test_add_rvalue_reference<Foo, Foo&&>();
62
63 //  LWG 2101 specifically talks about add_rvalue_reference and functions.
64 //  The term of art is "a referenceable type", which a cv- or ref-qualified function is not.
65     test_function0<void()>();
66 #if TEST_STD_VER >= 11
67     test_function1<void() const>();
68     test_function1<void() &>();
69     test_function1<void() &&>();
70     test_function1<void() const &>();
71     test_function1<void() const &&>();
72 #endif
73
74 //  But a cv- or ref-qualified member function *is* "a referenceable type"
75     test_function0<void (Foo::*)()>();
76 #if TEST_STD_VER >= 11
77     test_function0<void (Foo::*)() const>();
78     test_function0<void (Foo::*)() &>();
79     test_function0<void (Foo::*)() &&>();
80     test_function0<void (Foo::*)() const &>();
81     test_function0<void (Foo::*)() const &&>();
82 #endif
83 #endif
84 }