Closed grandseiken closed 6 months ago
Just to be clear...you want to pass an object to apply(...) that has an operator(...) which then has a side-effect on the object?
I am very much into functional programming and I personally think doing something like this is a code smell, but I guess you are right...there is no reason to disallow this. C++ is about freedom and letting people make their own design choices.
apply()
returns void
, so (at least in overload where the named tuple itself is const
) the object passed must represent a side-effect of some sort, or else the call does nothing. Whether the side effect happens to apply to the object itself, or something else known to that object (e.g. a pointer captured in a lambda, or some global state) is immaterial.
58f1e41c830d2e598415e480939e38df3a76f785 changed the parameter type of the named tuple
apply
method fromF&&
toconst F&
, but this prevents it from being used with non-const objects. There is certainly no reason to disallow this (my fault for not adding a test).