Home | History | Annotate | Download | only in meta.unary.cat
      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 // is_function
     13 
     14 #include <type_traits>
     15 #include <cstddef>        // for std::nullptr_t
     16 
     17 #include "test_macros.h"
     18 
     19 template <class T>
     20 void test_is_function()
     21 {
     22     static_assert( std::is_function<T>::value, "");
     23     static_assert( std::is_function<const T>::value, "");
     24     static_assert( std::is_function<volatile T>::value, "");
     25     static_assert( std::is_function<const volatile T>::value, "");
     26 #if TEST_STD_VER > 14
     27     static_assert( std::is_function_v<T>, "");
     28     static_assert( std::is_function_v<const T>, "");
     29     static_assert( std::is_function_v<volatile T>, "");
     30     static_assert( std::is_function_v<const volatile T>, "");
     31 #endif
     32 }
     33 
     34 template <class T>
     35 void test_is_not_function()
     36 {
     37     static_assert(!std::is_function<T>::value, "");
     38     static_assert(!std::is_function<const T>::value, "");
     39     static_assert(!std::is_function<volatile T>::value, "");
     40     static_assert(!std::is_function<const volatile T>::value, "");
     41 #if TEST_STD_VER > 14
     42     static_assert(!std::is_function_v<T>, "");
     43     static_assert(!std::is_function_v<const T>, "");
     44     static_assert(!std::is_function_v<volatile T>, "");
     45     static_assert(!std::is_function_v<const volatile T>, "");
     46 #endif
     47 }
     48 
     49 class Empty
     50 {
     51 };
     52 
     53 class NotEmpty
     54 {
     55     virtual ~NotEmpty();
     56 };
     57 
     58 union Union {};
     59 
     60 struct bit_zero
     61 {
     62     int :  0;
     63 };
     64 
     65 class Abstract
     66 {
     67     virtual ~Abstract() = 0;
     68 };
     69 
     70 enum Enum {zero, one};
     71 struct incomplete_type;
     72 
     73 typedef void (*FunctionPtr)();
     74 
     75 int main()
     76 {
     77 	test_is_function<void(void)>();
     78 	test_is_function<int(int)>();
     79 	test_is_function<int(int, double)>();
     80 	test_is_function<int(Abstract *)>();
     81 	test_is_function<void(...)>();
     82 
     83   test_is_not_function<std::nullptr_t>();
     84   test_is_not_function<void>();
     85   test_is_not_function<int>();
     86   test_is_not_function<int&>();
     87   test_is_not_function<int&&>();
     88   test_is_not_function<int*>();
     89   test_is_not_function<double>();
     90   test_is_not_function<char[3]>();
     91   test_is_not_function<char[]>();
     92   test_is_not_function<Union>();
     93   test_is_not_function<Enum>();
     94   test_is_not_function<FunctionPtr>(); // function pointer is not a function
     95   test_is_not_function<Empty>();
     96   test_is_not_function<bit_zero>();
     97   test_is_not_function<NotEmpty>();
     98   test_is_not_function<Abstract>();
     99   test_is_not_function<Abstract*>();
    100   test_is_not_function<incomplete_type>();
    101 
    102 #if TEST_STD_VER >= 11
    103   test_is_function<void() noexcept>();
    104   test_is_function<void() const && noexcept>();
    105 #endif
    106 }
    107