3#ifndef DUNE_COMMON_SIMD_VALUEPROXY_HH
4#define DUNE_COMMON_SIMD_VALUEPROXY_HH
25 template<
class Proxy,
class ValueType>
26 struct NoExtraOperations {};
84 template<
class,
class>
class ExtraOperations = NoExtraOperations>
86 :
public ExtraOperations<ValueProxy<V, ExtraOperations>,
87 typename V::value_type>
90 "ValueProxy may only be instantiated with unqualified "
92 static_assert(IsIndexable<V&>::value && IsIndexable<const V&>::value,
93 "Class ValueProxy requires a SIMD type with "
96 using value_type =
typename V::value_type;
100 "Only arithmetic types are supported");
105 void set(
const value_type &x)
const { vec_[idx_] = x; }
109 : vec_(vec), idx_(idx)
112 ValueProxy(
const ValueProxy&) =
delete;
114 ValueProxy(ValueProxy&&) =
default;
116 operator value_type()
const {
return get(); }
119#define DUNE_SIMD_VALUEPROXY_ASSIGNMENT(OP) \
121 class = decltype(std::declval<value_type&>() OP \
122 autoCopy(std::declval<T>()) )> \
123 ValueProxy operator OP(T &&o) && \
125 value_type x = get(); \
126 x OP autoCopy(std::forward<T>(o)); \
128 return { idx_, vec_ }; \
141#undef DUNE_SIMD_VALUEPROXY_ASSIGNMENT
144 template<
class T = value_type,
146 ValueProxy operator++()
148 value_type x = get();
150 return { idx_, vec_ };
152 template<
class T = value_type,
154 ValueProxy operator--()
156 value_type x =
get();
158 return { idx_, vec_ };
162 template<
class T = value_type,
164 value_type operator++(
int)
166 value_type x =
get();
167 value_type result = x++;
171 template<
class T = value_type,
173 value_type operator--(
int)
175 value_type x =
get();
176 value_type result = x--;
183 friend void swap(
const ValueProxy &a,
const ValueProxy &b) {
184 value_type tmp = a.get();
188 friend void swap(value_type &a,
const ValueProxy &b) {
189 value_type tmp = std::move(a);
193 friend void swap(
const ValueProxy &a, value_type &b) {
194 value_type tmp = a.get();
215#define DUNE_SIMD_VALUEPROXY_BINARY(OP) \
216 template<std::derived_from<V> W> \
217 friend auto operator OP(const W &l, ValueProxy &&r) \
218 -> decltype(l OP std::declval<value_type>()) \
220 return l OP r.get(); \
222 template<std::derived_from<V> W> \
223 friend auto operator OP(ValueProxy &&l, const W &r) \
224 -> decltype(std::declval<value_type>() OP r) \
226 return l.get() OP r; \
228 template<class D = void> \
229 friend auto operator OP(ValueProxy &&l, ValueProxy &&r) \
230 -> decltype(std::declval<std::conditional_t<true, value_type, D> >() \
231 OP std::declval<value_type>()) \
233 return l.get() OP r.get(); \
236 std::enable_if_t<std::is_arithmetic<S>::value, int> = 0> \
237 friend auto operator OP(const S &l, ValueProxy &&r) \
238 -> decltype(l OP std::declval<value_type>()) \
240 return l OP r.get(); \
243 std::enable_if_t<std::is_arithmetic<S>::value, int> = 0> \
244 friend auto operator OP(ValueProxy &&l, const S &r) \
245 -> decltype(std::declval<value_type>() OP r) \
247 return l.get() OP r; \
266#undef DUNE_SIMD_VALUEPROXY_BINARY
268#define DUNE_SIMD_VALUEPROXY_ASSIGN(OP) \
269 template<std::derived_from<V> W> \
270 friend auto operator OP(W &l, ValueProxy &&r) \
271 -> decltype(l OP std::declval<value_type>()) \
273 return l OP r.get(); \
286#undef DUNE_SIMD_VALUEPROXY_ASSIGN
293 template<
class V,
template<
class,
class>
class ExtraOperations>
294 struct AutonomousValueType<Simd::Impl::ValueProxy<V, ExtraOperations> > :
295 AutonomousValueType<typename V::value_type> {};
#define DUNE_SIMD_VALUEPROXY_BINARY(OP)
Definition valueproxy.hh:215
#define DUNE_SIMD_VALUEPROXY_ASSIGNMENT(OP)
Definition valueproxy.hh:119
#define DUNE_SIMD_VALUEPROXY_ASSIGN(OP)
Definition valueproxy.hh:268
Traits for type conversions and type information.
Dune namespace
Definition alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition integersequence.hh:22