libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

is_empty.pass.cpp (2742B)


      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_empty
     13 
     14 // T is a non-union class type with:
     15 //  no non-static data members,
     16 //  no unnamed bit-fields of non-zero length,
     17 //  no virtual member functions,
     18 //  no virtual base classes,
     19 //  and no base class B for which is_empty_v<B> is false.
     20 
     21 
     22 #include <type_traits>
     23 #include "test_macros.h"
     24 
     25 template <class T>
     26 void test_is_empty()
     27 {
     28     static_assert( std::is_empty<T>::value, "");
     29     static_assert( std::is_empty<const T>::value, "");
     30     static_assert( std::is_empty<volatile T>::value, "");
     31     static_assert( std::is_empty<const volatile T>::value, "");
     32 #if TEST_STD_VER > 14
     33     static_assert( std::is_empty_v<T>, "");
     34     static_assert( std::is_empty_v<const T>, "");
     35     static_assert( std::is_empty_v<volatile T>, "");
     36     static_assert( std::is_empty_v<const volatile T>, "");
     37 #endif
     38 }
     39 
     40 template <class T>
     41 void test_is_not_empty()
     42 {
     43     static_assert(!std::is_empty<T>::value, "");
     44     static_assert(!std::is_empty<const T>::value, "");
     45     static_assert(!std::is_empty<volatile T>::value, "");
     46     static_assert(!std::is_empty<const volatile T>::value, "");
     47 #if TEST_STD_VER > 14
     48     static_assert(!std::is_empty_v<T>, "");
     49     static_assert(!std::is_empty_v<const T>, "");
     50     static_assert(!std::is_empty_v<volatile T>, "");
     51     static_assert(!std::is_empty_v<const volatile T>, "");
     52 #endif
     53 }
     54 
     55 class Empty {};
     56 struct NotEmpty { int foo; };
     57 
     58 class VirtualFn
     59 {
     60     virtual ~VirtualFn();
     61 };
     62 
     63 union Union {};
     64 
     65 struct EmptyBase    : public Empty {};
     66 struct VirtualBase  : virtual Empty {};
     67 struct NotEmptyBase : public NotEmpty {};
     68 
     69 struct StaticMember    { static int foo; };
     70 struct NonStaticMember {        int foo; };
     71 
     72 struct bit_zero
     73 {
     74     int :  0;
     75 };
     76 
     77 struct bit_one
     78 {
     79     int :  1;
     80 };
     81 
     82 int main()
     83 {
     84     test_is_not_empty<void>();
     85     test_is_not_empty<int&>();
     86     test_is_not_empty<int>();
     87     test_is_not_empty<double>();
     88     test_is_not_empty<int*>();
     89     test_is_not_empty<const int*>();
     90     test_is_not_empty<char[3]>();
     91     test_is_not_empty<char[]>();
     92     test_is_not_empty<Union>();
     93     test_is_not_empty<NotEmpty>();
     94     test_is_not_empty<VirtualFn>();
     95     test_is_not_empty<VirtualBase>();
     96     test_is_not_empty<NotEmptyBase>();
     97     test_is_not_empty<NonStaticMember>();
     98 //    test_is_not_empty<bit_one>();
     99 
    100     test_is_empty<Empty>();
    101     test_is_empty<EmptyBase>();
    102     test_is_empty<StaticMember>();
    103     test_is_empty<bit_zero>();
    104 }