Home | History | Annotate | Download | only in func.require
      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 // [func.require]
     11 
     12 // INVOKE
     13 #if __cplusplus < 201103L
     14 int main () {}      // no __invoke in C++03
     15 #else
     16 
     17 #include <type_traits>
     18 
     19 template <typename T, int N>
     20 struct Array
     21 {
     22     typedef T type[N];
     23 };
     24 
     25 struct Type
     26 {
     27     Array<char, 1>::type& f1();
     28     Array<char, 2>::type& f2() const;
     29 
     30     Array<char, 1>::type& g1()        &;
     31     Array<char, 2>::type& g2() const  &;
     32 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     33     Array<char, 3>::type& g3()       &&;
     34     Array<char, 4>::type& g4() const &&;
     35 #endif
     36 };
     37 
     38 int main()
     39 {
     40     static_assert(sizeof(std::__invoke(&Type::f1, std::declval<Type        >())) == 1, "");
     41     static_assert(sizeof(std::__invoke(&Type::f2, std::declval<Type const  >())) == 2, "");
     42 
     43     static_assert(sizeof(std::__invoke(&Type::g1, std::declval<Type       &>())) == 1, "");
     44     static_assert(sizeof(std::__invoke(&Type::g2, std::declval<Type const &>())) == 2, "");
     45 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     46     static_assert(sizeof(std::__invoke(&Type::g3, std::declval<Type      &&>())) == 3, "");
     47     static_assert(sizeof(std::__invoke(&Type::g4, std::declval<Type const&&>())) == 4, "");
     48 #endif
     49 }
     50 #endif
     51