28 #ifndef VC_COMMON_WHERE_H_ 29 #define VC_COMMON_WHERE_H_ 34 namespace Vc_VERSIONED_NAMESPACE
44 template<
typename _Mask,
typename _LValue>
struct MaskedLValue
47 typedef _LValue LValue;
53 constexpr MaskedLValue(
const Mask &m, LValue &l) : mask(m), lhs(l) {}
54 MaskedLValue(
const MaskedLValue &) =
delete;
55 #ifndef __cpp_guaranteed_copy_elision 56 constexpr MaskedLValue(MaskedLValue &&) =
default;
63 template<
typename T> Vc_ALWAYS_INLINE
void operator =(T &&rhs) { conditional_assign<Operator:: Assign>(lhs, mask, std::forward<T>(rhs)); }
64 template<
typename T> Vc_ALWAYS_INLINE
void operator +=(T &&rhs) { conditional_assign<Operator:: PlusAssign>(lhs, mask, std::forward<T>(rhs)); }
65 template<
typename T> Vc_ALWAYS_INLINE
void operator -=(T &&rhs) { conditional_assign<Operator:: MinusAssign>(lhs, mask, std::forward<T>(rhs)); }
66 template<
typename T> Vc_ALWAYS_INLINE
void operator *=(T &&rhs) { conditional_assign<Operator:: MultiplyAssign>(lhs, mask, std::forward<T>(rhs)); }
67 template<
typename T> Vc_ALWAYS_INLINE
void operator /=(T &&rhs) { conditional_assign<Operator:: DivideAssign>(lhs, mask, std::forward<T>(rhs)); }
68 template<
typename T> Vc_ALWAYS_INLINE
void operator %=(T &&rhs) { conditional_assign<Operator:: RemainderAssign>(lhs, mask, std::forward<T>(rhs)); }
69 template<
typename T> Vc_ALWAYS_INLINE
void operator ^=(T &&rhs) { conditional_assign<Operator:: XorAssign>(lhs, mask, std::forward<T>(rhs)); }
70 template<
typename T> Vc_ALWAYS_INLINE
void operator &=(T &&rhs) { conditional_assign<Operator:: AndAssign>(lhs, mask, std::forward<T>(rhs)); }
71 template<
typename T> Vc_ALWAYS_INLINE
void operator |=(T &&rhs) { conditional_assign<Operator:: OrAssign>(lhs, mask, std::forward<T>(rhs)); }
72 template<
typename T> Vc_ALWAYS_INLINE
void operator<<=(T &&rhs) { conditional_assign<Operator:: LeftShiftAssign>(lhs, mask, std::forward<T>(rhs)); }
73 template<
typename T> Vc_ALWAYS_INLINE
void operator>>=(T &&rhs) { conditional_assign<Operator::RightShiftAssign>(lhs, mask, std::forward<T>(rhs)); }
74 Vc_ALWAYS_INLINE
void operator++() { conditional_assign<Operator:: PreIncrement>(lhs, mask); }
75 Vc_ALWAYS_INLINE
void operator++(
int) { conditional_assign<Operator::PostIncrement>(lhs, mask); }
76 Vc_ALWAYS_INLINE
void operator--() { conditional_assign<Operator:: PreDecrement>(lhs, mask); }
77 Vc_ALWAYS_INLINE
void operator--(
int) { conditional_assign<Operator::PostDecrement>(lhs, mask); }
80 template <
class T,
class IV,
class S>
81 Vc_INTRINSIC
void operator=(Common::SubscriptOperation<T, IV, S, true> &&rhs)
83 lhs.gather(std::move(rhs).gatherArguments(), mask);
85 template <
class T,
class IV,
class S>
86 void operator+=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
87 template <
class T,
class IV,
class S>
88 void operator-=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
89 template <
class T,
class IV,
class S>
90 void operator*=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
91 template <
class T,
class IV,
class S>
92 void operator/=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
93 template <
class T,
class IV,
class S>
94 void operator%=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
95 template <
class T,
class IV,
class S>
96 void operator^=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
97 template <
class T,
class IV,
class S>
98 void operator&=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
99 template <
class T,
class IV,
class S>
100 void operator|=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
101 template <
class T,
class IV,
class S>
102 void operator<<=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
103 template <
class T,
class IV,
class S>
104 void operator>>=(Common::SubscriptOperation<T, IV, S, true> &&rhs) =
delete;
107 template <
typename _Mask,
typename T_,
typename I_,
typename S_>
108 struct MaskedLValue<_Mask, Common::SubscriptOperation<T_, I_, S_, true>>
111 typedef Common::SubscriptOperation<T_, I_, S_, true> SO;
116 template <
typename T>
using Decay =
typename std::decay<T>::type;
119 constexpr MaskedLValue(
const Mask &m, SO &&l) : mask(m), lhs(l) {}
120 MaskedLValue(
const MaskedLValue &) =
delete;
121 #ifndef __cpp_guaranteed_copy_elision 122 constexpr MaskedLValue(MaskedLValue &&) =
default;
129 template <
class T> Vc_ALWAYS_INLINE
void operator=(T &&rhs) &&
131 std::forward<T>(rhs).scatter(std::move(lhs).scatterArguments(), mask);
157 template<
typename _LValue>
struct MaskedLValue<bool, _LValue>
160 typedef _LValue LValue;
166 constexpr MaskedLValue(
const Mask &m, LValue &l) : mask(m), lhs(l) {}
167 MaskedLValue(
const MaskedLValue &) =
delete;
168 constexpr MaskedLValue(MaskedLValue &&) =
default;
170 template<
typename T> Vc_ALWAYS_INLINE
void operator =(T &&rhs) {
if (mask) lhs = std::forward<T>(rhs); }
171 template<
typename T> Vc_ALWAYS_INLINE
void operator +=(T &&rhs) {
if (mask) lhs += std::forward<T>(rhs); }
172 template<
typename T> Vc_ALWAYS_INLINE
void operator -=(T &&rhs) {
if (mask) lhs -= std::forward<T>(rhs); }
173 template<
typename T> Vc_ALWAYS_INLINE
void operator *=(T &&rhs) {
if (mask) lhs *= std::forward<T>(rhs); }
174 template<
typename T> Vc_ALWAYS_INLINE
void operator /=(T &&rhs) {
if (mask) lhs /= std::forward<T>(rhs); }
175 template<
typename T> Vc_ALWAYS_INLINE
void operator %=(T &&rhs) {
if (mask) lhs %= std::forward<T>(rhs); }
176 template<
typename T> Vc_ALWAYS_INLINE
void operator ^=(T &&rhs) {
if (mask) lhs ^= std::forward<T>(rhs); }
177 template<
typename T> Vc_ALWAYS_INLINE
void operator &=(T &&rhs) {
if (mask) lhs &= std::forward<T>(rhs); }
178 template<
typename T> Vc_ALWAYS_INLINE
void operator |=(T &&rhs) {
if (mask) lhs |= std::forward<T>(rhs); }
179 template<
typename T> Vc_ALWAYS_INLINE
void operator<<=(T &&rhs) {
if (mask) lhs <<= std::forward<T>(rhs); }
180 template<
typename T> Vc_ALWAYS_INLINE
void operator>>=(T &&rhs) {
if (mask) lhs >>= std::forward<T>(rhs); }
181 Vc_ALWAYS_INLINE
void operator++() {
if (mask) ++lhs; }
182 Vc_ALWAYS_INLINE
void operator++(
int) {
if (mask) lhs++; }
183 Vc_ALWAYS_INLINE
void operator--() {
if (mask) --lhs; }
184 Vc_ALWAYS_INLINE
void operator--(
int) {
if (mask) lhs--; }
187 template<
typename _Mask>
struct WhereMask
193 constexpr WhereMask(
const Mask &m) : mask(m) {}
194 WhereMask(
const WhereMask &) =
delete;
196 template <
typename T,
typename I,
typename S>
197 constexpr Vc_WARN_UNUSED_RESULT
198 MaskedLValue<Mask, Common::SubscriptOperation<T, I, S, true>>
199 operator|(Common::SubscriptOperation<T, I, S, true> &&lhs)
const 201 static_assert(!std::is_const<T>::value,
202 "masked scatter to constant memory not possible.");
203 return {mask, std::move(lhs)};
206 template<
typename T> constexpr Vc_WARN_UNUSED_RESULT MaskedLValue<Mask, T>
operator|(T &&lhs)
const 208 static_assert(std::is_lvalue_reference<T>::value,
"Syntax error: Incorrect use of Vc::where. Maybe operator precedence got you by surprise. Examples of correct usage:\n" 209 " Vc::where(x < 2) | x += 1;\n" 210 " (Vc::where(x < 2) | x)++;\n" 211 " Vc::where(x < 2)(x) += 1;\n" 212 " Vc::where(x < 2)(x)++;\n" 214 return { mask, lhs };
218 class = decltype(std::declval<T>() = std::declval<const T &>())>
219 constexpr Vc_WARN_UNUSED_RESULT MaskedLValue<Mask, T> operator()(T &&lhs)
const 265 template<
typename M> constexpr Vc_WARN_UNUSED_RESULT WhereImpl::WhereMask<M>
where(
const M &mask)
270 template <
class M,
class V>
271 constexpr Vc_WARN_UNUSED_RESULT WhereImpl::MaskedLValue<M, V>
where(
const M &mask,
274 return {mask, value};
279 template <
class M,
class T,
class IT,
class Scale>
280 constexpr Vc_WARN_UNUSED_RESULT
281 WhereImpl::MaskedLValue<M, Common::SubscriptOperation<T, IT, Scale, true>>
282 where(
const M &mask, Common::SubscriptOperation<T, IT, Scale, true> &&value)
284 return {mask, std::move(value)};
287 template<
typename M> constexpr Vc_WARN_UNUSED_RESULT WhereImpl::WhereMask<M> _if(
const M &m)
294 #endif // VC_COMMON_WHERE_H_ result_vector_type< L, R > operator|(L &&lhs, R &&rhs)
Applies | component-wise and concurrently.
constexpr WhereImpl::WhereMask< M > where(const M &mask)
Conditional assignment.