vec - multiple declarations

Function vec

Build a Vec whose component type and size is deducted from arguments.

auto vec(Comps...) (
  Comps comps
)
if (Comps.length > 0 && !(Comps.length == 1 && isStaticArray!(Comps[0])));

auto vec(Arr) (
  in Arr arr
)
if (isStaticArray!Arr);

Example

import std.algorithm : equal;
import std.traits : Unqual;

immutable v1 = vec (1, 2, 4.0, 0); // CommonType!(int, double) is double
immutable int[4] arr1 = [1, 2, 4, 0];

static assert( is(Unqual!(typeof(v1)) == DVec4) );

assert(equal(v1.data, arr1[]));

immutable int[3] arr2 = [0, 1, 2];
immutable v2 = vec (arr2);
static assert( is(Unqual!(typeof(v2)) == IVec3) );
assert(equal(v2.data, arr2[]));

Template vec

Build a Vec with specified component type T and size deducted from arguments.

template vec(T) ;

Contained Functions

NameDescription
vec
vec

Example

import std.algorithm : equal;
import std.traits : Unqual;

immutable v1 = dvec (1, 2, 4, 0); // none of the args is double
immutable int[4] arr1 = [1, 2, 4, 0];
static assert( is(Unqual!(typeof(v1)) == DVec4) );
assert(equal(v1.data, arr1[]));

immutable int[3] arr2 = [0, 1, 2];
immutable v2 = fvec(arr2);
static assert( is(Unqual!(typeof(v2)) == FVec3) );
assert(equal(v2.data, arr2[]));

immutable int[4] arr3 = [0, 1, 2, 3];
immutable v3 = dvec (1, 2);
immutable v4 = dvec (0, v3, 3);
static assert( is(Unqual!(typeof(v4)) == DVec4) );
assert(equal(v4.data, arr3[]));

Template vec

Build a Vec with specified size and type deducted from arguments

template vec(ulong N) ;

Contained Functions

NameDescription
vec
vec

Example

import std.algorithm : equal;
import std.array : staticArray;
import std.traits : Unqual;

const double[4] arr1 = [1, 2, 4, 0];
const v1 = vec4 (arr1[]);            // passing slice to erase compile-time length
static assert( is(Unqual!(typeof(v1)) == DVec4) );
assert(equal(v1.data, arr1[]));

const int comp = 2;
const v2 = vec4 (comp);
static assert( is(Unqual!(typeof(v2)) == IVec4) );
assert(equal(v2.data, staticArray([2, 2, 2, 2])[]));