Function backInserter

If container is a container with insertBack-support, backInserter returns an output range that puts the elements into the container with insertBack.

auto backInserter(Container) (
  scope ref return Container container
)
if (hasMember!(Container, "insertBack"));

The resulting output range supports all types insertBack supports.

The range keeps a reference to the container passed to it, it doesn't use any other storage. So there is no method to get the written data out of the range - the container passed to backInserter contains that data and can be used directly after all operations on the output range are completed. It also means that the result range is not allowed to outlive its container.

Parameters

NameDescription
Container Container type.
container Container used as an output range.

Returns

insertBack-based output range.

Example

static struct Container
{
    int element;

    void insertBack(int element)
    {
        this.element = element;
    }
}
Container container;
backInserter(container)(5);

assert(container.element == 5);