Corrade/Utility/TypeTraits.h file

Macros CORRADE_HAS_TYPE(), alias Corrade::Utility::IsIterable.

Contents

Namespaces

namespace Corrade
Root namespace.
namespace Corrade::Utility
Utitlities.

Typedefs

template<class T>
using IsIterable = std::integral_constant<bool,(Implementation::HasMemberBegin<T>::value||Implementation::HasBegin<T>::value||Implementation::HasStdBegin<T>::value)&&(Implementation::HasMemberEnd<T>::value||Implementation::HasEnd<T>::value||Implementation::HasStdEnd<T>::value)>
Traits class for checking whether given type is iterable.

Defines

#define CORRADE_HAS_TYPE(className, typeExpression)
Macro for creating traits class that checks for type expression validity.

Define documentation

#define CORRADE_HAS_TYPE(className, typeExpression)

Macro for creating traits class that checks for type expression validity.

Parameters
className Resulting class name
typeExpression Type expression to check

Defines a traits class checking whether typeExpression is valid. You can use T to reference the type which is being checked. The defined class is then implicitly convertible to bool holding the result.

Usage examples: checking for presence of const_iterator member type:

CORRADE_HAS_TYPE(HasKeyType, typename T::key_type);

static_assert(HasKeyType<std::map<int, int>>::value, "");
static_assert(!HasKeyType<std::vector<int>>::value, "");

Checking for presence of size() member function:

CORRADE_HAS_TYPE(HasSize, decltype(std::declval<T>().size()));

static_assert(HasSize<std::vector<int>>::value, "");
static_assert(!HasSize<std::tuple<int, int>>::value, "");