Andrei Alexandrescu <> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #6 from Andrei Alexandrescu <> 2011-12-31 
08:43:40 PST ---
OK, it looks like this is safe to close now. I compiled a slightly modified
version. There was a bug elsewhere, the line

   Variant opDispatch(string m, Args)(Args args...) {

should be

   Variant opDispatch(string m, Args...)(Args args) {

Also, the signature of the delegate should contain "...", i.e. replace

      delegate Variant(Dynamic, Variant[]) {


      delegate Variant(Dynamic, Variant[]...) {

The working code is:

module test;// Context begin
#line 1369 "0900-operators.tex"
import std.variant;

alias Variant delegate(Dynamic self, Variant[] args...) DynMethod;
// Context end
// Context begin
#line 1383 "0900-operators.tex"
class Dynamic {
   private DynMethod[string] methods;
   void addMethod(string name, DynMethod m) {
      methods[name] = m;
   void removeMethod(string name) {
   // Dispatch dynamically on method
   Variant call(string methodName, Variant[] args...) {
      return methods[methodName](this, args);
   // Provide syntactic sugar with opDispatch
   Variant opDispatch(string m, Args...)(Args args) {
      Variant[] packedArgs = new Variant[args.length];
      foreach (i, arg; args) {
         packedArgs[i] = Variant(arg);
      return call(m, args);
// Context end
#line 1409 "0900-operators.tex"
unittest {
  import std.stdio;
  auto obj = new Dynamic;
      delegate Variant(Dynamic, Variant[]...) {
        writeln("Hello, world!");
        return Variant();
  obj.sayHello();  // Prints "Hello, world!"

void main(){}

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to