Skip to main content
Add related link
Source Link
JimmyHu
  • 7.6k
  • 2
  • 11
  • 48

You may want to add a variant that omits the initial value, and instead uses the result of calling the fold function on the final two elements as the initial value, similar to the existing std::ranges::fold_right_laststd::ranges::fold_right_last.

You may want to add a variant that omits the initial value, and instead uses the result of calling the fold function on the final two elements as the initial value, similar to the existing std::ranges::fold_right_last.

You may want to add a variant that omits the initial value, and instead uses the result of calling the fold function on the final two elements as the initial value, similar to the existing std::ranges::fold_right_last.

added 354 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39

You tagged this , then did not constrain your templatesbut the only constraint is whether a parameter named T is an input range (when it in fact needs to be a bidirectional range). I recommend a more-descriptive name than T, and constraints for the properties that the algorithm uses (if for no other reason, so overloads can have the same number of arguments and the compiler gives a useful error message if it can’t figure out which to call).

You tagged this , then did not constrain your templates.

You tagged this , but the only constraint is whether a parameter named T is an input range (when it in fact needs to be a bidirectional range). I recommend a more-descriptive name than T, and constraints for the properties that the algorithm uses (if for no other reason, so overloads can have the same number of arguments and the compiler gives a useful error message if it can’t figure out which to call).

added 329 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39

I would question whether adding a proj function is worth it. The intended use seems to be to convert the return type to the input type of the recursive function, if different, and it defaults to an identity function. A If the intent is to convert between an output and an input type, you might write a converting constructor or conversion operator. A more complicated arbitrary transformation could be incorporated intodone as part of the recursive function. Eliminating this Or if the intermediate values used in computation are a different type than you want for the final result, you could apply the transformation function once to the return value. Replacing proj with a static_cast means you no longer need the complicated State template struct, and you can simplify the unfolding version to just take an invokable whose inputs and outputs are properly convertible.

I would question whether adding a proj function is worth it. The intended use seems to be to convert the return type to the input type of the recursive function, if different, and it defaults to an identity function. A more complicated arbitrary transformation could be incorporated into the recursive function. Eliminating this means you no longer need the complicated State template struct, and you can simplify the unfolding version to just take an invokable whose inputs and outputs are properly convertible.

I would question whether adding a proj function is worth it. The intended use seems to be to convert the return type to the input type of the recursive function, if different, and it defaults to an identity function. If the intent is to convert between an output and an input type, you might write a converting constructor or conversion operator. A more complicated arbitrary transformation could be done as part of the recursive function. Or if the intermediate values used in computation are a different type than you want for the final result, you could apply the transformation function once to the return value. Replacing proj with a static_cast means you no longer need the complicated State template struct, and you can simplify the unfolding version to just take an invokable whose inputs and outputs are properly convertible.

added 1448 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 1448 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
edited body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 206 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 3 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 2 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 99 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
deleted 205 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 27 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
added 27 characters in body
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading
Source Link
Davislor
  • 9.2k
  • 19
  • 39
Loading