mapbox / mapbox/variant

Remove `get_type_index` in favour of more standard `which()`

Open
#73 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement interface change
Dominant language
C++
Stars
384
Forks
96
PR merge metrics
No merged PRs in 30d

Description

`get_type_index` returns index in reversed order which is confusing.
`which` method is complaint with `boost::variant`.

In order to remove `get_type_index` we need to address last remaining issue - `invalid_type` value.

Proposed solution:

``` c++
invalid_type == sizeof(Types...) + 1
```

``` c++
// relevant test that needs upgrading
REQUIRE(variant_type{mapbox::util::no_init()}.get_type_index() == mapbox::util::detail::invalid_value);
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating get_type_index, which(), invalid_type/invalid_value, and the cited variant_type no_init test. Update the relevant test and behavior so invalid_type follows the proposed sizeof(Types...) + 1 value and get_type_index can be removed in favor of which(); done when the affected tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.