Function singleton

Creates a bidirectional and random-access range with the single element element.

auto singleton(E) (
  return E element
)
if (isMutable!E);

auto singleton(E) (
  ref return E element
);

If element is passed by value the resulting range stores it internally. If element is passed by reference, the resulting range keeps only a pointer to the element.

Parameters

NameDescription
E Element type.
element Element.

Returns

A range with one element.

Example

auto singleChar = singleton('a');

assert(singleChar.length == 1);
assert(singleChar.front == 'a');

singleChar.popFront();
assert(singleChar.empty);