Using Slices as OutputRange
Explore how to use slices as OutputRange in D programming and understand the implications of their put() operations. Learn about element consumption, length constraints, and how to use std.array.Appender to safely append elements to slices. This lesson helps you properly manage slice output for flexible and efficient data handling.
We'll cover the following...
The std.range module makes slices OutputRange objects as well. In contrast, std.array makes them only input ranges. Unfortunately, using slices as OutputRange objects has a confusing effect: Slices lose an element for each put() operation on them; and that element is the one that has just been displayed!
The reason for this behavior is a consequence of slices’ not having a put() member function. As a result, the third case of the previous table is matched for slices, and the following method ...