Remove `get_type_index` in favour of more standard `which()`
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:
invalid_type == sizeof(Types...) + 1
// relevant test that needs upgrading
REQUIRE(variant_type{mapbox::util::no_init()}.get_type_index() == mapbox::util::detail::invalid_value);
I was thinking about the invalid index value when attempting to use a smaller type for storing the index (#19).
std/tuple/boost/... use indices 0, ..., N-1, and size_t(-1) as invalid index. I think of that as the invalid type preceding valid types in the list (its index is -1, although unsigned).
mapbox::variant internally uses indices N-1, ..., 0, and size_t(-1) as invalid. In the same line of thinking, the invalid type follows valid types. index_type(-1) is awkward in comparisons when index_type is an arbitrary unsigned type, so while implementing that, I modified the internal indexing to N, ..., 1, and 0 as invalid index. It's simple and reliable with whatever type is used for storing the index.
@lightmare - thanks. I can see it will work but I'm a bit hesitant to just go and change internal index to
N,...,1 Lets get a consensus on this :) @joto ?
@artemp how is this related to #67? Can one be closed in favor of the other?
Currently there is still the public get_type_index() function, so this internal index is visible outside. I suggest we mark this function as deprecated and remove it in 2.0 and then revisit this issue. @artemp?
ok with me
/cc @joto @lightmare @springmeyer
/agree, shouldn't be changed until it's truly internal.