On Thursday, 2 August 2018 at 08:40:55 UTC, John Colvin wrote:
On Thursday, 2 August 2018 at 07:47:19 UTC, aliak wrote:
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
This looks cool. Lots of things that lots of people have
reimplemented lots of times over the years, but all in one
place and documented.
2 points:
1) Are you aware of this:
https://github.com/dlang/phobos/blob/master/std/meta.d ? I
think if a bunch of good motivating examples are given, making
this public would be possible. Then everyone would be using the
same one and your library would truly just be utilities.
woops, pressed send too early:
2) I don't think "doth" is synonymous with "is" how you're using
it. "doth" is for doing, e.g.
"Methinks he doth protest too much" or "This code doth stink" is
OK
"Green doth a colour" or "strstr doth a function" is not OK.