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)
  4. auto makeSlice(Allocator allocator, Slice!(Iterator, N, kind) slice)
    makeSlice
    (
    Allocator
    Iterator
    size_t N
    SliceKind kind
    )
    (
    auto ref Allocator allocator
    ,
    Slice!(Iterator, N, kind) slice
    )

Parameters

slice Slice!(Iterator, N, kind)

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