diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index cf41d4a..9f3a980 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -413,6 +413,11 @@ template struct variant_base_impl { } + constexpr std::size_t index() const noexcept + { + return ix_ - 1; + } + template constexpr mp_at_c, I>& _get_impl( mp_size_t ) noexcept { size_t const J = I+1; @@ -486,6 +491,11 @@ template struct variant_base_impl { } + constexpr std::size_t index() const noexcept + { + return ix_ >= 0? ix_ - 1: -ix_ - 1; + } + template constexpr mp_at_c, I>& _get_impl( mp_size_t ) noexcept { size_t const J = I+1; @@ -555,6 +565,11 @@ template struct variant_base_impl _destroy(); } + constexpr std::size_t index() const noexcept + { + return ix_ - 1; + } + template constexpr mp_at_c, I>& _get_impl( mp_size_t ) noexcept { size_t const J = I+1; @@ -661,6 +676,11 @@ template struct variant_base_impl _destroy(); } + constexpr std::size_t index() const noexcept + { + return ix_ >= 0? ix_ - 1: -ix_ - 1; + } + template constexpr mp_at_c, I>& _get_impl( mp_size_t ) noexcept { size_t const J = I+1; @@ -958,10 +978,7 @@ public: // value status - constexpr size_t index() const noexcept - { - return this->ix_ >= 0? this->ix_ - 1 : -this->ix_ - 1; - } + using variant_base::index; // swap