On 2019-06-01 04:43:13 +0000, Alex said:

That's ok, but could you provide an example anyway? Is it like this?

´´´
void main(){
     auto target = new myClass!int();
     target.objects.length = 4;
     auto val = 42;
     put(target, val, testfunction); // does the test function enters here?
     put(target, val);
     auto f = myFilter!int; // where do you want to use this entity?
}
´´´

myClass shouldn't be subclassed, only just used.

The myFilter struct is the implementation which myClass.put() should use to iterate over all objects. All things being only examples. So, the idea is, that I can provide a delegate which foreach(...; myFilter(objects)) uses. Like a run-time plug-in.

Do you have control about the contained classes? If so, it is a hint to implement the testing inside them. Like:

/* probably inside a templated mixin */
bool testfunction(inputs){...}

class myOtherClass(/*probably templated*/){... mixin testfunction ... & provide a put function}

I thought about a mixin too. But this requires an understanding of how myClass works. Which I what I want to avoid.

* So, you are not totally against the idea of modifying the foreign library, but you want to keep modifications small?

Yes, because myClass is some external lib, which can be changed to support this approach here. But not more.

With the approach now, you could, for example, handle compile time blocks inside the put function in the myClass and dynamical ones inside the myOtherClasses. class myClass(E){/* inserted put function */ void put(...){static if put action is at all possible --> put. }}

As said, KISS and really just want to provide a plug-in which is used to iterate of a sequence I provide from the outside.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to