HeadConst library type (was: "headconst" dynamic arrays?)

dsimcha dsimcha at yahoo.com
Wed Aug 31 10:30:56 PDT 2011


Have we considered the obvious library head-const solution?

struct HeadConst(T) {
    T __payload;

    T __get() {
        return __payload;
    }

    alias __get this;
}

HeadConst!T headConst(T)(T stuff) { return typeof(return)(stuff); }

Usage:

auto headConstArray = headConst([1, 2, 3]);

The only problem I see is that you'd get unnecessary copying of structs with
postblits.  IMHO, though, the language spec should be relaxed to allow copying to
be elided due to function inlining.


More information about the Digitalmars-d mailing list