◆ if_one_else_zero()

Value boost::simd::if_one_else_zero ( Value const &  c)

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

Header <boost/simd/function/if_one_else_zero.hpp>
Example:
#include <boost/simd/boolean.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/constant/valmax.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.0 };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " -> bs::if_one_else_zero(pf) = " << bs::if_one_else_zero(pf) << '\n';
std::int32_t xf = 3, yf = 0;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::if_one_else_zero(xf) = " << bs::if_one_else_zero(xf) << '\n'
<< " -> bs::if_one_else_zero(yf) = " << bs::if_one_else_zero(yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, 0, -3, -0)
-> bs::if_one_else_zero(pf) = (1, 0, 1, 0)
---- scalar
xf = 3
yf = 0