-
Notifications
You must be signed in to change notification settings - Fork 220
Open
Labels
Description
This issue is a spinoff of #90. Here, instead of considering algorithms that return values/references like at
and at_key
, we consider algorithms that return containers that should probably hold references like find_if
and members
. I'm splitting #90 into two issues because I think the solution for both will be slightly different, even though related.
To illustrate the issue, consider the following code, which was submitted to me in a private email:
#include <boost/hana.hpp>
#include <iostream>
using namespace boost::hana;
using namespace boost::hana::literals;
struct Person {
BOOST_HANA_DEFINE_STRUCT(Person,
(int, age)
);
};
int main() {
Person john{30};
members(john)[0_c] = 0;
// fails because the expression is not assignable
}
This is because members
returns a container holding copies of the members of the struct, not references to it. While it seems that it would be more useful to return a sequence of references, it would also create lifetime issues when the Person
is a temporary.
ScottFreeCode