1 /* This file is part of the Vc library.
3 Copyright (C) 2009-2012 Matthias Kretz <kretz@kde.org>
5 Vc is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of
8 the License, or (at your option) any later version.
10 Vc is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with Vc. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef VC_SCALAR_WRITEMASKEDVECTOR_H
21 #define VC_SCALAR_WRITEMASKEDVECTOR_H
28 template<typename T> class WriteMaskedVector
30 friend class Vector<T>;
31 typedef typename Vector<T>::Mask Mask;
32 typedef typename Vector<T>::EntryType EntryType;
35 inline Vector<T> &operator++() { if (mask) ++vec->m_data; return *vec; }
36 inline Vector<T> &operator--() { if (mask) --vec->m_data; return *vec; }
38 inline Vector<T> operator++(int) { if (mask) vec->m_data++; return *vec; }
39 inline Vector<T> operator--(int) { if (mask) vec->m_data--; return *vec; }
41 inline Vector<T> &operator+=(Vector<T> x) { if (mask) vec->m_data += x.m_data; return *vec; }
42 inline Vector<T> &operator-=(Vector<T> x) { if (mask) vec->m_data -= x.m_data; return *vec; }
43 inline Vector<T> &operator*=(Vector<T> x) { if (mask) vec->m_data *= x.m_data; return *vec; }
44 inline Vector<T> &operator/=(Vector<T> x) { if (mask) vec->m_data /= x.m_data; return *vec; }
46 inline Vector<T> &operator=(Vector<T> x) {
51 inline Vector<T> &operator+=(EntryType x) { if (mask) vec->m_data += x; return *vec; }
52 inline Vector<T> &operator-=(EntryType x) { if (mask) vec->m_data -= x; return *vec; }
53 inline Vector<T> &operator*=(EntryType x) { if (mask) vec->m_data *= x; return *vec; }
54 inline Vector<T> &operator/=(EntryType x) { if (mask) vec->m_data /= x; return *vec; }
56 inline Vector<T> &operator=(EntryType x) {
57 vec->assign(Vector<T>(x), mask);
61 template<typename F> inline void call(const F &f) const {
64 template<typename F> inline void call(F &f) const {
67 template<typename F> inline Vector<T> apply(const F &f) const {
69 return Vector<T>(f(vec->m_data));
74 template<typename F> inline Vector<T> apply(F &f) const {
76 return Vector<T>(f(vec->m_data));
82 WriteMaskedVector(Vector<T> *v, Mask k) : vec(v), mask(k) {}
89 #endif // VC_SCALAR_WRITEMASKEDVECTOR_H