Skip to content

Structured bindings for vectors #11806

@knoepfel

Description

@knoepfel

Explain what you would like to see improved

For vector-like constructs (TVector2, TVector3, TLorentzVector, ROOT::Math::DisplacementVector3D, etc.), it would be very helpful to support structured bindings to the Cartesian coordinates (e.g.):

auto const [x, y] = func_that_returns_TVector2();

// which would be equivalent to the pair of statements:
TVector2 const vec = func_that_returns_TVector2();
auto const [a, b] = std::pair{vec[0], vec[1]};

assert(x == a);
assert(y == b);

I understand that this utility would only be helpful for accessing Cartesian coordinates, and not those related to (e.g.) polar representations.

Optional: share how it could be improved

This can be done by introducing suitable template specializations of get<std::size_t>, std::tuple_size, and std::tuple_element. See https://compiler-explorer.com/z/bv4Yef8GE as an example.

If this seems a desirable feature, I am willing to consider helping implement it.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions