I want to declare a function, that gets a range as input, outputs a single number and use it directly with ranges::views::transform of the range-v3 library.
The following works but I have to use a lambda that doesn't really do anything.
int64_t getGroupValue( ranges::input_range auto&& group ) {
return ranges::accumulate( group, 1ll, ranges::multiplies() );
}
int64_t calculateGroupSum( const std::vector<int>& data ) {
using ranges::views::transform;
using ranges::views::chunk;
return ranges::accumulate(
data
| chunk( 3 )
| transform( [] ( auto group ) { return getGroupValue( group ); })
, 0ll);
}
I want to do the following:
int64_t calculateGroupSum( const std::vector<int>& data ) {
using ranges::views::transform;
using ranges::views::chunk;
return ranges::accumulate(
data
| chunk( 3 )
| transform( getGroupValue )
, 0ll);
}
Is this somehow possible by using a different parameter type for getGroupValue() or do I have to use the lambda?