C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Classes | Typedefs | Functions
Traits Namespace Reference

Contains traits for conveniently exploiting SFINAE. More...

Classes

struct  All
 Evaluates to Bool<true> if all specified conditions are true; otherwise evaluates to Bool<false>. More...
 
struct  All< Head, Tail... >
 Evaluates to Bool<true> if all specified conditions are true; otherwise evaluates to Bool<false>. More...
 
struct  Any
 Evaluates to Bool<true> if at least one of the specified conditions is true; otherwise evaluates to Bool<false>. More...
 
struct  Any< Head, Tail... >
 Evaluates to Bool<true> if at least one of the specified conditions is true; otherwise evaluates to Bool<false>. More...
 
struct  Bool
 Wraps a static boolean constant. More...
 
struct  IsAnyOf
 Evaluates to Bool<true> if the specified type is any of the specified types; otherwise evaluates to Bool<false>. More...
 
struct  IsAnyOf< Type, OtherType, RemainingTypes... >
 Evaluates to Bool<true> if the specified type is any of the specified types; otherwise evaluates to Bool<false>. More...
 
struct  IsComplete
 Evaluates to Bool<true> if the specified type is complete; if the type is only forward-declared it evaluates to Bool<false>. More...
 
struct  IsComplete< T, decltype(void(sizeof(T)))>
 Evaluates to Bool<true> if the specified type is complete; if the type is only forward-declared it evaluates to Bool<false>. More...
 
struct  IsCString
 Evaluates to Bool<true> if the specified type is a C-string (char * or const char *); otherwise evaluates to Bool<false>. More...
 
struct  IsNoneOf
 Evaluates to Bool<true> if the specified type is none of the specified types; otherwise evaluates to Bool<false>. More...
 
struct  IsNoneOf< Type, OtherType, RemainingTypes... >
 Evaluates to Bool<true> if the specified type is none of the specified types; otherwise evaluates to Bool<false>. More...
 
struct  IsSpecializationOf
 Evaluates to Bool<true> if the specified type is based on the specified. More...
 
struct  IsSpecializingAnyOf
 Evaluates to Bool<true> if the specified type is based on one of the specified templates; otherwise evaluates to Bool<false>. More...
 
struct  IsSpecializingAnyOf< Type, TemplateType, RemainingTemplateTypes... >
 Evaluates to Bool<true> if the specified type is based on one of the specified templates; otherwise evaluates to Bool<false>. More...
 
struct  IsString
 Evaluates to Bool<true> if the specified type is a C-string (char * or const char *); otherwise evaluates to Bool<false>. More...
 
struct  None
 Evaluates to Bool<true> if none of the specified conditions are true; otherwise evaluates to Bool<false>. More...
 
struct  None< Head, Tail... >
 Evaluates to Bool<true> if none of the specified conditions are true; otherwise evaluates to Bool<false>. More...
 

Typedefs

template<typename If , typename Then , typename Else >
using Conditional = typename std::conditional< If::value, Then, Else >::type
 Shortcut for std::conditional to omit ::value and ::type. More...
 
template<typename T >
using Not = Bool<!T::value >
 Negates the specified value. More...
 
template<typename... Condition>
using EnableIf = typename std::enable_if< All< Condition... >::value, Detail::Enabler >::type
 Shortcut for std::enable_if to omit ::value and ::type. More...
 
template<typename... Condition>
using DisableIf = typename std::enable_if<!All< Condition... >::value, Detail::Enabler >::type
 Shortcut for std::enable_if to negate the condition and omit ::value and ::type. More...
 
template<typename... Condition>
using EnableIfAny = typename std::enable_if< Any< Condition... >::value, Detail::Enabler >::type
 Shortcut for std::enable_if to apply Traits::Any and omit ::value and ::type. More...
 
template<typename... Condition>
using DisableIfAny = typename std::enable_if<!Any< Condition... >::value, Detail::Enabler >::type
 Shortcut for std::enable_if to apply Traits::Any, negate the condition and omit ::value and ::type. More...
 

Functions

 CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK (IsDereferencable, *(std::declval< T & >()))
 Evaluates to Bool<true> if the specified type can be dereferenced using the *-operator; otherwise evaluates to Bool<false>. More...
 
 CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK (HasSize, std::is_integral< decltype(std::declval< T & >().size())>::value)
 Evaluates to Bool<true> if the specified type can has a size() method; otherwise evaluates to Bool<false>. More...
 
 CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK (IsReservable, std::declval< T & >().reserve(0u))
 Evaluates to Bool<true> if the specified type can has a reserve() method; otherwise evaluates to Bool<false>. More...
 
 CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK (IsResizable, std::declval< T & >().resize(0u))
 Evaluates to Bool<true> if the specified type can has a resize() method; otherwise evaluates to Bool<false>. More...
 
 CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK (HasOperatorBool, std::declval< T & >() ? true :false)
 Evaluates to Bool<true> if the specified type has operator bool(); otherwise evaluates to Bool<false>. More...
 
 CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK (IsIteratable, std::begin(std::declval< T & >()) !=std::end(std::declval< T & >()) CPP_UTILITIES_PP_COMMA void() CPP_UTILITIES_PP_COMMA++std::declval< decltype(begin(std::declval< T & >())) & >() CPP_UTILITIES_PP_COMMA void(*begin(std::declval< T & >())))
 Evaluates to Bool<true> if the specified type is iteratable (can be used in for-each loop); otherwise evaluates to Bool<false>. More...
 
template<typename T , EnableIf< IsDereferencable< T >> * = nullptr>
constexpr auto & dereferenceMaybe (T &value)
 Dereferences the specified value if possible; otherwise just returns value itself. More...
 
template<typename T , EnableIf< IsDereferencable< T >> * = nullptr>
constexpr const auto & dereferenceMaybe (const T &value)
 Dereferences the specified value if possible; otherwise just returns value itself. More...
 

Detailed Description

Contains traits for conveniently exploiting SFINAE.

Typedef Documentation

◆ Conditional

template<typename If , typename Then , typename Else >
using Traits::Conditional = typedef typename std::conditional<If::value, Then, Else>::type

Shortcut for std::conditional to omit ::value and ::type.

Definition at line 17 of file traits.h.

◆ DisableIf

template<typename... Condition>
using Traits::DisableIf = typedef typename std::enable_if<!All<Condition...>::value, Detail::Enabler>::type

Shortcut for std::enable_if to negate the condition and omit ::value and ::type.

Definition at line 50 of file traits.h.

◆ DisableIfAny

template<typename... Condition>
using Traits::DisableIfAny = typedef typename std::enable_if<!Any<Condition...>::value, Detail::Enabler>::type

Shortcut for std::enable_if to apply Traits::Any, negate the condition and omit ::value and ::type.

Definition at line 55 of file traits.h.

◆ EnableIf

template<typename... Condition>
using Traits::EnableIf = typedef typename std::enable_if<All<Condition...>::value, Detail::Enabler>::type

Shortcut for std::enable_if to omit ::value and ::type.

Definition at line 48 of file traits.h.

◆ EnableIfAny

template<typename... Condition>
using Traits::EnableIfAny = typedef typename std::enable_if<Any<Condition...>::value, Detail::Enabler>::type

Shortcut for std::enable_if to apply Traits::Any and omit ::value and ::type.

Definition at line 53 of file traits.h.

◆ Not

template<typename T >
using Traits::Not = typedef Bool<!T::value>

Negates the specified value.

Definition at line 24 of file traits.h.

Function Documentation

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [1/6]

Traits::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK ( IsDereferencable  ,
std::declval< T & >() 
)

Evaluates to Bool<true> if the specified type can be dereferenced using the *-operator; otherwise evaluates to Bool<false>.

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [2/6]

Traits::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK ( HasSize  ,
std::is_integral< decltype(std::declval< T & >().size())>::value   
)

Evaluates to Bool<true> if the specified type can has a size() method; otherwise evaluates to Bool<false>.

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [3/6]

Traits::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK ( IsReservable  ,
std::declval< T & >  ).reserve(0u 
)

Evaluates to Bool<true> if the specified type can has a reserve() method; otherwise evaluates to Bool<false>.

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [4/6]

Traits::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK ( IsResizable  ,
std::declval< T & >  ).resize(0u 
)

Evaluates to Bool<true> if the specified type can has a resize() method; otherwise evaluates to Bool<false>.

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [5/6]

Traits::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK ( HasOperatorBool  ,
std::declval< T & >() ? true :false   
)

Evaluates to Bool<true> if the specified type has operator bool(); otherwise evaluates to Bool<false>.

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [6/6]

Traits::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK ( IsIteratable  ,
std::begin(std::declval< T & >()) !  = std::end(std::declval< T & >()) CPP_UTILITIES_PP_COMMA void() CPP_UTILITIES_PP_COMMA++std::declval< decltype(begin(std::declval< T & >())) & >() CPP_UTILITIES_PP_COMMA void(*begin(std::declval< T & >())) 
)

Evaluates to Bool<true> if the specified type is iteratable (can be used in for-each loop); otherwise evaluates to Bool<false>.

◆ dereferenceMaybe() [1/2]

template<typename T , EnableIf< IsDereferencable< T >> * = nullptr>
constexpr auto & Traits::dereferenceMaybe ( T &  value)

Dereferences the specified value if possible; otherwise just returns value itself.

Definition at line 156 of file traits.h.

◆ dereferenceMaybe() [2/2]

template<typename T , EnableIf< IsDereferencable< T >> * = nullptr>
constexpr const auto & Traits::dereferenceMaybe ( const T &  value)

Dereferences the specified value if possible; otherwise just returns value itself.

Definition at line 168 of file traits.h.