tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
472 stars 29 forks source link

Projection with any() ? #128

Closed calebtt closed 11 months ago

calebtt commented 11 months ago

Replacing some of my ranges filter stuff with flux made it around 25% faster, but I am unable to use flux::proj() for a projection with any():

return ! std::ranges::any_of(mappingsList, [](const auto vk) { return vk == 0; }, &CBActionMap::ButtonVirtualKeycode); attempt: return !flux::ref(mappingsList).any([](const auto vk) { return vk == 0; }, flux::proj(std::equal{}, &CBActionMap::ButtonVirtualKeycode));

Documentation doesn't really refer to flux::proj() much at all, beyond a couple instances of it's usage.

calebtt commented 11 months ago

Nevermind, this works:

return !flux::ref(mappingsList).any(flux::proj([](const auto vk) { return vk == 0; },&CBActionMap::ButtonVirtualKeycode));

tcbrindle commented 11 months ago

Replacing some of my ranges filter stuff with flux made it around 25% faster

That's great to hear!

Documentation doesn't really refer to flux::proj() much at all, beyond a couple instances of it's usage.

Yeah, there's lots of stuff missing from the documentation at the moment, it definitely needs improvement

Nevermind, this works:

return !flux::ref(mappingsList).any(flux::proj([](const auto vk) { return vk == 0; },&CBActionMap::ButtonVirtualKeycode));

Glad to hear you figured it out! If you're interested, I think the following should be equivalent but is a bit shorter and perhaps more readable: (the generated code should be the same though)

return flux::all(mappingsList, flux::proj(flux::pred::nonzero, &CBActionMap::ButtonVirtualKeycode));

If you have any more questions about Flux please let me know :)