LvArray
Classes | Namespaces | Macros | Typedefs | Functions | Variables
typeManipulation.hpp File Reference

Contains templates useful for type manipulation. More...

#include "LvArrayConfig.hpp"
#include "Macros.hpp"
#include <camp/camp.hpp>
#include <initializer_list>
#include <utility>
#include <type_traits>
Include dependency graph for typeManipulation.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LvArray::typeManipulation::internal::GetViewType< T, bool >
 A helper struct used to get the view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetViewType< T, true >
 A helper struct used to get the view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetViewTypeConstSizes< T, bool >
 A helper struct used to get the un-resizable view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetViewTypeConstSizes< T, true >
 A helper struct used to get the un-resizable view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetViewTypeConst< T, bool >
 A helper struct used to get the const view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetViewTypeConst< T, true >
 A helper struct used to get the const view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetNestedViewType< T, bool >
 A helper struct used to get the nested view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetNestedViewType< T, true >
 A helper struct used to get the nested view type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetNestedViewTypeConst< T, bool >
 A helper struct used to get the nested view const type of an object. More...
 
struct  LvArray::typeManipulation::internal::GetNestedViewTypeConst< T, true >
 A helper struct used to get the nested view const type of an object. More...
 
struct  LvArray::typeManipulation::CArray< T, N >
 A wrapper around a compile time c array. More...
 

Namespaces

 LvArray
 The top level namespace.
 
 LvArray::typeManipulation
 Contains templates for manipulating types.
 

Macros

#define IS_VALID_EXPRESSION(NAME, T, ...)
 Macro that expands to a static constexpr bool with one template argument which is true only if the expression is valid. More...
 
#define IS_VALID_EXPRESSION_2(NAME, T, U, ...)
 Macro that expands to a static constexpr bool with two template arguments which is true only if the expression is valid. More...
 
#define HAS_MEMBER_FUNCTION_NO_RTYPE(NAME, ...)   IS_VALID_EXPRESSION( HasMemberFunction_ ## NAME, CLASS, std::declval< CLASS & >().NAME( __VA_ARGS__ ) )
 Macro that expands to a static constexpr bool templated on a type that is only true when the type has a method NAME which takes the given arguments. The name of the boolean variable is HasMemberFunction_ ## NAME. More...
 
#define HAS_MEMBER_TYPE(NAME)   IS_VALID_EXPRESSION( HasMemberType_ ## NAME, CLASS, std::declval< typename CLASS::NAME >() )
 Macro that expands to a static constexpr bool templated on a type that is only true when the type has a nested type (or type alias) called NAME. The name of the boolean variable is HasMemberType_ ## NAME. More...
 
#define HAS_STATIC_MEMBER(NAME)   IS_VALID_EXPRESSION( HasStaticMember_ ## NAME, CLASS, std::enable_if_t< !std::is_member_pointer< decltype( &CLASS::NAME ) >::value, bool >{} )
 Macro that expands to a static constexpr bool templated on a type that is only true when the type has a static member called NAME. The name of the boolean variable is HasStaticMember_ ## NAME. More...
 

Typedefs

template<bool ... BOOLS>
using LvArray::typeManipulation::all_of = camp::concepts::metalib::all_of< BOOLS ... >
 A struct that contains a static constexpr bool value that is true if all of BOOLS are true. More...
 
template<typename ... TYPES>
using LvArray::typeManipulation::all_of_t = camp::concepts::metalib::all_of_t< TYPES ... >
 A struct that contains a static constexpr bool value that is true if all of TYPES::value are true. More...
 
template<typename T >
using LvArray::typeManipulation::ViewType = typename internal::GetViewType< T >::type
 An alias for the view type of T. More...
 
template<typename T >
using LvArray::typeManipulation::ViewTypeConstSizes = typename internal::GetViewTypeConstSizes< T >::type
 An alias for the un-resizable view type of T. More...
 
template<typename T >
using LvArray::typeManipulation::ViewTypeConst = typename internal::GetViewTypeConst< T >::type
 An alias for the const view type of T. More...
 
template<typename T >
using LvArray::typeManipulation::NestedViewType = typename internal::GetNestedViewType< T >::type
 An alias for the nested view type of T. More...
 
template<typename T >
using LvArray::typeManipulation::NestedViewTypeConst = typename internal::GetNestedViewTypeConst< T >::type
 An alias for the nested const view type of T. More...
 

Functions

template<typename F >
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE void LvArray::typeManipulation::forEachArg (F &&f)
 The recursive base case where no argument is provided. More...
 
template<typename F , typename ARG , typename ... ARGS>
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE void LvArray::typeManipulation::forEachArg (F &&f, ARG &&arg, ARGS &&... args)
 Call the f with arg and then again with each argument in args . More...
 
 LvArray::typeManipulation::HAS_MEMBER_FUNCTION_NO_RTYPE (toView,)
 Defines a template static constexpr bool HasMemberFunction_toView that is true if CLASS has a method toView(). More...
 
 LvArray::typeManipulation::HAS_MEMBER_FUNCTION_NO_RTYPE (toViewConstSizes,)
 Defines a template static constexpr bool HasMemberFunction_toViewConstSizes that is true if CLASS has a method toView(). More...
 
 LvArray::typeManipulation::HAS_MEMBER_FUNCTION_NO_RTYPE (toViewConst,)
 Defines a template static constexpr bool HasMemberFunction_toViewConst that is true if CLASS has a method toViewConst(). More...
 
 LvArray::typeManipulation::HAS_MEMBER_FUNCTION_NO_RTYPE (toNestedView,)
 Defines a template static constexpr bool HasMemberFunction_toNestedView that is true if CLASS has a method toNestedView(). More...
 
 LvArray::typeManipulation::HAS_MEMBER_FUNCTION_NO_RTYPE (toNestedViewConst,)
 Defines a template static constexpr bool HasMemberFunction_toNestedViewConst that is true if CLASS has a method toNestedViewConst(). More...
 
template<camp::idx_t INDEX_TO_FIND, camp::idx_t INDEX>
constexpr bool LvArray::typeManipulation::internal::contains (camp::idx_seq< INDEX >)
 
template<camp::idx_t INDEX_TO_FIND, camp::idx_t INDEX0, camp::idx_t INDEX1, camp::idx_t... INDICES>
constexpr bool LvArray::typeManipulation::internal::contains (camp::idx_seq< INDEX0, INDEX1, INDICES... >)
 
template<typename PERMUTATION , camp::idx_t... INDICES>
constexpr bool LvArray::typeManipulation::internal::isValidPermutation (PERMUTATION, camp::idx_seq< INDICES... >)
 
template<camp::idx_t... INDICES>
constexpr camp::idx_t LvArray::typeManipulation::internal::getDimension (camp::idx_seq< INDICES... >)
 
template<camp::idx_t... INDICES>
LVARRAY_HOST_DEVICE constexpr camp::idx_t LvArray::typeManipulation::getStrideOneDimension (camp::idx_seq< INDICES... >)
 
template<typename PERMUTATION >
constexpr bool LvArray::typeManipulation::isValidPermutation (PERMUTATION)
 
template<typename T , typename U , typename INDEX_TYPE >
constexpr LVARRAY_HOST_DEVICE std::enable_if_t<(sizeof(T)<=sizeof(U)), INDEX_TYPE > LvArray::typeManipulation::convertSize (INDEX_TYPE const numU)
 Convert a number of values of type U to a number of values of type T. More...
 
template<typename T , typename U , typename INDEX_TYPE >
LVARRAY_HOST_DEVICE std::enable_if_t<(sizeof(T) > sizeof(U)), INDEX_TYPE > LvArray::typeManipulation::convertSize (INDEX_TYPE const numU)
 Convert a number of values of type U to a number of values of type T. More...
 
template<camp::idx_t... INDICES>
LVARRAY_HOST_DEVICE constexpr CArray< camp::idx_t, sizeof...(INDICES) > LvArray::typeManipulation::asArray (camp::idx_seq< INDICES... >)
 

Variables

template<template< typename ... > class TEMPLATE, typename TYPE >
constexpr bool LvArray::typeManipulation::is_instantiation_of = false
 Trait to detect if. More...
 
template<template< typename ... > class TEMPLATE, typename ... ARGS>
constexpr bool LvArray::typeManipulation::is_instantiation_of< TEMPLATE, TEMPLATE< ARGS... > > = true
 Trait to detect if. More...
 
template<typename T >
static constexpr camp::idx_t LvArray::typeManipulation::getDimension = internal::getDimension( T {} )
 

Detailed Description

Contains templates useful for type manipulation.

Macro Definition Documentation

◆ HAS_MEMBER_FUNCTION_NO_RTYPE

#define HAS_MEMBER_FUNCTION_NO_RTYPE (   NAME,
  ... 
)    IS_VALID_EXPRESSION( HasMemberFunction_ ## NAME, CLASS, std::declval< CLASS & >().NAME( __VA_ARGS__ ) )

Macro that expands to a static constexpr bool templated on a type that is only true when the type has a method NAME which takes the given arguments. The name of the boolean variable is HasMemberFunction_ ## NAME.

Parameters
NAMEThe name of the method to look for.
Note
The remaining macro arguments is the argument list to call the method with.
The class type is available through the name CLASS.

◆ HAS_MEMBER_TYPE

#define HAS_MEMBER_TYPE (   NAME)    IS_VALID_EXPRESSION( HasMemberType_ ## NAME, CLASS, std::declval< typename CLASS::NAME >() )

Macro that expands to a static constexpr bool templated on a type that is only true when the type has a nested type (or type alias) called NAME. The name of the boolean variable is HasMemberType_ ## NAME.

Parameters
NAMEThe name of the type to look for.

◆ HAS_STATIC_MEMBER

#define HAS_STATIC_MEMBER (   NAME)    IS_VALID_EXPRESSION( HasStaticMember_ ## NAME, CLASS, std::enable_if_t< !std::is_member_pointer< decltype( &CLASS::NAME ) >::value, bool >{} )

Macro that expands to a static constexpr bool templated on a type that is only true when the type has a static member called NAME. The name of the boolean variable is HasStaticMember_ ## NAME.

Parameters
NAMEThe name of the variable to look for.

◆ IS_VALID_EXPRESSION

#define IS_VALID_EXPRESSION (   NAME,
  T,
  ... 
)
Value:
template< typename _T > \
struct NAME ## _impl \
{ \
private: \
template< typename T > static constexpr auto test( int )->decltype( __VA_ARGS__, bool() ) \
{ return true; } \
template< typename T > static constexpr auto test( ... )->bool \
{ return false; } \
public: \
static constexpr bool value = test< _T >( 0 ); \
}; \
template< typename T > \
static constexpr bool NAME = NAME ## _impl< T >::value

Macro that expands to a static constexpr bool with one template argument which is true only if the expression is valid.

Parameters
NAMEThe name to give the boolean variable.
TName of the template argument in the expression.
Note
The remaining macro arguments consist of the expresion to check for validity.

◆ IS_VALID_EXPRESSION_2

#define IS_VALID_EXPRESSION_2 (   NAME,
  T,
  U,
  ... 
)
Value:
template< typename _T, typename _U > \
struct NAME ## _impl \
{ \
private: \
template< typename T, typename U > static constexpr auto test( int )->decltype( __VA_ARGS__, bool() ) \
{ return true; } \
template< typename T, typename U > static constexpr auto test( ... )->bool \
{ return false; } \
public: \
static constexpr bool value = test< _T, _U >( 0 ); \
}; \
template< typename T, typename U > \
static constexpr bool NAME = NAME ## _impl< T, U >::value

Macro that expands to a static constexpr bool with two template arguments which is true only if the expression is valid.

Parameters
NAMEThe name to give the boolean variable.
TName of the first template argument in the expression.
UName of the second template argument in the expression.
Note
The remaining macro arguments consist of the expresion to check for validity.

Function Documentation

◆ contains() [1/2]

template<camp::idx_t INDEX_TO_FIND, camp::idx_t INDEX>
constexpr bool LvArray::typeManipulation::internal::contains ( camp::idx_seq< INDEX >  )
Returns
Return true iff INDEX_TO_FIND == INDEX.
Template Parameters
INDEX_TO_FINDThe value of the index to find.
INDEXThe index.

◆ contains() [2/2]

template<camp::idx_t INDEX_TO_FIND, camp::idx_t INDEX0, camp::idx_t INDEX1, camp::idx_t... INDICES>
constexpr bool LvArray::typeManipulation::internal::contains ( camp::idx_seq< INDEX0, INDEX1, INDICES... >  )
Returns
Return true iff INDEX_TO_FIND is in { INDEX0, INDEX1, INDICES ... }.
Template Parameters
INDEX_TO_FINDThe value of the index to find.
INDEX0The first index.
INDEX1The second index.
INDICESThe remaining indices.

◆ getDimension()

template<camp::idx_t... INDICES>
constexpr camp::idx_t LvArray::typeManipulation::internal::getDimension ( camp::idx_seq< INDICES... >  )
Template Parameters
INDICESA variadic list of indices.
Returns
The number of indices.

◆ isValidPermutation()

template<typename PERMUTATION , camp::idx_t... INDICES>
constexpr bool LvArray::typeManipulation::internal::isValidPermutation ( PERMUTATION  ,
camp::idx_seq< INDICES... >   
)
Returns
Return true iff PERMUTATION is a valid permutation of INDICES.
Template Parameters
PERMUTATIONThe permutation to check.
INDICESThe indices.