Move index() into variant_base to avoid needless ix_ >= 0 checks when single buffered

This commit is contained in:
Peter Dimov
2017-06-02 05:41:13 +03:00
parent 2a6c157fcc
commit c99bf2205c

View File

@ -413,6 +413,11 @@ template<class... T> struct variant_base_impl<true, true, T...>
{
}
constexpr std::size_t index() const noexcept
{
return ix_ - 1;
}
template<std::size_t I> constexpr mp_at_c<variant<T...>, I>& _get_impl( mp_size_t<I> ) noexcept
{
size_t const J = I+1;
@ -486,6 +491,11 @@ template<class... T> struct variant_base_impl<true, false, T...>
{
}
constexpr std::size_t index() const noexcept
{
return ix_ >= 0? ix_ - 1: -ix_ - 1;
}
template<std::size_t I> constexpr mp_at_c<variant<T...>, I>& _get_impl( mp_size_t<I> ) noexcept
{
size_t const J = I+1;
@ -555,6 +565,11 @@ template<class... T> struct variant_base_impl<false, true, T...>
_destroy();
}
constexpr std::size_t index() const noexcept
{
return ix_ - 1;
}
template<std::size_t I> constexpr mp_at_c<variant<T...>, I>& _get_impl( mp_size_t<I> ) noexcept
{
size_t const J = I+1;
@ -661,6 +676,11 @@ template<class... T> struct variant_base_impl<false, false, T...>
_destroy();
}
constexpr std::size_t index() const noexcept
{
return ix_ >= 0? ix_ - 1: -ix_ - 1;
}
template<std::size_t I> constexpr mp_at_c<variant<T...>, I>& _get_impl( mp_size_t<I> ) 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