Skip to content

Support for reference_wrappers in make_xxx #176

@ldionne

Description

@ldionne

Right now, containers are documented as not supporting references at all. First, this should be changed because most containers are able to hold references. Furthermore, it would be nice to add support for reference_wrapper in make_tuple, like std::make_tuple. Specifically, hana::make_tuple(std::ref(x)) should create a hana::tuple<X&> instead of a hana::tuple<std::reference_wrapper<X>>.

Things I'm worried about:

  • Compile-time cost of adding even more machinery to make_tuple. This will have to be benchmarked to be sure.
  • Compile-time cost of including <functional> in such a fundamental header. This has to be benchmarked too, and we can probably cheat with a forward declaration otherwise.

As a motivating example for this feature, consider the following:

struct Person {
    std::string name;
};

auto xs = hana::make_tuple(Person{"Bob"}, Person{"John"});
auto ys = hana::transform(xs, [](Person& p) {
    return std::ref(p.name);
});

// Right now, ys contains reference_wrappers, which is hard to manipulate.
// This feature would give us the desired intuitive behavior.

Containers that should probably support this feature if we decide to go forward:

  • tuple
  • set
  • map
  • pair
  • optional
  • lazy?

As for basic_tuple, I think it is better to keep it as basic as possible for performance reasons. I don't think anybody using basic_tuple would expect that kind of sugar anyway.

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