◆ if_zero_else()

Value1 boost::simd::if_zero_else ( Value0 const &  c,
Value1 const &  x 
)

This function object conditionally returns 0 (respectively x) if c is True (respectively False)

Header <boost/simd/function/if_zero_else.hpp>
Example:
#include <boost/simd/boolean.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = { 3.0f, -0.0f, -3.0f, 0.0f };
pack_ft qf = { 4.0f, -3.0f, -3.0f, 0.0f };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::if_zero_else(pf, qf) = " << bs::if_zero_else(pf, qf) << '\n';
float xf = 3.0f, yf = 4.0f;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::if_zero_else(xf, yf) = " << bs::if_zero_else(xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, -0, -3, 0)
<- qf = (4, -3, -3, 0)
-> bs::if_zero_else(pf, qf) = (0, -3, 0, 0)
---- scalar
xf = 3
yf = 4
-> bs::if_zero_else(xf, yf) = 0