On Saturday, 1 November 2014 at 06:04:56 UTC, Jakob Ovrum wrote:
On Saturday, 1 November 2014 at 05:27:16 UTC, Jonathan Marler
wrote:
No need for the extra function, just call:
x.toString(&(outputRange.put));
That doesn't work for a wide variety of possible cases, notably
when `put` is a function template or when the code depends on
std.range.put or some other UFCS `put` function. As such, it
should be avoided in generic code, and then you might as well
avoid it in general, lest your algorithm unnecessarily ends up
breaking with output ranges you didn't test for after
refactoring.
(Note that parantheses are not required in your example)
Ah yes, you are right that this wouldn't work in generic code.
Meaning, if the code calling toString was itself a template
accepting output ranges, then many times the &outputRange.put
wouldn't work. In this case I think the anonymous function is a
good way to go. I was more thinking of the case where the code
calling toString was user code where the outputRange was a known
type. Thanks for catching my silly assumption.