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.