16 #include "LvArrayConfig.hpp" 20 #include <camp/camp.hpp> 23 #include <initializer_list> 25 #include <type_traits> 27 #if defined(__GLIBCXX__) && __GLIBCXX__ <= 20150626 33 template<
typename T >
34 using is_trivially_default_constructible = has_trivial_default_constructor< T >;
45 #define IS_VALID_EXPRESSION( NAME, T, ... ) \ 46 template< typename _T > \ 47 struct NAME ## _impl \ 50 template< typename T > static constexpr auto test( int )->decltype( __VA_ARGS__, bool() ) \ 52 template< typename T > static constexpr auto test( ... )->bool \ 55 static constexpr bool value = test< _T >( 0 ); \ 57 template< typename T > \ 58 static constexpr bool NAME = NAME ## _impl< T >::value 68 #define IS_VALID_EXPRESSION_2( NAME, T, U, ... ) \ 69 template< typename _T, typename _U > \ 70 struct NAME ## _impl \ 73 template< typename T, typename U > static constexpr auto test( int )->decltype( __VA_ARGS__, bool() ) \ 75 template< typename T, typename U > static constexpr auto test( ... )->bool \ 78 static constexpr bool value = test< _T, _U >( 0 ); \ 80 template< typename T, typename U > \ 81 static constexpr bool NAME = NAME ## _impl< T, U >::value 91 #define HAS_MEMBER_FUNCTION_NO_RTYPE( NAME, ... ) \ 92 IS_VALID_EXPRESSION( HasMemberFunction_ ## NAME, CLASS, std::declval< CLASS & >().NAME( __VA_ARGS__ ) ) 100 #define HAS_MEMBER_TYPE( NAME ) \ 101 IS_VALID_EXPRESSION( HasMemberType_ ## NAME, CLASS, std::declval< typename CLASS::NAME >() ) 109 #define HAS_STATIC_MEMBER( NAME ) \ 110 IS_VALID_EXPRESSION( HasStaticMember_ ## NAME, CLASS, std::enable_if_t< !std::is_member_pointer< decltype( &CLASS::NAME ) >::value, bool >{} ) 118 namespace typeManipulation
127 template<
typename F >
142 template<
typename F,
typename ARG,
typename ... ARGS >
147 forEachArg( std::forward< F >( f ), std::forward< ARGS >( args ) ... );
155 template<
bool ... BOOLS >
163 template<
typename ... TYPES >
172 template<
template<
typename ... >
class TEMPLATE,
183 template<
template<
typename ... >
class TEMPLATE,
185 constexpr bool is_instantiation_of< TEMPLATE, TEMPLATE< ARGS... > > =
true;
231 template<
typename T,
bool=HasMemberFunction_toView< T > >
244 template<
typename T >
248 using type = decltype( std::declval< T & >().toView() );
257 template<
typename T,
bool=HasMemberFunction_toViewConstSizes< T > >
270 template<
typename T >
274 using type = decltype( std::declval< T & >().toViewConstSizes() );
283 template<
typename T,
bool=HasMemberFunction_toViewConst< T > >
287 using type = std::remove_reference_t< T >
const &;
296 template<
typename T >
300 using type = decltype( std::declval< T & >().toViewConst() );
308 template<
typename T,
bool=HasMemberFunction_toNestedView< T > >
321 template<
typename T >
325 using type = decltype( std::declval< T & >().toNestedView() )
const;
333 template<
typename T,
bool=HasMemberFunction_toNestedViewConst< T > >
346 template<
typename T >
350 using type = decltype( std::declval< T & >().toNestedViewConst() )
const;
359 template<
typename T >
366 template<
typename T >
373 template<
typename T >
380 template<
typename T >
387 template<
typename T >
399 template< camp::
idx_t INDEX_TO_FIND, camp::
idx_t INDEX >
400 constexpr
bool contains( camp::idx_seq< INDEX > )
401 {
return INDEX_TO_FIND == INDEX; }
410 template< camp::idx_t INDEX_TO_FIND, camp::idx_t INDEX0, camp::idx_t INDEX1, camp::idx_t... INDICES >
411 constexpr
bool contains( camp::idx_seq< INDEX0, INDEX1, INDICES... > )
412 {
return ( INDEX_TO_FIND == INDEX0 ) || contains< INDEX_TO_FIND >( camp::idx_seq< INDEX1, INDICES... > {} ); }
419 template<
typename PERMUTATION, camp::idx_t... INDICES >
427 template< camp::idx_t... INDICES >
429 {
return sizeof...( INDICES ); }
437 template<
typename T >
438 static constexpr camp::idx_t
getDimension = internal::getDimension( T {} );
444 template< camp::idx_t... INDICES >
447 constexpr camp::idx_t dimension = camp::seq_at<
sizeof...( INDICES ) - 1, camp::idx_seq< INDICES... > >::value;
448 static_assert( dimension >= 0,
"The dimension must be greater than zero." );
449 static_assert( dimension <
sizeof...( INDICES ),
"The dimension must be less than NDIM." );
457 template<
typename PERMUTATION >
460 constexpr
int NDIM = getDimension< PERMUTATION >;
473 template<
typename T,
typename U,
typename INDEX_TYPE >
475 std::enable_if_t< ( sizeof( T ) <= sizeof( U ) ), INDEX_TYPE >
478 static_assert(
sizeof( U ) %
sizeof( T ) == 0,
"T and U need to have compatable sizes." );
480 return numU *
sizeof( U ) /
sizeof( T );
492 template<
typename T,
typename U,
typename INDEX_TYPE >
494 std::enable_if_t< ( sizeof( T ) >
sizeof( U ) ), INDEX_TYPE >
497 static_assert(
sizeof( T ) %
sizeof( U ) == 0,
"T and U need to have compatable sizes." );
499 INDEX_TYPE
const numUPerT =
sizeof( T ) /
sizeof( U );
500 INDEX_TYPE
const remainder = numU % numUPerT;
503 return numU / numUPerT;
512 template<
typename T, camp::
idx_t N >
521 {
return data[ i ]; }
529 {
return data[ i ]; }
547 template< camp::idx_t... INDICES >
549 CArray< camp::idx_t,
sizeof...( INDICES ) >
asArray( camp::idx_seq< INDICES... > )
550 {
return { INDICES ... }; }
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:79
typename GetViewTypeConst< T >::type type
An alias for the view type.
Definition: typeManipulation.hpp:337
decltype(std::declval< T &>().toNestedViewConst()) const type
An alias for the view type.
Definition: typeManipulation.hpp:350
T & type
An alias for the view type.
Definition: typeManipulation.hpp:235
LVARRAY_HOST_DEVICE constexpr CArray< camp::idx_t, sizeof...(INDICES) > asArray(camp::idx_seq< INDICES... >)
Definition: typeManipulation.hpp:549
A helper struct used to get the const view type of an object.
Definition: typeManipulation.hpp:284
constexpr bool isValidPermutation(PERMUTATION)
Definition: typeManipulation.hpp:458
A helper struct used to get the nested view const type of an object.
Definition: typeManipulation.hpp:334
decltype(std::declval< T &>().toNestedView()) const type
An alias for the view type.
Definition: typeManipulation.hpp:325
typename GetViewType< T >::type type
An alias for the view type.
Definition: typeManipulation.hpp:261
decltype(std::declval< T &>().toViewConst()) type
An alias for the const view type.
Definition: typeManipulation.hpp:300
LVARRAY_HOST_DEVICE constexpr camp::idx_t getStrideOneDimension(camp::idx_seq< INDICES... >)
Definition: typeManipulation.hpp:445
typename internal::GetViewTypeConst< T >::type ViewTypeConst
An alias for the const view type of T.
Definition: typeManipulation.hpp:374
constexpr bool is_instantiation_of
Trait to detect if.
Definition: typeManipulation.hpp:174
A helper struct used to get the view type of an object.
Definition: typeManipulation.hpp:232
decltype(std::declval< T &>().toView()) type
An alias for the view type.
Definition: typeManipulation.hpp:248
A helper struct used to get the un-resizable view type of an object.
Definition: typeManipulation.hpp:258
constexpr LVARRAY_HOST_DEVICE camp::idx_t size()
Definition: typeManipulation.hpp:535
decltype(std::declval< T &>().toViewConstSizes()) type
An alias for the view type.
Definition: typeManipulation.hpp:274
#define HAS_MEMBER_FUNCTION_NO_RTYPE(NAME,...)
Macro that expands to a static constexpr bool templated on a type that is only true when the type has...
Definition: typeManipulation.hpp:91
camp::concepts::metalib::all_of< BOOLS ... > all_of
A struct that contains a static constexpr bool value that is true if all of BOOLS are true...
Definition: typeManipulation.hpp:156
typename internal::GetNestedViewTypeConst< T >::type NestedViewTypeConst
An alias for the nested const view type of T.
Definition: typeManipulation.hpp:388
The top level namespace.
Definition: Array.hpp:24
typename internal::GetViewTypeConstSizes< T >::type ViewTypeConstSizes
An alias for the un-resizable view type of T.
Definition: typeManipulation.hpp:367
typename internal::GetNestedViewType< T >::type NestedViewType
An alias for the nested view type of T.
Definition: typeManipulation.hpp:381
typename GetViewType< T >::type type
An alias for the view type.
Definition: typeManipulation.hpp:312
Contains a bunch of macro definitions.
LVARRAY_HOST_DEVICE std::enable_if_t<(sizeof(T) > sizeof(U)), INDEX_TYPE > convertSize(INDEX_TYPE const numU)
Convert a number of values of type U to a number of values of type T.
Definition: typeManipulation.hpp:495
constexpr LVARRAY_HOST_DEVICE T const & operator[](camp::idx_t const i) const
Definition: typeManipulation.hpp:528
A helper struct used to get the nested view type of an object.
Definition: typeManipulation.hpp:309
A wrapper around a compile time c array.
Definition: typeManipulation.hpp:513
typename internal::GetViewType< T >::type ViewType
An alias for the view type of T.
Definition: typeManipulation.hpp:360
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:614
camp::concepts::metalib::all_of_t< TYPES ... > all_of_t
A struct that contains a static constexpr bool value that is true if all of TYPES::value are true...
Definition: typeManipulation.hpp:164
#define LVARRAY_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:360
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE void forEachArg(F &&f, ARG &&arg, ARGS &&... args)
Call the f with arg and then again with each argument in args .
Definition: typeManipulation.hpp:144
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600
std::remove_reference_t< T > const & type
An alias for the const view type.
Definition: typeManipulation.hpp:287
static constexpr camp::idx_t getDimension
Definition: typeManipulation.hpp:438
LVARRAY_INTEL_CONSTEXPR LVARRAY_HOST_DEVICE T & operator[](camp::idx_t const i)
Definition: typeManipulation.hpp:520