C++ Utilities 5.24.7
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
CppUtilities::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 template; otherwise evaluates to Bool<false>. 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 standard string, standard string view or 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.
 
template<typename T >
using Not = Bool<!T::value>
 Negates the specified value.
 
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.
 
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.
 
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.
 
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.
 

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>.
 
 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 (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 (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 (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 (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>.
 
template<typename T , EnableIf< IsDereferencable< T > > * = nullptr>
constexpr autodereferenceMaybe (T &&value)
 Dereferences the specified value if possible; otherwise just returns value itself.
 

Detailed Description

Contains traits for conveniently exploiting SFINAE.

Typedef Documentation

◆ Conditional

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

Definition at line 20 of file traits.h.

◆ DisableIf

template<typename... Condition>
using CppUtilities::Traits::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.

Definition at line 46 of file traits.h.

◆ DisableIfAny

template<typename... Condition>
using CppUtilities::Traits::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.

Definition at line 51 of file traits.h.

◆ EnableIf

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

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

Definition at line 44 of file traits.h.

◆ EnableIfAny

template<typename... Condition>
using CppUtilities::Traits::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.

Definition at line 49 of file traits.h.

◆ Not

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

Negates the specified value.

Definition at line 26 of file traits.h.

Function Documentation

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [1/6]

CppUtilities::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() [2/6]

CppUtilities::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]

CppUtilities::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() [4/6]

CppUtilities::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>.

◆ CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK() [5/6]

CppUtilities::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() [6/6]

CppUtilities::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>.

◆ dereferenceMaybe()

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

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

Definition at line 143 of file traits.h.