Filter for opDispatch?
    frame 
    frame86 at live.com
       
    Sat May 15 23:41:19 UTC 2021
    
    
  
On Friday, 14 May 2021 at 23:02:22 UTC, frame wrote:
> Thanks! I stumbled around with static asserts and mixins... 
> totally forgot about the constraints but they will to the trick.
Now I run into the error
"class Foo member s is not accessible"
"template instance Base.opDispatch!("s", int, Foo) error 
instantiating"
and I have no clue why.
I swear the original code is just simple as that and 
satisfyDispatch works fine (there is no problem if I change s to 
a simple field).
```d
abstract class Base {
   void opDispatch(string property, S, this T)(auto ref S v) // if 
(satisfyDispatch!(T, property))
   {
      __traits(getMember, cast(T) this, property) = v; // error 
reported here
   }
   auto opDispatch(string property, this T)() // if 
(satisfyDispatch!(T, property))
   {
     return __traits(getMember, cast(T) this, property);
   }
}
// other module
class Foo : Base {
   protected:
     int _s;
     // int s; // would work
     void s(int v) {
         _s = v;
     }
     int s() {
         return _s;
     }
}
// called from a method like this:
void updateValue(T, V)(V value, Object object) {
    (cast(T) object).opDispatch!(property)(value);
}
```
I first thought the compiler does a recursive call on 
__traits(getMember) but it has no problems with this simple code 
above.
    
    
More information about the Digitalmars-d-learn
mailing list