Policy for returning sequences of references
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
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:
``` c++
#include
#include
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.
Contributor guide
Assessment
This issue has not been assessed yet.