std.typecons.rebindable
- multiple declarations
- Function rebindable
- Function rebindable
- Template Rebindable
Function rebindable
Convenience function for creating a
using automatic type
inference.
Rebindable
Prototype
Rebindable!T rebindable(T)( T obj ) if (is(T == class) || is(T == interface) || isDynamicArray!T);
Parameters
Name | Description |
---|---|
obj | A reference to an object or interface, or an array slice
to initialize the with. |
Returns
A newly constructed
initialized with the given reference.
Rebindable
Function rebindable
This function simply returns the Rebindable
object
passed in. It's useful
in generic programming cases when a given object
may be either a regular
class
or a
.
Rebindable
Prototype
Rebindable!T rebindable(T)( Rebindable!T obj );
Parameters
Name | Description |
---|---|
obj | An instance of Rebindable !T. |
Returns
without any modification.
obj
Template Rebindable
is a simple, efficient wrapper that behaves just
like an Rebindable
!(T)object
of type T
, except that you can reassign it to
refer to another object
. For completeness,
aliases
itself away to Rebindable
!(T)T
if T
is a non-const object
type. However,
does not compile if Rebindable
!(T)T
is a non-class type.
You may want to use
when you want to have mutable
storage referring to Rebindable
const
objects, for example an array of
references that must be sorted in place.
does not
break the soundness of D's type system and does not incur any of the
risks usually associated with Rebindable
cast
.
Arguments
template Rebindable(T);
Parameters
Name | Description |
---|---|
T | An object , interface, or array slice type. |
Example
Regular const
object
references cannot be reassigned.
class Widget { int x; int y() const { return x; } } const a = new Widget; // Fine a.y(); // error! can't modify const a // a.x = 5; // error! can't modify const a // a = new Widget;
Example
However,
does allow reassignment,
while otherwise behaving exactly like a Rebindable
!(Widget)const Widget
.
class Widget { int x; int y() const { return x; } } auto a = Rebindable!(const Widget)(new Widget); // Fine a.y(); // error! can't modify const a // a.x = 5; // Fine a = new Widget;
Authors
Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara