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);

Modules

experimental
module bolts.experimental

Contains experimental features - these can break *anytime*

from
module bolts.from

Lazy import symbols

iz
module bolts.iz

Iz is is - reason for choosing iz is because is is a keyword. Answers the qustions "is this 'thing' ____ ?"

members
module bolts.members

Provides compile time utilities that can query a type's members

meta
module bolts.meta

Provides meta utilities that can modify types

range
module bolts.range

Static introspection utilties for ranges

traits
module bolts.traits

Provides utilites that allow you to determine type traits

Public Imports

bolts.traits
public import bolts.traits;
bolts.meta
public import bolts.meta;
bolts.range
public import bolts.range;
bolts.members
public import bolts.members;
bolts.iz
public import bolts.iz;
bolts.from
public import bolts.from;
bolts.experimental
public import bolts.experimental;

Detailed Description

Iz Super Template

The $(DDOX_NAMED_REF bolts.iz.iz, `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 $(DDOX_NAMED_REF bolts.members.member, `member`) super template, found in the bolts.members module is similar to the $(DDOX_NAMED_REF bolts.iz.iz, `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

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

Meta