View source code
Display the source code in std/experimental/typecons.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

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

template wrap
{
  // ...
  alias wrap = wrap!(staticMap!(Unqual,Targets));
  // ...
}

Authors

Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara

License

Boost License 1.0.