@@ -41,6 +41,7 @@ namespace detail
41
41
template <typename T_Type, int T_Dim>
42
42
struct Vector_components
43
43
{
44
+ static const bool isConst = false ;
44
45
static const int dim = T_Dim;
45
46
typedef T_Type type;
46
47
@@ -60,6 +61,42 @@ struct Vector_components
60
61
}
61
62
};
62
63
64
+
65
+ /* * functor to copy a object element wise
66
+ *
67
+ * @tparam isDestConst define if destination is const (not copyable) object
68
+ */
69
+ template <bool isDestConst>
70
+ struct CopyElementWise
71
+ {
72
+ /* * copy object element wise
73
+ *
74
+ * @tparam T_Dest destination object type
75
+ * @tparam T_Src source object type
76
+ */
77
+ template <typename T_Dest,typename T_Src>
78
+ HDINLINE void operator ()(T_Dest& dest,const T_Src& src) const
79
+ {
80
+ PMACC_CASSERT_MSG (CopyElementWise_destination_and_source_had_different_dimension,
81
+ T_Dest::dim == T_Src::dim);
82
+ for (int d = 0 ; d < T_Dest::dim; d++)
83
+ dest[d] = src[d];
84
+ }
85
+ };
86
+
87
+ /* * specialization for constant destination
88
+ *
89
+ * the constant storage is already available and set in the destination
90
+ */
91
+ template <>
92
+ struct CopyElementWise <true >
93
+ {
94
+ template <typename T_Dest,typename T_Src>
95
+ HDINLINE void operator ()(T_Dest& dest,const T_Src& src) const
96
+ {
97
+ }
98
+ };
99
+
63
100
} // namespace detail
64
101
65
102
namespace tag
@@ -128,8 +165,7 @@ struct Vector : private T_Storage<T_Type, T_dim>, protected T_Accessor, protecte
128
165
129
166
HDINLINE Vector (const This& other)
130
167
{
131
- for (int i = 0 ; i < dim; i++)
132
- (*this )[i] = other[i];
168
+ detail::CopyElementWise<Storage::isConst>()(*this ,other);
133
169
}
134
170
135
171
template <
0 commit comments