Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute D Online

import std.stdio;
import std.variant;

struct Vec(T, int N)
{
    this (T v)
    {
        elements = v;
    }
    this (T[] v)
    {
        elements = v[0..N];
    }
    
    @property T[] toArray()
    {
        return elements;
    }
    alias toArray this;
    
    T[N] elements;
}

void test()
{
    alias vec4f = Vec!(float, 4);
    
    assert (vec4f(5).elements[3] == 5);
    assert (vec4f([5, 6, 7, 3, 5, 8, 56]).elements[] == [5, 6, 7, 3]);
    //assert (vec4f( vec4f([1, 2, 3, 4]) ).elements[0] == 1);
}

/* Hello World Program in D Programming */
void main(string[ ] args)
{
   writeln(__LINE__);
   test();
   Vec!(float, 4) v;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.