Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

is_empty
PrevUpHomeNext
template <class T>
struct is_empty : public true_type-or-false_type {};

Inherits: If T is an empty class type (and not a union type) then inherits from true_type, otherwise inherits from false_type.

C++ Standard Reference: 10p5.

Header: #include <boost/type_traits/is_empty.hpp> or #include <boost/type_traits.hpp>

Compiler Compatibility: In order to correctly detect empty classes this trait relies on either:

  • the compiler implementing zero sized empty base classes, or
  • the compiler providing intrinsics to detect empty classes - this latter case can be tested for by checking to see if the macro BOOST_IS_EMPTY is defined.

Can not be used with incomplete types.

Examples:

Given: struct empty_class {};

is_empty<empty_class> inherits from true_type.

is_empty<empty_class const>::type is the type true_type.

is_empty<empty_class>::value is an integral constant expression that evaluates to true.

is_empty<T>::value_type is the type bool.


PrevUpHomeNext