CMS 3D CMS Logo

cuda_cxx17.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDAUtilities_cuda_cxx17_h
2 #define HeterogeneousCore_CUDAUtilities_cuda_cxx17_h
3 
4 #include <initializer_list>
5 
6 // CUDA does not support C++17 yet, so we define here some of the missing library functions
7 #if __cplusplus <= 201402L
8 
9 namespace std {
10 
11  // from https://en.cppreference.com/w/cpp/iterator/size
12  template <class C>
13  constexpr auto size(const C& c) -> decltype(c.size()) {
14  return c.size();
15  }
16 
17  template <class T, std::size_t N>
18  constexpr std::size_t size(const T (&array)[N]) noexcept {
19  return N;
20  }
21 
22  // from https://en.cppreference.com/w/cpp/iterator/empty
23  template <class C>
24  constexpr auto empty(const C& c) -> decltype(c.empty()) {
25  return c.empty();
26  }
27 
28  template <class T, std::size_t N>
29  constexpr bool empty(const T (&array)[N]) noexcept {
30  return false;
31  }
32 
33  template <class E>
34  constexpr bool empty(std::initializer_list<E> il) noexcept {
35  return il.size() == 0;
36  }
37 
38  // from https://en.cppreference.com/w/cpp/iterator/data
39  template <class C>
40  constexpr auto data(C& c) -> decltype(c.data()) {
41  return c.data();
42  }
43 
44  template <class C>
45  constexpr auto data(const C& c) -> decltype(c.data()) {
46  return c.data();
47  }
48 
49  template <class T, std::size_t N>
50  constexpr T* data(T (&array)[N]) noexcept {
51  return array;
52  }
53 
54  template <class E>
55  constexpr const E* data(std::initializer_list<E> il) noexcept {
56  return il.begin();
57  }
58 
59 } // namespace std
60 
61 #endif
62 
63 #endif // HeterogeneousCore_CUDAUtilities_cuda_cxx17_h
std::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: cuda_cxx17.h:40
mps_check.array
array
Definition: mps_check.py:216
std::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: cuda_cxx17.h:13
N
#define N
Definition: blowfish.cc:9
std::empty
constexpr auto empty(const C &c) -> decltype(c.empty())
Definition: cuda_cxx17.h:24
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
std
Definition: JetResolutionObject.h:76
gen::C
C
Definition: PomwigHadronizer.cc:76
T
long double T
Definition: Basic3DVectorLD.h:48