File indexing completed on 2025-01-18 09:54:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #pragma once
0018
0019 #include <type_traits>
0020
0021 #include "corecel/cont/Array.hh"
0022
0023 namespace celeritas
0024 {
0025
0026 #define CELER_DEFINE_ARRAY_ASSIGN(TOKEN) \
0027 template<class T, size_type N> \
0028 inline CELER_FUNCTION Array<T, N>& operator TOKEN(Array<T, N>& x, \
0029 Array<T, N> const& y) \
0030 { \
0031 for (size_type i = 0; i != N; ++i) \
0032 { \
0033 x[i] TOKEN y[i]; \
0034 } \
0035 return x; \
0036 } \
0037 \
0038 template<class T, size_type N, class T2 = std::remove_cv_t<T>> \
0039 inline CELER_FUNCTION Array<T, N>& operator TOKEN(Array<T, N>& x, \
0040 T2 const& y) \
0041 { \
0042 for (size_type i = 0; i != N; ++i) \
0043 { \
0044 x[i] TOKEN y; \
0045 } \
0046 return x; \
0047 }
0048
0049 #define CELER_DEFINE_ARRAY_ARITHM(TOKEN) \
0050 template<class T, size_type N> \
0051 inline CELER_FUNCTION Array<T, N> operator TOKEN(Array<T, N> const& x, \
0052 Array<T, N> const& y) \
0053 { \
0054 Array<T, N> result{x}; \
0055 return (result TOKEN## = y); \
0056 } \
0057 \
0058 template<class T, size_type N, class T2 = std::remove_cv_t<T>> \
0059 inline CELER_FUNCTION Array<T, N> operator TOKEN(Array<T, N> const& x, \
0060 T2 const& y) \
0061 { \
0062 Array<T, N> result{x}; \
0063 return (result TOKEN## = y); \
0064 }
0065
0066
0067
0068
0069 CELER_DEFINE_ARRAY_ASSIGN(+=)
0070 CELER_DEFINE_ARRAY_ASSIGN(-=)
0071 CELER_DEFINE_ARRAY_ASSIGN(*=)
0072 CELER_DEFINE_ARRAY_ASSIGN(/=)
0073
0074
0075
0076
0077
0078 CELER_DEFINE_ARRAY_ARITHM(+)
0079 CELER_DEFINE_ARRAY_ARITHM(-)
0080 CELER_DEFINE_ARRAY_ARITHM(*)
0081 CELER_DEFINE_ARRAY_ARITHM(/)
0082
0083
0084
0085 template<class T, size_type N, class T2 = std::remove_cv_t<T>>
0086 inline CELER_FUNCTION Array<T, N> operator*(T2 const& y, Array<T, N> const& x)
0087 {
0088 return x * y;
0089 }
0090
0091
0092
0093
0094
0095 template<class T, size_type N>
0096 inline CELER_FUNCTION Array<T, N> operator-(Array<T, N> const& x)
0097 {
0098 Array<T, N> result;
0099 for (size_type i = 0; i != N; ++i)
0100 {
0101 result[i] = -x[i];
0102 }
0103 return result;
0104 }
0105
0106 #undef CELER_DEFINE_ARRAY_ASSIGN
0107 #undef CELER_DEFINE_ARRAY_ARITHM
0108
0109 }