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.

  1. auto makeSlice(Allocator alloc, Slice!(N, Iterator) slice)
  2. Slice!(T*, N) makeSlice(Allocator alloc, size_t[N] lengths)
  3. Slice!(T*, N) makeSlice(Allocator alloc, size_t[N] lengths, T init)
    Slice!(T*, N)
    makeSlice
    (
    T
    Allocator
    size_t N
    )
    (
    auto ref Allocator alloc
    ,
    size_t[N] lengths
    ,)
  4. auto makeSlice(Allocator allocator, Slice!(Iterator, N, kind) slice)

Parameters

alloc Allocator

allocator

lengths size_t[N]

list of lengths for each dimension

init T

default value for array initialization

Return Value

Type: Slice!(T*, N)

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