typeindices.hpp - start index from 0

Starting it from 1 makes it more error-prone to use.
This commit is contained in:
Nekotekina 2019-08-16 00:59:30 +03:00
parent 92e6dee60f
commit 11a43e25d7
2 changed files with 14 additions and 37 deletions

View file

@ -9,8 +9,8 @@ namespace stx
template <typename Info>
class type_info final : public Info
{
// Current type id (non-zero)
unsigned type = 0;
// Current type id (starts from 0)
unsigned type = 0u - 1;
// Next typeinfo in linked list
type_info* next = nullptr;
@ -45,7 +45,7 @@ namespace stx
unsigned count() const
{
return next->index();
return next->index() + 1;
}
class const_iterator
@ -114,7 +114,7 @@ namespace stx
template <typename Info>
type_info<Info>::type_info(Info info, decltype(sizeof(int))) noexcept
: Info(info)
, type(typeinfo_v<Info>.count() + 1)
, type(typeinfo_v<Info>.count())
{
// Update linked list
typeinfo_v<Info>.next->next = this;