ericniebler/meta

Early abortion in for_each possible?

gabyx opened this issue · 1 comments

gabyx commented

Is there any way to support early abortion in meta::for_each (or the like).

So basically to do something at runtime for a specific Trait we can do:

int index = 2;
using A = meta::list<TraitA, TraitB , TraitC>;
meta::for_each(A{}, [](auto a){
     using Trait = decltype(a); 
     if (meta::find_index<A, Trait>  == index)
    {
          // do something ...
          return false; // abort iteration, not possible right now
    }
     return true; // true for continuation,  not possible right now
});

So far since its a aggregate initialization under the hood, this will not be possible.
Is there a better way of doing the above? With something else?

gabyx commented

closed in favor of #57