QUDA  v1.1.0
A library for QCD on GPUs
array.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace detail {
4 
5 template<typename T, int m>
6 struct array {
7  typedef T value_type;
8  typedef T head_type;
9  typedef array<T, m-1> tail_type;
10  static const int size = m;
13  __host__ __device__ __forceinline__
14  array(head_type h, const tail_type& t) : head(h), tail(t) {}
15  __host__ __device__ __forceinline__
16  array() : head(), tail() {}
17  __host__ __device__ __forceinline__
18  array(const array& other) : head(other.head), tail(other.tail) {}
19  __host__ __device__ __forceinline__
20  array& operator=(const array& other) {
21  head = other.head;
22  tail = other.tail;
23  return *this;
24  }
25  __host__ __device__ __forceinline__
26  bool operator==(const array& other) const {
27  return (head == other.head) && (tail == other.tail);
28  }
29  __host__ __device__ __forceinline__
30  bool operator!=(const array& other) const {
31  return !operator==(other);
32  }
33 };
34 
35 template<typename T>
36 struct array<T, 1> {
37  typedef T value_type;
38  typedef T head_type;
39  static const int size = 1;
41  __host__ __device__ __forceinline__
42  array(head_type h) : head(h){}
43  __host__ __device__ __forceinline__
44  array() : head() {}
45  __host__ __device__ __forceinline__
46  array(const array& other) : head(other.head) {}
47  __host__ __device__ __forceinline__
48  array& operator=(const array& other) {
49  head = other.head;
50  return *this;
51  }
52  __host__ __device__ __forceinline__
53  bool operator==(const array& other) const {
54  return (head == other.head);
55  }
56  __host__ __device__ __forceinline__
57  bool operator!=(const array& other) const {
58  return !operator==(other);
59  }
60 };
61 
62 template<typename T>
63 struct array<T, 0>{};
64 
65 template<typename T, int m, int i>
66 struct get_impl {
67  __host__ __device__ __forceinline__ static T& impl(array<T, m>& src) {
69  }
70  __host__ __device__ __forceinline__ static T impl(const array<T, m>& src) {
72  }
73 };
74 
75 template<typename T, int m>
76 struct get_impl<T, m, 0> {
77  __host__ __device__ __forceinline__ static T& impl(array<T, m>& src) {
78  return src.head;
79  }
80  __host__ __device__ __forceinline__ static T impl(const array<T, m>& src) {
81  return src.head;
82  }
83 };
84 
85 template<int i, typename T, int m>
86 __host__ __device__ __forceinline__
87 T& get(array<T, m>& src) {
89 }
90 
91 template<int i, typename T, int m>
92 __host__ __device__ __forceinline__
93 T get(const array<T, m>& src) {
95 }
96 
97 } //end namespace detail
Definition: alias.h:4
__host__ __device__ __forceinline__ T & get(array< T, m > &src)
Definition: array.h:87
__host__ __device__ __forceinline__ array(const array &other)
Definition: array.h:46
__host__ __device__ __forceinline__ array()
Definition: array.h:44
head_type head
Definition: array.h:40
__host__ __device__ __forceinline__ bool operator==(const array &other) const
Definition: array.h:53
__host__ __device__ __forceinline__ bool operator!=(const array &other) const
Definition: array.h:57
__host__ __device__ __forceinline__ array & operator=(const array &other)
Definition: array.h:48
__host__ __device__ __forceinline__ array(head_type h)
Definition: array.h:42
array< T, m-1 > tail_type
Definition: array.h:9
static const int size
Definition: array.h:10
__host__ __device__ __forceinline__ array & operator=(const array &other)
Definition: array.h:20
T value_type
Definition: array.h:7
tail_type tail
Definition: array.h:12
T head_type
Definition: array.h:8
__host__ __device__ __forceinline__ array(const array &other)
Definition: array.h:18
__host__ __device__ __forceinline__ array()
Definition: array.h:16
__host__ __device__ __forceinline__ bool operator==(const array &other) const
Definition: array.h:26
__host__ __device__ __forceinline__ array(head_type h, const tail_type &t)
Definition: array.h:14
head_type head
Definition: array.h:11
__host__ __device__ __forceinline__ bool operator!=(const array &other) const
Definition: array.h:30
__host__ __device__ static __forceinline__ T impl(const array< T, m > &src)
Definition: array.h:80
__host__ __device__ static __forceinline__ T & impl(array< T, m > &src)
Definition: array.h:77
__host__ __device__ static __forceinline__ T impl(const array< T, m > &src)
Definition: array.h:70
__host__ __device__ static __forceinline__ T & impl(array< T, m > &src)
Definition: array.h:67