non-static variant::visit
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 384
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
I'm creating this separate issue to keep the discussion in #113 clean.
> @artemp Because variant::visit doesn't modify internal state and making it static gives compiler some hints on how to generate binary code. Why are you thinking it shouldn't be static ?
What hints? Visiting a non-const variant _can_ modify internal state (e.g. comparison operators can give different results after such visit; edit: that's modifying external state, actually).
`visit` is a static member function template only by syntax. Its first argument is always a reference to the class it's defined in. That's identical to non-static member functions under the hood.
Why this:
``` c++
template
auto VARIANT_INLINE apply_visitor(F&& f, V& v) -> decltype(V::visit(v, std::forward(f)))
{
return V::visit(v, std::forward(f));
}
```
instead of this:
``` c++
template
auto VARIANT_INLINE apply_visitor(F&& f, V& v) -> decltype(v.visit(std::forward(f)))
{
return v.visit(std::forward(f));
}
```
// ignoring for now that `V` should be forwarded as well
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 reading issue #113 and the discussion here, then inspect the existing visit and apply_visitor entry points. Compare the static and non-static call forms, including behavior for non-const variants. Done means the design question is resolved and the chosen API behavior is documented and covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100