boostorg / boostorg/hana

Policy for returning sequences of references

Open
#175 11 comments 1 reaction 0 assignees View on GitHub
bug
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.