Wrapping an arbitrary class/struct API

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sat Aug 24 05:12:18 PDT 2013


Hello all,

Suppose that I have a struct like e.g.:

     struct A
     {
         void foo(int n) { ... }
         void foo(Range)(Range r) { ... }
         int bar() { ... }
         int bar(double x) { ... }
         // ... and others ...
     }

... an I want to wrap it in another struct, B.  If I do this manually it would 
be something like,

     struct B
     {
         private A a;
         void foo(int n) { return a.foo(n); }
         void foo(Range)(Range r) { return a.foo(r); }
         // ... etc ...
     }

But suppose that I don't a priori know the list of functions (and function 
arguments) that need to be wrapped.  How could I go about working this out, with 
a generic programming approach?

More specifically, how could I work this out limited to a specific function of A 
(say, foo) ... ?

Thanks & best wishes,

     -- Joe


More information about the Digitalmars-d-learn mailing list