Access via type
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reviewing the variant get() entry points and how they handle duplicate types, type aliases, std::reference_wrapper, and mapbox::util::recursive_wrapper. Compare that behavior with the issue's discussion of index-based access and determine the intended unambiguous API. Done means the access rules are defined and consistently enforced or supported, with coverage for the ambiguous wrapper cases.
Written by the indexing model from the issue text.
Description
Our implementation of variant allows access via get<type>() even if the type appears several times in the variant. This can be potentially confusing and error prone, especially when type aliasing is involved. Say, you got a variant variant<int32_t, int>. Do you know what get<int>() will do? Does the architecture matter?
What makes things even more confusing is the addition of special versions of get that unwrap std::reference_wrapper and mapbox::util::recursive_wrapper on the fly. And they get accessed using the underlying type. So having a variant<recursive_wrapper<int>> you can access that int using the somewhat magical get<int>(). What happens when you access a variant<int, recursive_wrapper<int>> using get<int>()?
I do see the convenience these choices bring, but on the other hand, these could lead to really hard to find bugs. The upcoming standards "solves" the first issue by not allowing get-access through the types if the types are not unique. You have to use index-based access then, which we don't have. It doesn't have the second problem because it doesn't have those magic wrappers.
- Dominant language
- C++
- Stars
- 384
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mapbox/variant
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100