Skip to content

Policy for returning sequences of references #175

@ldionne

Description

@ldionne

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions