I have myClass and I want to add a way where I can provide a delegate to iterate over myClass.objects when a member function put(...) of myClass is called. The idea is that a user of myClass can provide something like an "iterator filter" so that the function is only called on a subset of myClass.objects.

myClass(E){
        myOtherClass!E objects;

        void put(E obj) {
                .put(objects, obj);
        }

        void put(T)(E obj, T filter) {
                foreach(o ; filter!E(objects)){
                        .put(o, obj);
                }
        }
}

struct myFilter {
        myOtherClass!E object;

        opApply(int delegate(E) foreach_body) const {
                if(mytestfunc(object))
                        return(foreach_body(object));
        }
}

But I'm struggeling how to write all this down with tempaltes, because E is not known in myFilter. But the filter code needs to be aware of the template type if myClass. I hope the idea want to do is understandable.

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

Reply via email to