◆ replace()

template<typename T >
void boost::simd::replace ( T *  first,
T *  last,
T const &  old_val,
T const &  new_val 
)

Replaces all elements that are equal to old_value with new_value in the range [first, last).

Parameters
firstBeginning of the range of elements
lastEnd of the range of elements
old_valValue to be replaced
new_valValue to replace with
Requirement
  • first, last and out must be pointer to Vectorizable type.
  • new_val and old_val must be a scalar values convertible to pointee type of first.
Example:
#include <boost/simd/algorithm/replace.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
#include <vector>
namespace bs = boost::simd;
int main()
{
namespace bs = boost::simd;
std::vector<float> d{2.0f, 2.5f, 4.0f, 3.5f, 4.0f, 4.0f, 5.0f, 4.0f};
d[7] = 42.0f;
bs::replace( d.data(),d.data()+7, 4.0f, 0.0f);
std::cout << "d = (" ;
for( auto e : d) std::cout << e << " ";
std::cout << ") " << std::endl;
std::vector<float> d1{4.0f, 2.5f, 4.0f, 3.5f, 4.0f, 4.0f, 5.0f, 4.0f};
bs::replace( d1.data()+1,d1.data()+8, 4.0f, 0.0f);
std::cout << "d1 = (" ;
for( auto e : d1) std::cout << e << " ";
std::cout << ") " << std::endl;
return 0;
}
possible output:
d = (2 2.5 0 3.5 0 0 5 42 )
d1 = (4 2.5 0 3.5 0 0 5 0 )