Advanced Multi-Physics (AMP)
On-Line Documentation
TypeTraits.h
Go to the documentation of this file.
1// This file contains functions to help identify type traits
2// clang-format off
3#ifndef included_AMP_TypeTraits
4#define included_AMP_TypeTraits
5
6#include <memory>
7#include <utility>
8#include <vector>
9
10#include "AMP/utils/ArraySize.h" // Forward declare Array
11
12namespace AMP {
13
15template<typename T> struct is_shared_ptr : std::false_type {};
16template<typename T> struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
17
19template<typename T> struct is_unique_ptr : std::false_type {};
20template<typename T> struct is_unique_ptr<std::unique_ptr<T>> : std::true_type {};
21
23template<typename T> struct is_vector : std::false_type {};
24template<typename T> struct is_vector<std::vector<T>> : std::true_type {};
25
27template<typename T> struct is_array : std::false_type {};
28template<typename T, std::size_t N> struct is_array<std::array<T, N>> : std::true_type {};
29
30// Function to test if a type is a std::pair
31template<typename> struct is_pair : std::false_type {};
32template<typename T, typename U> struct is_pair<std::pair<T, U>> : std::true_type {};
33
35template<typename T> struct is_Array : std::false_type {};
36template<typename T> struct is_Array<Array<T,FunctionTable<T>,HostAllocator<void>>> : std::true_type {};
37template<typename T> struct is_Array<Array<T,FunctionTable<T>,HostAllocator<T>>> : std::true_type {};
38#ifdef AMP_USE_CUDA
39template<typename T> struct is_Array<Array<T,GPUFunctionTable<T>,CudaManagedAllocator<T>>> : std::true_type {};
40template<typename T> struct is_Array<Array<T,GPUFunctionTable<T>,CudaDevAllocator<T>>> : std::true_type {};
41#endif
42#ifdef AMP_USE_HIP
43template<typename T> struct is_Array<Array<T,GPUFunctionTable<T>,HipManagedAllocator<T>>> : std::true_type {};
44template<typename T> struct is_Array<Array<T,GPUFunctionTable<T>,HipDevAllocator<T>>> : std::true_type {};
45#endif
46
48template<typename T> struct is_string : std::false_type {};
49template<> struct is_string<std::string> : std::true_type {};
50template<> struct is_string<std::string_view> : std::true_type {};
51template<> struct is_string<char *> : std::true_type {};
52template<std::size_t N> struct is_string<char[N]> : std::true_type {};
53
55template<typename T>
56struct has_size {
57private:
58 typedef std::true_type yes;
59 typedef std::false_type no;
60 template<typename U> static auto test( int ) -> decltype( std::declval<U>().size() == 1, yes() );
61 template<typename> static no test( ... );
62public:
63 static constexpr bool value = std::is_same<decltype( test<T>( 0 ) ), yes>::value;
64};
65
67using std::begin;
68template<typename T, typename = void> struct has_begin : std::false_type {};
69template<typename T> struct has_begin<T, decltype( void( std::begin( std::declval<T &>() ) ) )> : std::true_type {};
70template<typename T, typename = void> struct has_end : std::false_type {};
71template<typename T> struct has_end<T, decltype( void( std::end( std::declval<T &>() ) ) )> : std::true_type {};
72template<typename T, typename = void> struct has_empty : std::false_type {};
73template<typename T> struct has_empty<T, decltype( void( std::empty( std::declval<T &>() ) ) )> : std::true_type {};
74
76template<typename T> struct is_initializer_list : std::false_type {};
77template<typename T> struct is_initializer_list<std::initializer_list<T>> : std::true_type {};
78
80template<class T> struct is_complex : public std::false_type {};
81template<class T> struct is_complex<const T> : public is_complex<T> {};
82template<class T> struct is_complex<volatile const T> : public is_complex<T> {};
83template<class T> struct is_complex<volatile T> : public is_complex<T> {};
84template<class T> struct is_complex<std::complex<T>> : public std::true_type {};
85
86// Helper functions
87template<class T> constexpr bool is_shared_ptr_v = is_shared_ptr<T>::value;
88template<class T> constexpr bool is_unique_ptr_v = is_unique_ptr<T>::value;
89template<class T> constexpr bool is_vector_v = is_vector<T>::value;
90template<class T> constexpr bool is_array_v = is_array<T>::value;
91template<class T> constexpr bool is_Array_v = is_Array<T>::value;
92template<class T> constexpr bool is_pair_v = is_pair<T>::value;
93template<class T> constexpr bool is_string_v = is_string<T>::value;
94template<class T> constexpr bool has_size_v = has_size<T>::value;
95template<class T> constexpr bool has_begin_v = has_begin<T>::value;
96template<class T> constexpr bool has_end_v = has_end<T>::value;
97template<class T> constexpr bool has_empty_v = has_empty<T>::value;
98template<class T> constexpr bool is_container_v = has_begin_v<T> && has_end_v<T> && has_empty_v<T>;
99template<class T> constexpr bool is_initializer_list_v = is_initializer_list<T>::value;
100template<class T> constexpr bool is_complex_v = is_complex<T>::value;
101
103template<class T1, class T2> constexpr bool is_same_int_v =
104 std::is_integral_v<T1> && std::is_integral_v<T2> &&
105 ( std::is_signed_v<T1> == std::is_signed_v<T2> ) && ( sizeof( T1 ) == sizeof( T2 ) );
106
107// Remove const and reference
108template<typename T> using remove_cvref_t = typename std::remove_cv_t<typename std::remove_reference_t<T>>;
109
110// Return the number of arguments in a given function
111template<typename T> struct arg_count;
112template<typename T, typename... Args>
113struct arg_count<T( Args... )> { static constexpr std::size_t value = sizeof...( Args ); };
114template<class T> constexpr bool arg_count_v = arg_count<T>::value;
115
116} // namespace AMP
117
118#endif
119// clang-format on
Allocator based on cudaMallocManaged.
constexpr bool is_pair_v
Definition TypeTraits.h:92
constexpr bool is_vector_v
Definition TypeTraits.h:89
constexpr bool is_unique_ptr_v
Definition TypeTraits.h:88
constexpr bool has_begin_v
Definition TypeTraits.h:95
constexpr bool is_container_v
Definition TypeTraits.h:98
constexpr bool is_array_v
Definition TypeTraits.h:90
constexpr bool arg_count_v
Definition TypeTraits.h:114
constexpr bool is_Array_v
Definition TypeTraits.h:91
constexpr bool is_complex_v
Definition TypeTraits.h:100
constexpr bool is_initializer_list_v
Definition TypeTraits.h:99
constexpr bool has_empty_v
Definition TypeTraits.h:97
std::allocator< TYPE > HostAllocator
Definition Memory.h:69
constexpr bool is_string_v
Definition TypeTraits.h:93
constexpr bool has_end_v
Definition TypeTraits.h:96
typename std::remove_cv_t< typename std::remove_reference_t< T > > remove_cvref_t
Definition TypeTraits.h:108
constexpr bool has_size_v
Definition TypeTraits.h:94
constexpr bool is_same_int_v
Checks whether two types are both integers of the same size and sign.
Definition TypeTraits.h:103
constexpr bool is_shared_ptr_v
Definition TypeTraits.h:87
Checks whether T has a size() function.
Definition TypeTraits.h:56
static auto test(int) -> decltype(std::declval< U >().size()==1, yes())
static no test(...)
static constexpr bool value
Definition TypeTraits.h:63
std::false_type no
Definition TypeTraits.h:59
std::true_type yes
Definition TypeTraits.h:58
Checks whether T is an AMP::Array.
Definition TypeTraits.h:35
Checks whether T is a std::array.
Definition TypeTraits.h:27
Checks whether T is complex.
Definition TypeTraits.h:80
Checks whether T is an initializer_list.
Definition TypeTraits.h:76
Checks whether T is a shared_ptr.
Definition TypeTraits.h:15
Checks whether T is convertible to a string.
Definition TypeTraits.h:48
Checks whether T is a unique_ptr.
Definition TypeTraits.h:19
Checks whether T is a std::vector.
Definition TypeTraits.h:23



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page