◆ transform() [1/2]

template<typename T , typename U , typename UnOp >
U* boost::simd::transform ( T const *  first,
T const *  last,
U *  out,
UnOp const &  f 

Applies the given function f to the Contiguous Range [first, last[ and stores the result in another Contiguous Range, beginning at out.

firstBeginning of the range of elements to transform
lastEnd of the range of elements to transform
outBeginning of the destination range
funary operation function object that will be applied.
  • first, last and out must be pointer to Vectorizable type.
  • f must be a polymorphic unary function object, i.e callable on generic types.
  • boost::simd::pack<T>::static_size == boost::simd::pack<U>::static_size

The following code uses simd::transform to compute the square of the values stored in a std::vector.

#include <boost/simd/algorithm/transform.hpp>
#include <boost/simd/function/sqr.hpp>
#include <iostream>
#include <vector>
int main()
std::vector<float> d{1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f};
boost::simd::transform( d.data(), d.data()+7, d.data(), boost::simd::sqr );
for(auto e : d )
std::cout << e << " ";
return 0;

Expected output:

1 4 9 16 25 36 49
Pointer to the element past the last element transformed.