wrap.wrap

Wrap src in an anonymous class implementing 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].

template wrap(Targets...)
version(StdDdoc)
wrap
(
Source
)
(
inout Source src
)
if (
implementsInterface!(Source, Targets)
)
if (
Targets.length >= 1 &&
allSatisfy!(isInterface, Targets)
)

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

Suggestion Box / Bug Report