◆ transform() [2/2]

template<typename T1 , typename T2 , typename U , typename BinOp >
U* boost::simd::transform ( T1 const *  first1,
T1 const *  last1,
T2 const *  first2,
U *  out,
BinOp const &  f 
)

Applies the given function f to pairs of elements from two ranges: one defined by [first1, last1[ and the other beginning at first2, and stores the result in another Contiguous Range, beginning at out.

Parameters
first1Beginning of the first range of elements to transform
last1End of the range of elements to transform
first2Beginning of the second range of elements to transform
outBeginning of the destination range
funary operation function object that will be applied.
Requirement
  • first, last and out must be pointer to Vectorizable type.
  • f must be a polymorphic binary function object, i.e callable on generic types.
  • boost::simd::pack<T1>::static_size == boost::simd::pack<T> <U>::static_size
  • boost::simd::pack<T2>::static_size == boost::simd::pack<T> <U>::static_size
Example
#include <boost/simd/algorithm/transform.hpp>
#include <iostream>
#include <vector>
struct f
{
template<typename T> T operator()(T const& a, T const& b) const { return b/a; }
};
int main()
{
std::vector<float> d{1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f};
std::vector<float> e{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f};
std::vector<float> out(7);
boost::simd::transform( d.data(), d.data()+7, e.data(), out.data(), f{});
for(auto x : out )
std::cout << x << " ";
return 0;
}
Possible output:
0 0.5 0.666667 0.75 0.8 0.833333 0.857143
Returns
Pointer to the element past the last element transformed.