The OpenD Programming Language

makeSlice

Allocates an array through a specified allocator and creates an n-dimensional slice over it. See also std.experimental.allocator.

Parameters

alloc Allocator

allocator

slice Slice!(N, Iterator)

slice to copy shape and data from

Return Value

Type: auto

a structure with fields array and slice Note: makeSlice always returns slice with mutable elements

Examples

Initialization with default value

import std.experimental.allocator;
import std.experimental.allocator.mallocator;
import mir.algorithm.iteration: all;
import mir.ndslice.topology: map;

auto sl = Mallocator.instance.makeSlice([2, 3, 4], 10);
auto ar = sl.field;
assert(sl.all!"a == 10");

auto sl2 = Mallocator.instance.makeSlice(sl.map!"a * 2");
auto ar2 = sl2.field;
assert(sl2.all!"a == 20");

Mallocator.instance.dispose(ar);
Mallocator.instance.dispose(ar2);

Meta