std.experimental.typecons.wrap.wrap
- multiple declarations
Function wrap.wrap
Wrap src in an anonymous class implementing Targets.
auto wrap(Source)
(
inout Source src
)
if (implementsInterface!(Source, Targets));
wrap creates an internal wrapper class which implements the
interfaces in Targets
using the methods of src
, then returns a
GC-allocated instance of it.
Source can be either a class
or a struct
, but it must
structurally conform with all the Targets
interfaces; i.e. it must provide concrete methods with compatible
signatures of those in Targets.
If Source is a struct
then wrapping/unwrapping will
create a copy; it is not possible to affect the original struct
through the wrapper.
The returned object additionally supports unwrap
.
Note
If Targets has only one entry and Source is a
class which explicitly implements it, wrap simply returns src
upcasted to Targets[0]
.
Bugs
wrap does not support interfaces which take their own type as either a parameter type or return type in any of its methods.
See Also
unwrap
for examples
Alias wrap.wrap
Authors
Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara