28 #ifndef VC_COMMON_ELEMENTREFERENCE_H_ 29 #define VC_COMMON_ELEMENTREFERENCE_H_ 33 namespace Vc_VERSIONED_NAMESPACE
37 template <
typename U,
typename Accessor = U>
class ElementReference
39 using value_type =
typename U::value_type;
42 Vc_INTRINSIC ElementReference(U &o,
int i) noexcept : index(i), obj(o) {}
44 static constexpr
bool get_noexcept =
45 noexcept(Accessor::get(std::declval<U &>(),
int()));
46 template <
typename T>
static constexpr
bool set_noexcept()
48 return noexcept(Accessor::set(std::declval<U &>(),
int(), std::declval<T>()));
52 Vc_INTRINSIC ElementReference(
const ElementReference &) =
delete;
54 Vc_INTRINSIC
operator value_type() const noexcept(get_noexcept)
56 return Accessor::get(obj, index);
60 Vc_INTRINSIC ElementReference &operator=(T &&x) &&
61 noexcept(noexcept(Accessor::set(std::declval<U &>(),
int(), std::declval<T>())))
63 Accessor::set(obj, index, std::forward<T>(x));
70 template <typename T, typename R = decltype(std::declval<const value_type &>() \ 71 op_ std::declval<T>())> \ 72 Vc_INTRINSIC ElementReference &operator op_##=(T &&x) && \ 73 noexcept(get_noexcept && noexcept(Accessor::set(std::declval<U &>(), int(), \ 74 std::declval<R &&>()))) \ 76 const value_type &lhs = Accessor::get(obj, index); \ 77 Accessor::set(obj, index, lhs op_ std::forward<T>(x)); \ 80 Vc_ALL_ARITHMETICS(Vc_OP_);
81 Vc_ALL_SHIFTS(Vc_OP_);
82 Vc_ALL_BINARY(Vc_OP_);
85 template <
typename =
void>
86 Vc_INTRINSIC ElementReference &operator++() &&
87 noexcept(noexcept(std::declval<value_type &>() =
88 Accessor::get(std::declval<U &>(),
int())) &&
89 set_noexcept<decltype(++std::declval<value_type &>())>())
91 value_type x = Accessor::get(obj, index);
92 Accessor::set(obj, index, ++x);
96 template <
typename =
void>
97 Vc_INTRINSIC value_type operator++(
int) &&
98 noexcept(noexcept(std::declval<value_type &>() =
99 Accessor::get(std::declval<U &>(),
int())) &&
100 set_noexcept<decltype(std::declval<value_type &>()++)>())
102 const value_type r = Accessor::get(obj, index);
104 Accessor::set(obj, index, ++x);
108 template <
typename =
void>
109 Vc_INTRINSIC ElementReference &operator--() &&
110 noexcept(noexcept(std::declval<value_type &>() =
111 Accessor::get(std::declval<U &>(),
int())) &&
112 set_noexcept<decltype(--std::declval<value_type &>())>())
114 value_type x = Accessor::get(obj, index);
115 Accessor::set(obj, index, --x);
119 template <
typename =
void>
120 Vc_INTRINSIC value_type operator--(
int) &&
121 noexcept(noexcept(std::declval<value_type &>() =
122 Accessor::get(std::declval<U &>(),
int())) &&
123 set_noexcept<decltype(std::declval<value_type &>()--)>())
125 const value_type r = Accessor::get(obj, index);
127 Accessor::set(obj, index, --x);
138 #endif // VC_COMMON_ELEMENTREFERENCE_H_