is_aggregate.pass.cpp (2286B)
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, c++11, c++14 11 12 // <type_traits> 13 14 // template <class T> struct is_aggregate; 15 // template <class T> constexpr bool is_aggregate_v = is_aggregate<T>::value; 16 17 #include <type_traits> 18 #include "test_macros.h" 19 20 template <class T> 21 void test_true() 22 { 23 #if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) 24 static_assert( std::is_aggregate<T>::value, ""); 25 static_assert( std::is_aggregate<const T>::value, ""); 26 static_assert( std::is_aggregate<volatile T>::value, ""); 27 static_assert( std::is_aggregate<const volatile T>::value, ""); 28 static_assert( std::is_aggregate_v<T>, ""); 29 static_assert( std::is_aggregate_v<const T>, ""); 30 static_assert( std::is_aggregate_v<volatile T>, ""); 31 static_assert( std::is_aggregate_v<const volatile T>, ""); 32 #endif 33 } 34 35 template <class T> 36 void test_false() 37 { 38 #if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) 39 static_assert(!std::is_aggregate<T>::value, ""); 40 static_assert(!std::is_aggregate<const T>::value, ""); 41 static_assert(!std::is_aggregate<volatile T>::value, ""); 42 static_assert(!std::is_aggregate<const volatile T>::value, ""); 43 static_assert(!std::is_aggregate_v<T>, ""); 44 static_assert(!std::is_aggregate_v<const T>, ""); 45 static_assert(!std::is_aggregate_v<volatile T>, ""); 46 static_assert(!std::is_aggregate_v<const volatile T>, ""); 47 #endif 48 } 49 50 struct Aggregate {}; 51 struct HasCons { HasCons(int); }; 52 struct HasPriv { 53 void PreventUnusedPrivateMemberWarning(); 54 private: 55 int x; 56 }; 57 struct Union { int x; void* y; }; 58 59 60 int main () 61 { 62 { 63 test_false<void>(); 64 test_false<int>(); 65 test_false<void*>(); 66 test_false<void()>(); 67 test_false<void() const>(); 68 test_false<void(Aggregate::*)(int) const>(); 69 test_false<Aggregate&>(); 70 test_false<HasCons>(); 71 test_false<HasPriv>(); 72 } 73 { 74 test_true<Aggregate>(); 75 test_true<Aggregate[]>(); 76 test_true<Aggregate[42][101]>(); 77 test_true<Union>(); 78 } 79 }