add projections to tuple operations
- Dominant language
- C++
- Stars
- 291
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
Assume we want to invoke tuple_for_each or tuple_apply on the keys or values of a map. We can encode our projection inside the function object passed as argument, but it would be nicer to pass a unary function as optional third argument.
Consider this example
```
template
constexpr void reset_values1 (std::tuple& map)
{
mp11::tuple_for_each (map, [] (auto& p) {
p.second = 0;
});
}
template
constexpr void reset_values2 (std::tuple& map)
{
auto set_zero = [] (auto& x) {
x = 0;
};
auto second = [] (auto& x) -> auto& {
return x.second;
};
mp11::tuple_for_each (map, set_zero, second);
}
```
The second implementation is more verbose because we had to write some function objects, but it enables easier composition.
mp11 doesn't have useful function objects to compose with this feature, but higher order function libraries do.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.