Home | History | Annotate | Download | only in meta.trans.ref
      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // type_traits
     13 
     14 // add_rvalue_reference
     15 // If T names a referenceable type then the member typedef type
     16 //   shall name T&&; otherwise, type shall name T.
     17 
     18 #include <type_traits>
     19 #include "test_macros.h"
     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 
     48 struct Foo {};
     49 
     50 int main()
     51 {
     52     test_add_rvalue_reference<void, void>();
     53     test_add_rvalue_reference<int, int&&>();
     54     test_add_rvalue_reference<int[3], int(&&)[3]>();
     55     test_add_rvalue_reference<int&, int&>();
     56     test_add_rvalue_reference<const int&, const int&>();
     57     test_add_rvalue_reference<int*, int*&&>();
     58     test_add_rvalue_reference<const int*, const int*&&>();
     59     test_add_rvalue_reference<Foo, Foo&&>();
     60 
     61 //  LWG 2101 specifically talks about add_rvalue_reference and functions.
     62 //  The term of art is "a referenceable type", which a cv- or ref-qualified function is not.
     63     test_function0<void()>();
     64     test_function1<void() const>();
     65     test_function1<void() &>();
     66     test_function1<void() &&>();
     67     test_function1<void() const &>();
     68     test_function1<void() const &&>();
     69 
     70 //  But a cv- or ref-qualified member function *is* "a referenceable type"
     71     test_function0<void (Foo::*)()>();
     72     test_function0<void (Foo::*)() const>();
     73     test_function0<void (Foo::*)() &>();
     74     test_function0<void (Foo::*)() &&>();
     75     test_function0<void (Foo::*)() const &>();
     76     test_function0<void (Foo::*)() const &&>();
     77 }
     78