This module implements a variety of type constructors, i.e., templates
that allow construction of new, useful general-purpose types.
Synopsis
// value tuples
alias Coord = Tuple!(float, "x", float, "y", float, "z");
Coord c;
c[1] = 1; // access by index
c.z = 1; // access by given name
alias DicEntry = Tuple!(string, string); // names can be omitted
// Rebindable references to const and immutable objects
void bar()
{
const w1 = new Widget, w2 = new Widget;
w1.foo();
// w1 = w2 would not work; can't rebind const object
auto r = Rebindable!(const Widget)(w1);
// invoke method as if r were a Widget object
r.foo();
// rebind r to refer to another object
r = w2;
}
Order the provided members to minimize size while preserving alignment.
Alignment is not always optimal for 80-bit reals, nor for structs declared
as align(1).
This function simply returns the Rebindableobject passed in. It's useful
in generic programming cases when a given object may be either a regular
class or a Rebindable.
Initializes a RefCounted with val. The template parameter
T of RefCounted is inferred from val.
This function can be used to move non-copyable values to the heap.
It also disables the autoInit option of RefCounted.
Defines a value paired with a distinctive "null" state that denotes
the absence of a value. If default constructed, a Nullable!Tobject starts in the null state. Assigning it renders it
non-null. Calling nullify can nullify it again.
Just like Nullable!T, except that the null state is defined as a
particular value. For example, Nullable!(uint, uint.max) is an
uint that sets aside the value uint.max to denote a null
state. Nullable!(T, nullValue) is more storage-efficient than Nullable!T because it does not need to store an extra bool.
Just like Nullable!T, except that the object refers to a value
sitting elsewhere in memory. This makes assignments overwrite the
initially assigned value. Internally NullableRef!T only stores a
pointer to T (i.e., Nullable!T.sizeof == (T*).sizeof).
Defines a reference-counted object containing a T value as
payload. RefCounted keeps track of all references of an object,
and when the reference count goes down to zero, frees the underlying
store. RefCounted uses malloc and free for operation.
Tuple of values, for example Tuple!(int, string) is a record that
stores an int and a string. Tuple can be used to bundle
values together, notably when returning multiple values from a
function. If obj is a Tuple, the individual members are
accessible with the syntax obj[0] for the first field, obj[1]
for the second, and so on.
Typedef allows the creation of a unique type which is
based on an existing type. Unlike the alias feature,
Typedef ensures the two types are not considered as equals.
Encapsulates unique ownership of a resource. Resource of type T is
deleted at the end of the scope, unless it is transferred. The
transfer can be explicit, by calling release, or implicit, when
returning Unique from a function. The resource can be a polymorphic
class object, in which case Unique behaves polymorphically too.
Defines a simple, self-documenting yes/no flag. This makes it easy for
APIs to define functions accepting flags without resorting to bool, which is opaque in calls, and without needing to define an
enumerated type separately. Using Flag!"Name" instead of bool makes the flag's meaning visible in calls. Each yes/no flag has
its own type, which makes confusions and mix-ups impossible.
Detect whether an enum is of integral type and has only "flag" values
(i.e. values with a bit count of exactly 1).
Additionally, a zero value is allowed for compatibility with enums including
a "None" value.
Creates a proxy for the value a that will forward all operations
while disabling implicit conversions. The aliased item a must be
an lvalue. This is useful for creating a new type from the
"base" type (though this is not a subtype-supertype
relationship; the new type is not related to the old type in any way,
by design).
Rebindable!(T) is a simple, efficient wrapper that behaves just
like an object of type T, except that you can reassign it to
refer to another object. For completeness, Rebindable!(T) aliases
itself away to T if T is a non-const object type.
Replaces all occurrences of From into To, in one or more types T. For
example, ReplaceType!(int, uint, Tuple!(int, float)[string]) yields
Tuple!(uint, float)[string]. The types in which replacement is performed
may be arbitrarily complex, including qualifiers, built-in type constructors
(pointers, arrays, associative arrays, functions, and delegates), and template
instantiations; replacement proceeds transitively through the type definition.
However, member types in structs or classes are not replaced because there
are no ways to express the types resulting after replacement.
Allocates a classobject right inside the current scope,
therefore avoiding the overhead of new. This facility is unsafe;
it is the responsibility of the user to not escape a reference to the
object outside the scope.
Similar to Rebindable!(T) but strips all qualifiers from the reference as
opposed to just constness / immutability. Primary intended use case is with
shared (having thread-local reference to shared class data)
BlackHole!Base is a subclass of Base which automatically implements
all abstract member functions in Base as do-nothing functions. Each
auto-implemented function just returns the default value of the return type
without doing anything.
WhiteHole!Base is a subclass of Base which automatically implements
all abstract member functions as functions that always fail. These functions
simply throw an Error and never return. Whitehole is useful for
trapping the use of class member functions that haven't been implemented.