make

Convenience function for constructing a generic container.

template make(alias Container, Args...)
make
(
Range
)
(
Range range
)
if (
!isDynamicArray!Range &&
isInputRange!Range
&&
!isInfinite!Range
)
if (
!is(Container)
)

Examples

forbid construction from infinite range

import std.container.array : Array;
import std.range : only, repeat;
import std.range.primitives : isInfinite;
static assert(__traits(compiles, { auto arr = make!Array(only(5)); }));
static assert(!__traits(compiles, { auto arr = make!Array(repeat(5)); }));
import std.algorithm.comparison : equal;
import std.container.array, std.container.rbtree, std.container.slist;
import std.range : iota;

auto arr = make!Array(iota(5));
assert(equal(arr[], [0, 1, 2, 3, 4]));

auto rbtmax = make!(RedBlackTree, "a > b")(iota(5));
assert(equal(rbtmax[], [4, 3, 2, 1, 0]));

auto rbtmin = make!RedBlackTree(4, 1, 3, 2);
assert(equal(rbtmin[], [1, 2, 3, 4]));

alias makeList = make!SList;
auto list = makeList(1, 7, 42);
assert(equal(list[], [1, 7, 42]));

Meta