Access via type
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 384
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
Our implementation of variant allows access via `get()` 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`. Do you know what `get()` 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>` you can access that `int` using the somewhat magical `get()`. What happens when you access a `variant>` using `get()`?
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.
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.
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.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100