Extracted _Choice<T>._Strategy to variable (#1426)

Co-authored-by: Casey Carter <cartec69@gmail.com>
Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
This commit is contained in:
futuarmo 2020-11-07 03:58:33 +03:00 коммит произвёл GitHub
Родитель 04eca1ccce
Коммит 10d8e33a67
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 82 добавлений и 48 удалений

Просмотреть файл

@ -827,11 +827,13 @@ namespace ranges {
requires (_Choice<_Rng>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Rng&& _Range) const noexcept(_Choice<_Rng>._No_throw) {
// clang-format on
if constexpr (_Choice<_Rng>._Strategy == _St::_View) {
constexpr _St _Strat = _Choice<_Rng>._Strategy;
if constexpr (_Strat == _St::_View) {
return _STD forward<_Rng>(_Range);
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Ref) {
} else if constexpr (_Strat == _St::_Ref) {
return ref_view{_STD forward<_Rng>(_Range)};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Subrange) {
} else if constexpr (_Strat == _St::_Subrange) {
return subrange{_STD forward<_Rng>(_Range)};
} else {
static_assert(_Always_false<_Rng>, "Should be unreachable");
@ -1812,15 +1814,17 @@ namespace ranges {
_NODISCARD constexpr auto operator()(_Rng&& _Range, range_difference_t<_Rng> _Count) const noexcept(
_Choice<_Rng>._No_throw) {
// clang-format on
if constexpr (_Choice<_Rng>._Strategy == _St::_Empty) {
constexpr _St _Strat = _Choice<_Rng>._Strategy;
if constexpr (_Strat == _St::_Empty) {
// it's an empty_view: return another empty view
return remove_cvref_t<_Rng>{};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Preserve) {
} else if constexpr (_Strat == _St::_Preserve) {
// it's a "reconstructible range"; return the same kind of range with a restricted extent
_Count = (_STD min)(_RANGES distance(_Range), _Count);
const auto _First = _RANGES begin(_Range);
return remove_cvref_t<_Rng>{_First, _First + _Count};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Take_view) {
} else if constexpr (_Strat == _St::_Take_view) {
return take_view{_STD forward<_Rng>(_Range), _Count};
}
}
@ -2180,14 +2184,16 @@ namespace ranges {
_NODISCARD constexpr auto operator()(_Rng&& _Range, range_difference_t<_Rng> _Count) const noexcept(
_Choice<_Rng>._No_throw) {
// clang-format on
if constexpr (_Choice<_Rng>._Strategy == _St::_Empty) {
constexpr _St _Strat = _Choice<_Rng>._Strategy;
if constexpr (_Strat == _St::_Empty) {
// it's an empty_view: return another empty view
return remove_cvref_t<_Rng>{};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Preserve) {
} else if constexpr (_Strat == _St::_Preserve) {
// it's a "reconstructible range"; return the same kind of range with a restricted extent
_Count = (_STD min)(_RANGES distance(_Range), _Count);
return remove_cvref_t<_Rng>{_RANGES begin(_Range) + _Count, _RANGES end(_Range)};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Drop_view) {
} else if constexpr (_Strat == _St::_Drop_view) {
return drop_view{_STD forward<_Rng>(_Range), _Count};
}
}
@ -2231,11 +2237,13 @@ namespace ranges {
noexcept(_Choice<decay_t<_It>>._No_throw) {
// clang-format on
_STL_ASSERT(_Count >= 0, "The size passed to views::counted must be non-negative");
if constexpr (_Choice<decay_t<_It>>._Strategy == _St::_Span) {
constexpr _St _Strat = _Choice<decay_t<_It>>._Strategy;
if constexpr (_Strat == _St::_Span) {
return span{_STD to_address(_STD forward<_It>(_First)), static_cast<size_t>(_Count)};
} else if constexpr (_Choice<decay_t<_It>>._Strategy == _St::_Subrange) {
} else if constexpr (_Strat == _St::_Subrange) {
return subrange{_First, _First + _Count};
} else if constexpr (_Choice<decay_t<_It>>._Strategy == _St::_Subrange_counted) {
} else if constexpr (_Strat == _St::_Subrange_counted) {
return subrange{counted_iterator{_STD forward<_It>(_First), _Count}, default_sentinel};
}
}
@ -2439,9 +2447,11 @@ namespace ranges {
requires (_Choice<_Rng>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Rng&& _Range) const noexcept(_Choice<_Rng>._No_throw) {
// clang-format on
if constexpr (_Choice<_Rng>._Strategy == _St::_All) {
constexpr _St _Strat = _Choice<_Rng>._Strategy;
if constexpr (_Strat == _St::_All) {
return views::all(_STD forward<_Rng>(_Range));
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Common) {
} else if constexpr (_Strat == _St::_Common) {
return common_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(_Always_false<_Rng>, "Should be unreachable");
@ -2580,13 +2590,15 @@ namespace ranges {
requires (_Choice<_Rng>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Rng&& _Range) const noexcept(_Choice<_Rng>._No_throw) {
// clang-format on
if constexpr (_Choice<_Rng>._Strategy == _St::_Base) {
constexpr _St _Strat = _Choice<_Rng>._Strategy;
if constexpr (_Strat == _St::_Base) {
return _STD forward<_Rng>(_Range).base();
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Subrange_unsized) {
} else if constexpr (_Strat == _St::_Subrange_unsized) {
return subrange{_Range.end().base(), _Range.begin().base()};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Subrange_sized) {
} else if constexpr (_Strat == _St::_Subrange_sized) {
return subrange{_Range.end().base(), _Range.begin().base(), _Range.size()};
} else if constexpr (_Choice<_Rng>._Strategy == _St::_Reverse) {
} else if constexpr (_Strat == _St::_Reverse) {
return reverse_view{_STD forward<_Rng>(_Range)};
} else {
static_assert(_Always_false<_Rng>, "Should be unreachable");

Просмотреть файл

@ -698,9 +698,11 @@ namespace ranges {
template <class _Ty>
requires (_Choice<_Ty>._Strategy != _St::_None)
_NODISCARD constexpr decltype(auto) operator()(_Ty&& _Val) const noexcept(_Choice<_Ty>._No_throw) {
if constexpr (_Choice<_Ty>._Strategy == _St::_Custom) {
constexpr _St _Strat = _Choice<_Ty>._Strategy;
if constexpr (_Strat == _St::_Custom) {
return iter_move(static_cast<_Ty&&>(_Val));
} else if constexpr (_Choice<_Ty>._Strategy == _St::_Fallback) {
} else if constexpr (_Strat == _St::_Fallback) {
using _Ref = decltype(*static_cast<_Ty&&>(_Val));
if constexpr (is_lvalue_reference_v<_Ref>) {
return _STD move(*static_cast<_Ty&&>(_Val));
@ -1085,11 +1087,13 @@ namespace ranges {
template <class _Ty1, class _Ty2>
requires (_Choice<_Ty1, _Ty2>._Strategy != _St::_None)
constexpr void operator()(_Ty1&& _Val1, _Ty2&& _Val2) const noexcept(_Choice<_Ty1, _Ty2>._No_throw) {
if constexpr (_Choice<_Ty1, _Ty2>._Strategy == _St::_Custom) {
constexpr _St _Strat = _Choice<_Ty1, _Ty2>._Strategy;
if constexpr (_Strat == _St::_Custom) {
iter_swap(static_cast<_Ty1&&>(_Val1), static_cast<_Ty2&&>(_Val2));
} else if constexpr (_Choice<_Ty1, _Ty2>._Strategy == _St::_Swap) {
} else if constexpr (_Strat == _St::_Swap) {
_RANGES swap(*static_cast<_Ty1&&>(_Val1), *static_cast<_Ty2&&>(_Val2));
} else if constexpr (_Choice<_Ty1, _Ty2>._Strategy == _St::_Exchange) {
} else if constexpr (_Strat == _St::_Exchange) {
*static_cast<_Ty1&&>(_Val1) =
_Iter_exchange_move(static_cast<_Ty2&&>(_Val2), static_cast<_Ty1&&>(_Val1));
} else {
@ -2399,11 +2403,13 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Array) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Array) {
return _Val;
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
} else if constexpr (_Strat == _St::_Member) {
return _Val.begin();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Non_member) {
} else if constexpr (_Strat == _St::_Non_member) {
return begin(_Val);
} else {
static_assert(_Always_false<_Ty>, "Should be unreachable");
@ -2462,9 +2468,11 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Member) {
return _Val._Unchecked_begin();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Unwrap) {
} else if constexpr (_Strat == _St::_Unwrap) {
return _Get_unwrapped(_RANGES begin(_Val));
} else {
static_assert(_Always_false<_Ty>, "Should be unreachable");
@ -2534,12 +2542,14 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Array) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Array) {
// extent_v<remove_reference_t<_Ty&>> reuses specializations from _Choose
return _Val + extent_v<remove_reference_t<_Ty&>>;
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
} else if constexpr (_Strat == _St::_Member) {
return _Val.end();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Non_member) {
} else if constexpr (_Strat == _St::_Non_member) {
return end(_Val);
} else {
static_assert(_Always_false<_Ty>, "should be unreachable");
@ -2595,9 +2605,11 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Member) {
return _Val._Unchecked_end();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Unwrap) {
} else if constexpr (_Strat == _St::_Unwrap) {
return _Get_unwrapped(_RANGES end(_Val));
} else {
static_assert(_Always_false<_Ty>, "Should be unreachable");
@ -2730,11 +2742,13 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Member) {
return _Val.rbegin();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Non_member) {
} else if constexpr (_Strat == _St::_Non_member) {
return rbegin(_Val);
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Make_reverse) {
} else if constexpr (_Strat == _St::_Make_reverse) {
return _STD make_reverse_iterator(_RANGES end(_Val));
} else {
static_assert(_Always_false<_Ty>, "should be unreachable");
@ -2801,11 +2815,13 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Member) {
return _Val.rend();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Non_member) {
} else if constexpr (_Strat == _St::_Non_member) {
return rend(_Val);
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Make_reverse) {
} else if constexpr (_Strat == _St::_Make_reverse) {
return _STD make_reverse_iterator(_RANGES begin(_Val));
} else {
static_assert(_Always_false<_Ty>, "should be unreachable");
@ -2918,14 +2934,16 @@ namespace ranges {
template <class _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Array) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Array) {
// extent_v<remove_cvref_t<_Ty&>> reuses specializations from _Choose
return extent_v<remove_cvref_t<_Ty&>>;
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
} else if constexpr (_Strat == _St::_Member) {
return _Val.size();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Non_member) {
} else if constexpr (_Strat == _St::_Non_member) {
return size(_Val);
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Subtract) {
} else if constexpr (_Strat == _St::_Subtract) {
const auto _Delta = _RANGES end(_Val) - _RANGES begin(_Val);
return static_cast<_Make_unsigned_like_t<remove_cv_t<decltype(_Delta)>>>(_Delta);
} else {
@ -2991,11 +3009,13 @@ namespace ranges {
template <class _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr bool operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Member) {
return static_cast<bool>(_Val.empty());
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Size) {
} else if constexpr (_Strat == _St::_Size) {
return _RANGES size(_Val) == 0;
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Compare) {
} else if constexpr (_Strat == _St::_Compare) {
return static_cast<bool>(_RANGES begin(_Val) == _RANGES end(_Val));
} else {
static_assert(_Always_false<_Ty>, "should be unreachable");
@ -3051,9 +3071,11 @@ namespace ranges {
template <_Should_range_access _Ty>
requires (_Choice<_Ty&>._Strategy != _St::_None)
_NODISCARD constexpr auto operator()(_Ty&& _Val) const noexcept(_Choice<_Ty&>._No_throw) {
if constexpr (_Choice<_Ty&>._Strategy == _St::_Member) {
constexpr _St _Strat = _Choice<_Ty&>._Strategy;
if constexpr (_Strat == _St::_Member) {
return _Val.data();
} else if constexpr (_Choice<_Ty&>._Strategy == _St::_Address) {
} else if constexpr (_Strat == _St::_Address) {
return _STD to_address(_RANGES begin(_Val));
} else {
static_assert(_Always_false<_Ty>, "should be unreachable");