SPH
Classes | Typedefs | Functions | Variables
Traits.h File Reference

Few non-standard type traits. More...

#include "common/Globals.h"
#include <memory>
#include <type_traits>

Go to the source code of this file.

Classes

struct  TypeSelector< n, T0, TArgs... >
 
struct  TypeSelector< 0, T0, TArgs... >
 
struct  TypeIndex< T0, n, T1, TArgs >
 Returns the index of type T0 in type list. If the type is not in the list, returns -1. More...
 
struct  TypeIndex< T0, n, T1 >
 
struct  MakeVoid< Ts >
 
struct  FunctionSignature< TSignature >
 Function traits. More...
 
struct  FunctionTraits< TFunction >
 
struct  FunctionTraits< TReturn(TClass::*)(TArgs...) const >
 
struct  FunctionTraits< TReturn(TClass::*)(TArgs...)>
 
struct  FunctionTraits< TReturn(*)(TArgs...)>
 
struct  IsCallableImpl< TCallable, TEnabler, TArgs >
 
struct  IsCallableImpl< TCallable, VoidType< decltype(std::declval< TCallable >()(std::declval< TArgs >()...))>, TArgs... >
 
struct  IsCallable< TCallable, TArgs >
 
struct  HasStreamOperator< T, TStream, typename >
 
struct  HasStreamOperator< T, TStream, VoidType< decltype(std::declval< TStream & >()<< std::declval< T >())> >
 
class  ReferenceWrapper< T >
 Helper class for storing l-value references. Has a default constructor for convenient usage in containers. More...
 
struct  WrapReferenceType< T >
 Type trait wrapping references. Other types keeps unchanged. More...
 
struct  WrapReferenceType< T & >
 
struct  UnwrapReferenceType< T >
 Type trait for "extracting" stored references from reference_wrappers. Other types keeps unchanged. More...
 
struct  UnwrapReferenceType< ReferenceWrapper< T > >
 
struct  UndecayType< T, TOther >
 Adds const or reference to the type, based on const-ness and reference-ness of given type. More...
 
struct  UndecayType< T, const TOther >
 
struct  UndecayType< T, TOther & >
 
struct  UndecayType< T, const TOther & >
 
struct  ConvertToSizeType< T, TEnabler >
 Converts all signed integral types and enums into Size, does not change other types. More...
 
struct  ConvertToSizeType< T, std::enable_if_t< std::is_enum< std::decay_t< T > >::value > >
 
struct  IsEnumClass< T >
 
struct  AllTrue< First, Second, Others... >
 
struct  AllTrue< Value >
 
struct  AnyTrue< First, Second, Others... >
 
struct  AnyTrue< Value >
 

Typedefs

template<int n, typename... TArgs>
using SelectType = typename TypeSelector< n, TArgs... >::Type
 
template<typename... Ts>
using VoidType = typename MakeVoid< Ts... >::Type
 
template<typename TFunction >
using ReturnType = typename FunctionTraits< TFunction >::TReturnType
 
template<typename T >
using WrapReference = typename WrapReferenceType< T >::Type
 
template<typename T , typename TOther >
using Undecay = typename UndecayType< T, TOther >::Type
 
template<typename T >
using ConvertToSize = typename ConvertToSizeType< T >::Type
 

Functions

template<typename T >
INLINE const T & asConst (T &ref)
 Converts a non-const reference to const one. More...
 
template<typename T >
INLINE const T & asConst (const T &&ref)=delete
 

Variables

template<typename T0 , typename... TArgs>
constexpr int getTypeIndex = TypeIndex<T0, 0, TArgs...>::value
 

Detailed Description

Few non-standard type traits.

Author
Pavel Sevecek (sevecek at sirrah.troja.mff.cuni.cz)
Date
2016-2021

Definition in file Traits.h.

Typedef Documentation

◆ ConvertToSize

template<typename T >
using ConvertToSize = typename ConvertToSizeType<T>::Type

Definition at line 197 of file Traits.h.

◆ ReturnType

template<typename TFunction >
using ReturnType = typename FunctionTraits<TFunction>::TReturnType

Definition at line 82 of file Traits.h.

◆ SelectType

template<int n, typename... TArgs>
using SelectType = typename TypeSelector<n, TArgs...>::Type

Definition at line 27 of file Traits.h.

◆ Undecay

template<typename T , typename TOther >
using Undecay = typename UndecayType<T, TOther>::Type

Definition at line 185 of file Traits.h.

◆ VoidType

template<typename... Ts>
using VoidType = typename MakeVoid<Ts...>::Type

Definition at line 49 of file Traits.h.

◆ WrapReference

template<typename T >
using WrapReference = typename WrapReferenceType<T>::Type

Definition at line 153 of file Traits.h.

Function Documentation

◆ asConst() [1/2]

template<typename T >
INLINE const T& asConst ( const T &&  ref)
delete

◆ asConst() [2/2]

template<typename T >
INLINE const T& asConst ( T &  ref)

Converts a non-const reference to const one.

Similar to std::as_const in C++17. Useful for unit testing to explicitly call a const overload of a function, or for some hacky tricks with const_cast.

Definition at line 237 of file Traits.h.

Variable Documentation

◆ getTypeIndex

template<typename T0 , typename... TArgs>
constexpr int getTypeIndex = TypeIndex<T0, 0, TArgs...>::value
constexpr

Definition at line 41 of file Traits.h.