ae.utils.meta

Metaprogramming

Modules

args
module ae.utils.meta.args

Named method and struct literal arguments

binding
module ae.utils.meta.binding

Method binding - using alias inference patch Currently dysfunctional.

binding_v1
module ae.utils.meta.binding_v1

Method binding - before alias inference

caps
module ae.utils.meta.caps

Compiler capability detection

chain
module ae.utils.meta.chain
Undocumented in source.
misc
module ae.utils.meta.misc
Undocumented in source.
proxy
module ae.utils.meta.proxy

Proxy objects

rcclass
module ae.utils.meta.rcclass

Basic reference-counting for classes.

reference
module ae.utils.meta.reference

Reference type abstraction

tuplerange
module ae.utils.meta.tuplerange

Tuple ranges

x
module ae.utils.meta.x

An implementation of Timon Gehr's X template

Public Imports

ae.utils.meta.reference
public import ae.utils.meta.reference;
Undocumented in source.
ae.utils.meta.x
public import ae.utils.meta.x;
Undocumented in source.
ae.utils.meta.proxy
public import ae.utils.meta.proxy;
Undocumented in source.
ae.utils.meta.binding_v1
public import ae.utils.meta.binding_v1;
Undocumented in source.
ae.utils.meta.binding
public import ae.utils.meta.binding;
Undocumented in source.

Members

Aliases

ArrayToTuple
deprecated alias ArrayToTuple = arrayToTuple
Undocumented in source.
BoxedVoid
alias BoxedVoid = BoxedVoidElement[0]

What to use instead of void for boxVoid/unboxVoid. Use a zero-length array instead of an empty struct as this one has a .sizeof of 0, unlike the struct.

EnumLength
deprecated alias EnumLength = enumLength
Undocumented in source.
ExpandNumericType
alias ExpandNumericType(T, uint additionalBits) = ResizeNumericType!(T, valueBits!T + additionalBits)

Expand to a built-in numeric type of the same kind (signed integer / unsigned integer / floating-point) with at least additionalBits more bits of precision.

GenerateContructorProxies
deprecated alias GenerateContructorProxies = GenerateConstructorProxies
Undocumented in source.
HAVE_UDA
deprecated alias HAVE_UDA = haveUDA
Undocumented in source.
I
alias I(alias A) = A

Shorter synonym for std.traits.Identity. Can be used to UFCS-chain static methods and nested functions.

IsDebug
deprecated alias IsDebug = isDebug
Undocumented in source.
RangeTuple
deprecated alias RangeTuple = rangeTuple
Undocumented in source.
ValueTuple
deprecated alias ValueTuple = valueTuple
Undocumented in source.
isHomogenous
deprecated alias isHomogenous = isHomogeneous
Undocumented in source.

Functions

and
CommonType!Args and(Args args)

Lazily evaluate and return first false-ish result; otherwise return last result.

boxVoid
BoxVoid!T boxVoid(T expr)

D does not allow void variables or parameters. As such, there is no "common type" for functions that return void and non-void. To allow generic metaprogramming in such cases, this function will "box" a void expression to a different type.

classInit
immutable(T) classInit()

Returns the class's initializer instance. Returns null if all class fields are zero. Can be used to get the value of class fields' initial values.

has
auto has(E e)

Convenience facility for manipulating bitfield enums.

has
auto has(E e)
Undocumented in source. Be warned that the author may not have intended to support it.
identity
T identity(T value)

Identity function.

or
CommonType!Args or(Args args)

Lazily evaluate and return first true-ish result; otherwise return last result.

prog1
Args[0] prog1(Args args)

Like progn, but return the first argument instead.

progn
Args[$ - 1] progn(Args args)

Evaluate all arguments and return the last argument. Can be used instead of the comma operator. Inspired by http://clhs.lisp.se/Body/s_progn.htm

tupleMap
auto tupleMap(Values values)

Maps values with a predicate, returning a std.typecons tuple.

unboxVoid
auto unboxVoid(T value)

Inverse of boxVoid. Can be used in a return statement, i.e.: return unboxVoid(someBoxedVoid);

voidStruct
auto voidStruct(T value)

As boxVoid/unboxVoid, but returns a struct with zero or one members. .tupleof can then be used to paste the tuple in e.g. an argument list.

Manifest constants

isDebug
enum isDebug;
Undocumented in source.
isDebug
enum isDebug;
Undocumented in source.

Mixin templates

FieldList
mixintemplate FieldList(Fields...)

Like std.typecons.Tuple, but a template mixin. Unlike std.typecons.Tuple, names may not be omitted - but repeating types may be.

GenerateConstructorProxies
mixintemplate GenerateConstructorProxies()

Generate constructors that simply call the parent class constructors. Based on http://forum.dlang.org/post/i3hpj0$2vc6$1@digitalmars.com

Properties

enumIota
auto enumIota [@property getter]

A range that iterates over all members of an enum.

isHomogeneous
bool isHomogeneous [@property getter]

Return true if all of T's fields are the same type.

singleton
T singleton [@property getter]

Generate a @property function which creates/returns a thread-local singleton of a class with the given arguments.

singleton
singleton [@property getter]

As above, but using arbitrary types and a factory function.

structFields
string[] structFields [@property getter]

Evaluates to array of strings with name for each field.

Static functions

findParameter
size_t findParameter()
size_t findParameter(string[] searchedNames, string soughtNames, string funName)

Returns the index of fun's parameter with the name matching "names", or asserts if the parameter is not found. "names" can contain multiple names separated by slashes.

Structs

Has
struct Has(E, bool byRef)
Undocumented in source.
StructFromParams
struct StructFromParams(args...)

Generates a struct containing fields with names, types, and default values corresponding to a function's parameter list.

Templates

AllMembers
template AllMembers(X...)

Combines the getMember and allMembers traits, to return the parameter's members as aliases.

BoxVoid
template BoxVoid(T)

Resolves to BoxedVoid if T is void, or to T otherwise.

CTIterate
template CTIterate(alias A)

Return something to foreach over optimally. If A is known at compile-time, return a tuple, so the foreach is unrolled at compile-time. Otherwise, return A for a regular runtime foreach.

ParameterNames
template ParameterNames(func...)

std.traits.ParameterIdentifierTuple patched to support anonymous functions.

ResizeNumericType
template ResizeNumericType(T, uint bits)

Expand to a built-in numeric type of the same kind (signed integer / unsigned integer / floating-point) with at least the indicated number of bits of precision.

SignedBitsType
template SignedBitsType(uint bits)

Integer type big enough to fit N bits of precision.

TryExpandNumericType
template TryExpandNumericType(T, uint additionalBits)

Like ExpandNumericType, but do not error if the resulting type is too large to fit any native D type - just expand to the largest type of the same kind instead.

UnsignedBitsType
template UnsignedBitsType(uint bits)

Integer type big enough to fit N bits of precision.

_rangeTupleImpl
template _rangeTupleImpl(size_t N, R...)
Undocumented in source.
apply
template apply(alias dg)

Call a predicate with the given value. Return the value. Intended to be used in UFCS chains using functions which mutate their argument, such as skipOver and each.

arrayToTuple
template arrayToTuple(alias arr, Elements...)

Expand an array to a tuple. The array value must be known during compilation.

enumLength
template enumLength(T)

One past the biggest element of the enum T.

expand
template expand(alias arr, size_t offset = 0)

Expand a static array to a tuple. Unlike arrayToTuple, the array may be a runtime variable.

findValueOfTypeInTuple
template findValueOfTypeInTuple(X, T...)

Returns the first value in T of type X.

functor
deprecated template functor(alias fun)

Create a functor value type (bound struct) from an alias.

getAttribute
template getAttribute(T, alias D)

Retrieves the attribute (type or value of the given type).

getAttribute
template getAttribute(T, alias D)

Stub (unsupported)>

hasAttribute
template hasAttribute(Args...)

Detects types and values of the given type.

hasAttribute
template hasAttribute(T, alias D)

Stub (unsupported)>

isValueOfTypeInTuple
template isValueOfTypeInTuple(X, T...)

Resolves to true if tuple T contains a value whose type is X.

isVersion
template isVersion(string versionName)

Is a specific version on?

rangeTuple
template rangeTuple(size_t N)

Generate a tuple containing integers from 0 to N-1. Useful for static loop unrolling. (staticIota)

stringofArray
template stringofArray(Args...)

Apply .stringof over Args and return the result as a string[].

structFun
template structFun(S)

Generates a function which passes its arguments to a struct, which is returned. Preserves field names (as parameter names) and default values.

thisOf
template thisOf(alias f)

Get f's ancestor which represents its "this" pointer. Skips template and mixin ancestors until it finds a struct or class.

valueBits
template valueBits(T)

Return the number of bits used to store the value part, i.e. T.sizeof*8 for integer parts and the mantissa size for floating-point types.

valueTuple
template valueTuple(T...)

Same as TypeTuple, but meant to be used with values.

Variables

haveCommonType
enum bool haveCommonType(T...);

Resolves to true if there exists a non-void common type for all elements of T.

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <ae@cy.md>