28
28
29
29
namespace pmacc
30
30
{
31
+ namespace detail
32
+ {
33
+ template <typename T_Vector, typename T_TYPE>
34
+ HDINLINE auto & subscript (T_TYPE* p, int const idx, std::integral_constant<uint32_t , 1 >)
35
+ {
36
+ return p[idx];
37
+ }
38
+
39
+ template <typename T_Vector, typename T_TYPE>
40
+ HDINLINE auto * subscript (T_TYPE* p, int const idx, std::integral_constant<uint32_t , 2 >)
41
+ {
42
+ return p + idx * T_Vector::x::value;
43
+ }
44
+
45
+ template <typename T_Vector, typename T_TYPE>
46
+ HDINLINE auto * subscript (T_TYPE* p, int const idx, std::integral_constant<uint32_t , 3 >)
47
+ {
48
+ return p + idx * (T_Vector::x::value * T_Vector::y::value);
49
+ }
50
+ } // namespace detail
51
+
31
52
/* * create shared memory on gpu
32
53
*
33
54
* @tparam T_TYPE type of memory objects
@@ -52,16 +73,16 @@ namespace pmacc
52
73
53
74
HDINLINE SharedBox (SharedBox const &) = default;
54
75
55
- HDINLINE decltype (auto ) operator[](const int idx) const
76
+ using ReducedType1D = T_TYPE&;
77
+ using ReducedType2D = SharedBox<T_TYPE, typename math::CT::shrinkTo<T_Vector,1 >::type, T_id>;
78
+ using ReducedType3D = SharedBox<T_TYPE, typename math::CT::shrinkTo<T_Vector,2 >::type, T_id>;
79
+ using ReducedType
80
+ = std::conditional_t <Dim == 1 , ReducedType1D, std::conditional_t <Dim == 2 , ReducedType2D, ReducedType3D>>;
81
+
82
+ HDINLINE ReducedType operator [](const int idx) const
56
83
{
57
- if constexpr (Dim == 1 )
58
- return fixedPointer[idx];
59
- else if constexpr (Dim == 2 )
60
- return SharedBox<T_TYPE, math::CT::Int<T_Vector::x::value>, T_id>{
61
- fixedPointer + idx * T_Vector::x::value};
62
- else if constexpr (Dim == 3 )
63
- return SharedBox<T_TYPE, math::CT::Int<T_Vector::x::value, T_Vector::y::value>, T_id>{
64
- fixedPointer + idx * (T_Vector::x::value * T_Vector::y::value)};
84
+ // /@todo(bgruber): inline and replace this by if constexpr in C++17
85
+ return {detail::subscript<T_Vector>(fixedPointer, idx, std::integral_constant<uint32_t , T_dim>{})};
65
86
}
66
87
67
88
/* !return the first value in the box (list)
0 commit comments