jfalcou / kumi

C++20 Compact Tuple Tools
https://jfalcou.github.io/kumi/
Boost Software License 1.0
47 stars 7 forks source link

[FEATURE] add filter like algorithm. #96

Open jehelset opened 1 week ago

jehelset commented 1 week ago

Is your feature request related to a problem? Please describe. Sometimes it is nice to be able to filter out elements from a product-type, and work only with subset.

Describe the solution you'd like A filter like algorithm that takes a product-type and a predicate, and removes elements for which the predicate returns false.

Describe alternatives you've considered I instead used something like:

constexpr bool is_supported_thing(thing t){
  return some-expr-with-t;
}
inline constexpr auto supported_things = []{
  constexpr auto n = []{
    return std::ranges::count_if(all_things, &is_supported_thing);
  }();
  std::array<thing, n> t;
  std::ranges::copy_if(all_things, t.data(), &is_supported_thing);
  return t;
}();
jehelset commented 1 week ago

@jfalcou suggested https://godbolt.org/z/sYq4Pecxh as a workaround, which is pretty close.

jfalcou commented 1 week ago

Just need to wrap it nicely I guess