brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 850af8b Raw
106 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// type_traits10 11// is_empty12 13// T is a non-union class type with:14//  no non-static data members,15//  no unnamed bit-fields of non-zero length,16//  no virtual member functions,17//  no virtual base classes,18//  and no base class B for which is_empty_v<B> is false.19 20 21#include <type_traits>22#include "test_macros.h"23 24template <class T>25void test_is_empty()26{27    static_assert( std::is_empty<T>::value, "");28    static_assert( std::is_empty<const T>::value, "");29    static_assert( std::is_empty<volatile T>::value, "");30    static_assert( std::is_empty<const volatile T>::value, "");31#if TEST_STD_VER > 1432    static_assert( std::is_empty_v<T>, "");33    static_assert( std::is_empty_v<const T>, "");34    static_assert( std::is_empty_v<volatile T>, "");35    static_assert( std::is_empty_v<const volatile T>, "");36#endif37}38 39template <class T>40void test_is_not_empty()41{42    static_assert(!std::is_empty<T>::value, "");43    static_assert(!std::is_empty<const T>::value, "");44    static_assert(!std::is_empty<volatile T>::value, "");45    static_assert(!std::is_empty<const volatile T>::value, "");46#if TEST_STD_VER > 1447    static_assert(!std::is_empty_v<T>, "");48    static_assert(!std::is_empty_v<const T>, "");49    static_assert(!std::is_empty_v<volatile T>, "");50    static_assert(!std::is_empty_v<const volatile T>, "");51#endif52}53 54class Empty {};55struct NotEmpty { int foo; };56 57class VirtualFn58{59    virtual ~VirtualFn();60};61 62union Union {};63 64struct EmptyBase    : public Empty {};65struct VirtualBase  : virtual Empty {};66struct NotEmptyBase : public NotEmpty {};67 68struct StaticMember    { static int foo; };69struct NonStaticMember {        int foo; };70 71struct bit_zero72{73    int :  0;74};75 76struct bit_one77{78    int :  1;79};80 81int main(int, char**)82{83    test_is_not_empty<void>();84    test_is_not_empty<int&>();85    test_is_not_empty<int>();86    test_is_not_empty<double>();87    test_is_not_empty<int*>();88    test_is_not_empty<const int*>();89    test_is_not_empty<char[3]>();90    test_is_not_empty<char[]>();91    test_is_not_empty<Union>();92    test_is_not_empty<NotEmpty>();93    test_is_not_empty<VirtualFn>();94    test_is_not_empty<VirtualBase>();95    test_is_not_empty<NotEmptyBase>();96    test_is_not_empty<NonStaticMember>();97//    test_is_not_empty<bit_one>();98 99    test_is_empty<Empty>();100    test_is_empty<EmptyBase>();101    test_is_empty<StaticMember>();102    test_is_empty<bit_zero>();103 104  return 0;105}106