E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ transform_copy_if

auto eve::algo::transform_copy_if = function_with_traits<detail::transform_copy_if_>
inlineconstexpr

#include <eve/module/algo/algo/transform_copy_if.hpp>

Defined in header

#include <eve/module/algo.hpp>
Note
If the scalar operation is cheap enough, copy_if + views::map might be slightly faster.
For an in-place version, see transform_keep_if.

Conditionally copies values from an input range to an output range, transforming them in the process.

If the output range is too small, fills all the available space and then stops.

If the output range's element type is different from the type of the values returned by the transforming function, performs the appropriate conversions.

Callable Signatures

namespace eve::algo
{
template <eve::algo::relaxed_range In, eve::algo::relaxed_range Out, typename Func>
auto transform_copy_if(In&& in, Out&& out, Func func) const -> unaligned_iterator_t<Out>
}
unaligned_t< iterator_t< R > > unaligned_iterator_t
Unaligned iterator for a relaxed range.
Definition ranges_types.hpp:68
constexpr auto transform_copy_if
Similar to applying eve::transform_to and eve::copy_if at the same time.
Definition transform_copy_if.hpp:155

Parameters

  • in: Input range
  • out: Output range
  • func: Function that takes elements from in as SIMD registers and returns a pair of:
    • the transformed values
    • a logical mask.

Return value

Output iterator past the last written element.

Example

#include <eve/module/core.hpp>
#include <eve/module/algo.hpp>
#include <tts/tts.hpp>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> input(16);
eve::algo::iota(input, 0);
std::cout << "Input vector:\n " << tts::as_string(input) << "\n\n";
auto func = [](eve::like<int> auto x) {
return kumi::make_tuple(-x, eve::is_even(x));
};
std::vector<int> output_big(42);
output_big.erase(eve::algo::transform_copy_if(input, output_big, func), output_big.end());
std::cout << "Output (opposites of even numbers):\n "
<< tts::as_string(output_big)
<< "\n\n";
std::vector<unsigned char> output_small(5);
output_small.erase(eve::algo::transform_copy_if(input, output_small, func), output_small.end());
std::cout << "Output on a range too small to hold all the results,\nwith conversion to unsigned char:\n "
<< tts::as_string(output_small)
<< std::endl;
return 0;
}
Specifies semantic compatibility between wrapper/wrapped types.
Definition product_type.hpp:107
constexpr auto iota
SIMD version of std::iota For conversion/overflow behaviour, should follow the standard.
Definition iota.hpp:38
constexpr auto is_even
elementwise callable returning a logical true if and only if the element value is even.
Definition is_even.hpp:78
See also
keep_if
copy_if
remove_if
transform_keep_if
transform_to
views::map