bolts 1.5.0

Utility library for meta programming


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Bolts Meta Programming Utility Library

Latest version Build Status codecov license

Full API docs available here

Bolts is a utility library for the D programming language which contains a number of static reflection utilties that query compile time entities (traits) or transform them (meta). General utilties are in the modules traits and meta, and more specific ones are in dedicated modules (i.e. bolts.members provides utilities over a type's members).

Modules:

  • meta: has functions that result in compile time entity transofrmations, including:
    • TypesOf, Flatten, AliasPack, staticZip, FilterMembersOf
  • traits: has general utitlites that can query compile time entities. including:
    • isFunctionOver, isUnaryOver, isBinaryOver, isProperty, hasProperty, propertySemantics, areCombinable, isManifestAssignable, isOf, isSame, isNullType, StringOf, isRefType, isValueType, isLiteralOf, isLiteral, isCopyConstructable, isNonTriviallyCopyConstructable, protectionLevel, isTriviallyCopyConstructable, hasFunctionMember, areEquatable, isNullSettable, isNullTestable, isRefDecl
  • members: has functions that allow you to query about the members of types
    • staticMembersOf, memberFunctionsOf, member (not eponymous)
  • range: query ranges
    • isSortedRange, sortingPredicate, CommonTypeOfRanges
  • aa: has functions that act on associative arrays
    • isKey (not eponymous)
  • iz: super non-eponymous template that provides a lot of the functionality that's in the traits module with a different sytax that allows their usage in meta functions as well.
  • experimental: contains experimental features
    • signatures: working implementation of type signatures

Most functions here operate on any compile time entity. For example isUnaryOver works in both these situatons:

int i;
void f(int) {}
isFunctionOver!(f, int);
isFunctionOver!(f, 3);
isFunctionOver!(f, i);

Iz super template

The iz super template. Has a lot of the traits on types encapulated in one place. So if there's a trait that tells you something about a compile time entity, chances are iz will have it. E.g:

void f(int, float, string) {}
iz!f.functionOver!(int, float, string);
iz!f.functionOver!(3, float, "");

Member super template

The member super template, found in the bolts.members module is similar to the iz template but works on members of types only:

import bolts.members: member;
struct S {
    static void f() {}
}
assert(member!(S, "f").exists);
assert(member!(S, "f").protection == ProtectionLevel.public_);
assert(!member!(S, "f").isProperty);

Signatures (experimental):

Signatures are a way to enforce types to comply with other types. For example if you are making a range you can ensure your types conform to a range by mixing in an ModelsSignature template to the type that needs it. You can also use the utilities provided here to constrain functions to types that adhere to a specific signature.

struct InputRangeSignature(T) {
    bool empty() { return true; }
    T front() { return T.init; }
    void popFront() {}
}

struct MyRange {
    mixin ModelsSignature!(InputRangeSignature!int);
}

The above will fail to compile with something like:

source/bolts/experimental/signatures.d(225,5): Error: static assert:  "Type R!(int) does not comply to signature InputRange!(int)
    Missing identifier empty of function pure nothrow @nogc @safe bool().
    Missing identifier front of function pure nothrow @nogc @safe int().
    Missing identifier popFront of function pure nothrow @nogc @safe void().
    source/bolts/experimental/signatures.d(364): <-- Signature InputRange!(int) defined here.
    source/bolts/experimental/signatures.d(373): <-- Checked here."
Authors:
  • Ali Akhtarzada
Dependencies:
none
Versions:
1.8.1 2020-Aug-17
1.8.0 2020-Jul-20
1.7.0 2020-Feb-20
1.6.0 2020-Feb-19
1.5.3 2020-Feb-18
Show all 38 versions
Download Stats:
  • 8 downloads today

  • 77 downloads this week

  • 406 downloads this month

  • 52245 downloads total

Score:
3.8
Short URL:
bolts.dub.pm