On Friday, 16 March 2012 at 11:22:07 UTC, Boscop wrote:
How would it be possible, the type of the delegate can't be typechecked at the call-site, because the type info is lost in the variant.
The trick is to build wrapper functions at the assignment point, where you still have all the type info. I showed that with the wrap() template in the implementation in a previous post - std.traits.ReturnType and std.traits.ParameterTypeTuple help a lot there. This same technique can do all kinds of conversions: I use it to do strings -> calls for web apps and Variant -> calls for this dynamic thing, weak typing, and script interaction. Remember, that while the wrapper is showed at the assignment type, it is a compile time thing to build the wrapper, so the assignment is still cheap. The call has a small runtime hit though, since it does the type conversions or checks there. If you wanted strict type checking, it could probably be fast; Variant.get() has a small cost.
