mp11 icon indicating copy to clipboard operation
mp11 copied to clipboard

Is it more consistent if `mp_for_each` invokes functor with `mp_identity<T>()`?

Open oliora opened this issue 6 years ago • 4 comments

Currently, mp_for_each invokes f with T(). This adds a default-constructible requirement for type T which is not always feasible and also not very consistent with other parts of mp11 that never instantiate user-provided types. Should not mp_for_each invoke passed functor with mp_identity<T>() instead?

oliora avatar Jul 02 '18 17:07 oliora

mp_identity is often what you want, but not always; when the list contains integral constants, you don't want them wrapped. I went back and forth on adding the mp_identity a few times and at the end decided not to. We could add mp_for_each_id<L> that does mp_for_each<mp_transform<mp_identity, L>> even though I don't mind spelling that out.

pdimov avatar Jul 02 '18 21:07 pdimov

mp_for_each_identity<L> or .._id sounds good as well.

oliora avatar Jul 03 '18 15:07 oliora

Just passing by with a comment: I slightly lean against adding mp_for_each_id because it is trivial to write, but I am in favour of explicitly pointing out the construction mp_for_each<mp_transform<mp_identity, L>> in an example in the documentation of mp_for_each.

HDembinski avatar May 13 '19 19:05 HDembinski

I think, extending the documentation but no code changes is a good trade-off.

oliora avatar May 13 '19 21:05 oliora