Skip to main content
deleted 2 characters in body
Source Link
G. Sliepen
  • 61.7k
  • 3
  • 61
  • 152

It can reduce more than just strings

Your code is now very generic. In fact, there is nothing in the code referring to strings of any kind. For example, you can sum a vector of integers with it:

std::vector<int> int_vector = {1, 2, 3, 4, 5};
std::cout << recursive_reduce_string<0>(int_vector) << '\n';

So you basically reimplemented your own recursive_reduce() with unwrap level, except instead of saying how many levels to unwrap, now the template parameter says how many levels to leave unwrappedwrapped.

You should either rename this new function such that it doesn't mention strings anymore, and makes it clear that the parameter is how many levels to leave unwrapped, or alternatively, consider merging this into recursive_reduce(), and maybe use negative values of the template parameter to get the new behavior?

It can reduce more than just strings

Your code is now very generic. In fact, there is nothing in the code referring to strings of any kind. For example, you can sum a vector of integers with it:

std::vector<int> int_vector = {1, 2, 3, 4, 5};
std::cout << recursive_reduce_string<0>(int_vector) << '\n';

So you basically reimplemented your own recursive_reduce() with unwrap level, except instead of saying how many levels to unwrap, now the template parameter says how many levels to leave unwrapped.

You should either rename this new function such that it doesn't mention strings anymore, and makes it clear that the parameter is how many levels to leave unwrapped, or alternatively, consider merging this into recursive_reduce(), and maybe use negative values of the template parameter to get the new behavior?

It can reduce more than just strings

Your code is now very generic. In fact, there is nothing in the code referring to strings of any kind. For example, you can sum a vector of integers with it:

std::vector<int> int_vector = {1, 2, 3, 4, 5};
std::cout << recursive_reduce_string<0>(int_vector) << '\n';

So you basically reimplemented your own recursive_reduce() with unwrap level, except instead of saying how many levels to unwrap, now the template parameter says how many levels to leave wrapped.

You should either rename this new function such that it doesn't mention strings anymore, and makes it clear that the parameter is how many levels to leave unwrapped, or alternatively, consider merging this into recursive_reduce(), and maybe use negative values of the template parameter to get the new behavior?

Source Link
G. Sliepen
  • 61.7k
  • 3
  • 61
  • 152

It can reduce more than just strings

Your code is now very generic. In fact, there is nothing in the code referring to strings of any kind. For example, you can sum a vector of integers with it:

std::vector<int> int_vector = {1, 2, 3, 4, 5};
std::cout << recursive_reduce_string<0>(int_vector) << '\n';

So you basically reimplemented your own recursive_reduce() with unwrap level, except instead of saying how many levels to unwrap, now the template parameter says how many levels to leave unwrapped.

You should either rename this new function such that it doesn't mention strings anymore, and makes it clear that the parameter is how many levels to leave unwrapped, or alternatively, consider merging this into recursive_reduce(), and maybe use negative values of the template parameter to get the new behavior?