Bolts 0.4 meta programming library

aliak something at something.com
Thu Aug 2 07:47:19 UTC 2018


Hi, just a release of a meta programming library 
(https://bolts.dub.pm) that has utilities that I use in personal 
projects, and that I find in phobos, and or in the forums. A 
notable difference is that functions here try to operate on any 
compile time entities if they can be resolved.

I.e.:

int i;
void g0(int) {}
struct S { void g1(int) {} }
alias g2 = (int a) => a;
static assert(isFunctionOver!(g0, int));
static assert(isFunctionOver!(S.g1, 3));
static assert(isFunctionOver!(g2, i));

And there's a "doth" super template that tries to contain most 
things under what I feel is a nicer api ("is" was taken, so i 
looked to Shakespearian gibberish :p) and also allows for easier 
use with meta functions:

E.g.:

int *pi = null;
static assert( doth!3.of!int);
static assert(!doth!pi.nullable);
static assert( doth!((a, b, c, d) => a).functionOver!(int, int, 
int, int));

int i;
import std.meta: allSatisfy;
static assert(allSatisfy!(doth!int.of, 3, 4, int, i));

Here's an example of a gem adapted from inside the forms/phobos 
sources as well:

alias a = AliasPack!(1, 2, 3);
alias b = AliasPack!(4, 5, 6);
alias c = AliasPack!(7, 8, 9);

alias d = staticZip!(a, b, c);

static assert(d.length == 3);

static assert(d.Unpack[0].equals!(1, 4, 7));
static assert(d.Unpack[1].equals!(2, 5, 8));
static assert(d.Unpack[2].equals!(3, 6, 9))

static assert(AliasPack!(d.UnpackDeep).equals!(1, 4, 7, 2, 5, 8, 
3, 6, 9));

Cheers,
- Ali


More information about the Digitalmars-d-announce mailing list