@@ -65,19 +65,15 @@ namespace pmacc
6565 {
6666 }
6767
68- constexpr DataSpace (DataSpace const &) = default;
69-
70- HDINLINE constexpr DataSpace& operator =(DataSpace const &) = default ;
71-
7268 /* * constructor.
7369 *
7470 * Sets size of all dimensions from alpaka.
71+ * Reverses (permutes) the order of the dimensions.
7572 */
7673 template <typename T_MemberType>
77- HDINLINE explicit DataSpace (alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const & value)
74+ HDINLINE explicit constexpr DataSpace (alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const & value)
75+ : BaseType(makeReversedArgs(value, std::make_index_sequence<T_dim>{}))
7876 {
79- for (uint32_t i = 0u ; i < T_dim; i++)
80- (*this )[T_dim - 1 - i] = value[i];
8177 }
8278
8379 /* * Constructor for N-dimensional DataSpace.
@@ -86,7 +82,8 @@ namespace pmacc
8682 *
8783 * @param args size of each dimension, x,y,z,...
8884 */
89- template <typename ... T_Args, typename = std::enable_if_t <(std::is_convertible_v<T_Args, int > && ...)>>
85+ template <std::convertible_to<int >... T_Args>
86+ requires (sizeof ...(T_Args) == T_dim)
9087 constexpr DataSpace (T_Args&&... args) : BaseType(std::forward<T_Args>(args)...)
9188 {
9289 static_assert (sizeof ...(T_Args) == T_dim, " Number of arguments must be equal to the DataSpace dimension." );
@@ -96,12 +93,9 @@ namespace pmacc
9693 {
9794 }
9895
99- HDINLINE DataSpace (math::Size_t<T_dim> const & vec)
96+ // constructor to convert from size_t vector to int dataspace
97+ HDINLINE constexpr DataSpace (math::Size_t<T_dim> const & vec) : BaseType(vec)
10098 {
101- for (uint32_t i = 0 ; i < T_dim; ++i)
102- {
103- (*this )[i] = vec[i];
104- }
10599 }
106100
107101 /* *
@@ -110,14 +104,10 @@ namespace pmacc
110104 * @param value value which is setfor all dimensions
111105 * @return the new DataSpace
112106 */
113- HDINLINE static DataSpace<T_dim> create (int value = 1 )
107+ HDINLINE static constexpr DataSpace<T_dim> create (int value = 1 ) noexcept
114108 {
115- DataSpace<T_dim> tmp;
116- for (uint32_t i = 0 ; i < T_dim; ++i)
117- {
118- tmp[i] = value;
119- }
120- return tmp;
109+ return [value]<std::size_t ... Is>(std::index_sequence<Is...>)
110+ { return DataSpace<T_dim>((static_cast <void >(Is), value)...); }(std::make_index_sequence<T_dim>{});
121111 }
122112
123113 /* *
@@ -136,22 +126,25 @@ namespace pmacc
136126 * @param other DataSpace to compare with
137127 * @return true if one dimension is greater, false otherwise
138128 */
139- HINLINE bool isOneDimensionGreaterThan (MemSpace<T_dim> const & other) const
129+ HINLINE constexpr bool isOneDimensionGreaterThan (MemSpace<T_dim> const & other) const
140130 {
141- for (uint32_t i = 0 ; i < T_dim; ++i)
142- {
143- if ((*this )[i] > other[i])
144- return true ;
145- }
146- return false ;
131+ return [this , other]<std::size_t ... Is>(std::index_sequence<Is...>)
132+ { return (((*this )[Is] > other[Is]) || ...); }(std::make_index_sequence<T_dim>{});
147133 }
148134
149135 HDINLINE operator math::Size_t<T_dim>() const
150136 {
151- math::Size_t<T_dim> result;
152- for (uint32_t i = 0 ; i < T_dim; i++)
153- result[i] = static_cast <size_t >((*this )[i]);
154- return result;
137+ return [this ]<std::size_t ... Is>(std::index_sequence<Is...>) -> math::Size_t<T_dim>
138+ { return {static_cast <std::size_t >((*this )[Is])...}; }(std::make_index_sequence<T_dim>{});
139+ }
140+
141+ private:
142+ template <typename T_MemberType, std::size_t ... Is>
143+ static constexpr BaseType makeReversedArgs (
144+ alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const & value,
145+ std::index_sequence<Is...>) noexcept
146+ {
147+ return {static_cast <int >(value[T_dim - 1 - Is])...};
155148 }
156149 };
157150
0 commit comments