ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
iif.h
Go to the documentation of this file.
1 /* This file is part of the Vc library. {{{
2 
3  Copyright (C) 2012 Matthias Kretz <kretz@kde.org>
4 
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.
9 
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.
14 
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/>.
17 
18 }}}*/
19 
20 #ifndef VC_COMMON_IIF_H
21 #define VC_COMMON_IIF_H
22 
23 #include "macros.h"
24 
25 namespace ROOT {
26 namespace Vc
27 {
28 /**
29  * Function to mimic the ternary operator '?:'.
30  *
31  * \param condition Determines which values are returned. This is analog to the first argument to
32  * the ternary operator.
33  * \param trueValue The values to return where \p condition is \c true.
34  * \param falseValue The values to return where \p condition is \c false.
35  * \return A combination of entries from \p trueValue and \p falseValue, according to \p condition.
36  *
37  * So instead of the scalar variant
38  * \code
39  * float x = a > 1.f ? b : b + c;
40  * \endcode
41  * you'd write
42  * \code
43  * float_v x = Vc::iif (a > 1.f, b, b + c);
44  * \endcode
45  */
46 #ifndef VC_MSVC
47 template<typename T> static Vc_ALWAYS_INLINE Vector<T> iif (typename Vector<T>::Mask condition, Vector<T> trueValue, Vector<T> falseValue)
48 {
49 #else
50 template<typename T> static Vc_ALWAYS_INLINE Vector<T> iif (const typename Vector<T>::Mask &condition, const Vector<T> &trueValue, const Vector<T> &_falseValue)
51 {
52  Vector<T> falseValue(_falseValue);
53 #endif
54  falseValue(condition) = trueValue;
55  return falseValue;
56 }
57 } // namespace Vc
58 } // namespace ROOT
59 
60 #include "undomacros.h"
61 
62 #endif // VC_COMMON_IIF_H
static Vc_ALWAYS_INLINE Vector< T > iif(typename Vector< T >::Mask condition, Vector< T > trueValue, Vector< T > falseValue)
Function to mimic the ternary operator '?:'.
Definition: iif.h:47
#define Vc_ALWAYS_INLINE
Definition: macros.h:130