ericniebler / meta

A tiny metaprogramming library
Boost Software License 1.0
302 stars 47 forks source link

Early abortion in for_each possible? #70

Closed gabyx closed 5 years ago

gabyx commented 5 years ago

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 5 years ago

closed in favor of #57