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