Module bolts

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 most specific ones are in dedicated modules (i.e. bolts.members provides utilities over a type's members).

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.unaryOver!(int, float, string);
iz!f.unaryOver!(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 a Models 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.

interface InputRange(T) {
    @property bool empty();
    @property T front();
    @ignoreAttributes void popFront();
}

struct MyRange {
    mixin Models!(InputRange!int);
}

The above will fail to compile with something like:

source/bolts/experimental/signatures.d(310,5): Error: static assert:  "Type MyRange does not comply to signature InputRange!(int)
  Missing identifier empty of type bool.
  Missing identifier front of type int.
  Missing identifier popFront of function void().
  source/bolts/experimental/signatures.d(464): <-- Signature InputRange!(int) defined here.
  source/bolts/experimental/signatures.d(471): <-- Checked here."

Refraction_(experimental):

It is sometimes necessary to create a function which is an exact copy of another function. Or sometimes it is necessary to introduce a few variations, while carrying all the other aspects. Because of function attributes, parameter storage classes and user-defined attributes, this requires building a string mixin. In addition, the mixed-in code must refer only to local names, if it is to work across module boundaires. This module facilitates the creation of such mixins.

For example, this creates a function that has a different name and return type, but retains the 'pure' attribute from the original function:

pure int answer() { return 42; }
mixin(
  refract!(answer, "answer").withName("realAnswer")
  .withReturnType("real")
  .mixture);
static assert(is(typeof(realAnswer()) == real));
static assert(functionAttributes!realAnswer & FunctionAttribute.pure_);

All the things

Module Function Description
bolts.from from lazy import of symbols
bolts.members memberFunctionsOf Returns a list of all member functions
staticMembersOf Returns a list of of all static members
member If a type has a member with certain attributes
Flatten Takes a list of ranges and non ranges and returns a list of types of the ranges and types of the non ranges
AliasPack Represents an AliasSeq that is not auto expanded
Zip Zip m n-tuple AliasPacks together to form n m-tuple AliasPacks
Pluck Extract AliasPack elements at positions
FilterMembersOf Filters the members of a type based on a has-predicate
RemoveAttributes Removes all the attributes of a symbol and returns the new type
bolts.range isSortedRange Tells you if a range is sorted
sortingPredicate Can be used to extract the sorting predicate for a range
CommonTypeOfRanges Finds the common type from a list of ranges
bolts.iz iz Allows you to query a type or alias with a nicer syntax, i.e. isNullSettable!T == iz!T.nullSettable
bolts.experimental.signatures isModelOf Allows you to check if a structure models another structure - i.e. enforces duck typing
Models Mixin that throws a compile error if a structure does not match another
bolts.experimental.refraction refract Returns a compile time object that helps create a string mixin corresponding to a function, possibly with variations
bolts.traits isFunctionOver Checks if a function is n-ary over the passed in types
isUnaryOver Checks if a function is unary over some type
isBinaryOver Checks if a function is binary over some types
TypesOf Returns an AliasSeq of the types of all values given - values can be types or expressions
areCombinable Checks if a set of ranges and non ranges share a common type
isProperty Tells you if a symbol is an @property
hasProperty Tells you if a name is a member and property in a type
propertySemantics Tells you if a property symbol has read and/or write semantics
protectionLevel Returns the protection level for a symbol
isManifestAssignable If a member of a type can be assigned to a manifest constant
isOf Is the resolved type is of another resolved type
isNullType If T is typeof(null)
StringOf Stringifies a type, unlike .stringof this version doesn't spit out mangled gibberish
isSame Returns true if a and b are the same thing - same type, same literal value, or same symbol
isRefType Checks if a compile time entity is a reference type
isLiteralOf Checks if a compile time entity is a litera of a specific type
isLiteral Checks if a compile time entity is a literal
isCopyConstructable Checks if a compile time entity is copy constructable
isNonTriviallyCopyConstructable Checks if a compile time entity is non-trivially (i.e. user defined) copy constructable
isTriviallyCopyConstructable Checks if a compile time entity is trivially copy constructable
hasFunctionMember Checks if a type has a member that is a function
isValueType Checks if a compile time entity is a value type
areEquatable Returns true if two things are equatable
isNullSettable Check if a thing can be set to null
isNullTestable Check if a thing can be checked to be null - i.e. if (thing is null)
isRefDecl See if a thing is declared as ref, or function returns by ref