From c99bf2205cc3f23e5310ea97f18db6eb711e7410 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 2 Jun 2017 05:41:13 +0300 Subject: [PATCH] Move index() into variant_base to avoid needless ix_ >= 0 checks when single buffered --- include/boost/variant2/variant.hpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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