Skip to content

Commit

Permalink
Remove redundant preprocessor conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
cpplearner committed Jan 9, 2024
1 parent 221218d commit 7687eec
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 355 deletions.
31 changes: 0 additions & 31 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
#include <vector>
#include <xloctime>
#include <xthreads.h>

#if _HAS_CXX20
#include <concepts>
#include <format>
#include <iomanip>
#endif // _HAS_CXX20
#endif // _HAS_CXX20

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down Expand Up @@ -1699,15 +1696,8 @@ namespace chrono {
: runtime_error(_Make_string(_Tp, _Info)) {}

private:
#if _HAS_CXX20
template <class _Duration>
_NODISCARD static string _Make_string(const local_time<_Duration>& _Tp, const local_info& _Info);
#else // ^^^ no workaround / workaround vvv
template <class _Duration>
_NODISCARD static string _Make_string(const local_time<_Duration>&, const local_info&) {
return "nonexistent_local_time";
}
#endif // ^^^ workaround ^^^
};

template <class _Duration>
Expand All @@ -1722,15 +1712,8 @@ namespace chrono {
: runtime_error(_Make_string(_Tp, _Info)) {}

private:
#if _HAS_CXX20
template <class _Duration>
_NODISCARD static string _Make_string(const local_time<_Duration>& _Tp, const local_info& _Info);
#else // ^^^ no workaround / workaround vvv
template <class _Duration>
_NODISCARD static string _Make_string(const local_time<_Duration>&, const local_info&) {
return "ambiguous_local_time";
}
#endif // ^^^ workaround ^^^
};

template <class _Duration>
Expand Down Expand Up @@ -1927,12 +1910,10 @@ namespace chrono {
return _Left.name() == _Right.name();
}

#if _HAS_CXX20
_EXPORT_STD _NODISCARD inline strong_ordering operator<=>(
const time_zone& _Left, const time_zone& _Right) noexcept {
return _Left.name() <=> _Right.name();
}
#endif // _HAS_CXX20

// [time.zone.leap]

Expand Down Expand Up @@ -2013,7 +1994,6 @@ namespace chrono {
return !(_Left < _Right.date());
}

#if _HAS_CXX20
_EXPORT_STD template <class _Duration>
requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>
_NODISCARD constexpr auto operator<=>(const leap_second& _Left, const sys_time<_Duration>& _Right) noexcept {
Expand All @@ -2023,7 +2003,6 @@ namespace chrono {
const leap_second& _Left, const leap_second& _Right) noexcept {
return _Left.date() <=> _Right.date();
}
#endif // _HAS_CXX20

// [time.zone.link]

Expand Down Expand Up @@ -2056,12 +2035,10 @@ namespace chrono {
return _Left.name() == _Right.name();
}

#if _HAS_CXX20
_EXPORT_STD _NODISCARD inline strong_ordering operator<=>(
const time_zone_link& _Left, const time_zone_link& _Right) noexcept {
return _Left.name() <=> _Right.name();
}
#endif // _HAS_CXX20

// [time.zone.db]

Expand Down Expand Up @@ -2648,13 +2625,7 @@ namespace chrono {
// Convert to the last leap second before or equal to _Time.
const auto& _Last_leap = *--_It;
const utc_seconds _Utc_leap_second{_Last_leap.date().time_since_epoch() + _It->_Elapsed() - seconds{1}};
#if _HAS_CXX20
const auto _Leap_cmp = _Utc_leap_second <=> _Time_floor;
#else // ^^^ __cpp_lib_concepts / TRANSITION, GH-395 workaround vvv
const auto _Leap_cmp = _Utc_leap_second > _Time_floor ? strong_ordering::greater
: _Utc_leap_second == _Time_floor ? strong_ordering::equal
: strong_ordering::less;
#endif // ^^^ workaround
if (_Tzdb._All_ls_positive && _STD is_gt(_Leap_cmp)) { // Case (1)
--_It;
}
Expand Down Expand Up @@ -4693,7 +4664,6 @@ namespace chrono {
}
} // namespace chrono

#if _HAS_CXX20
// [time.format]

// clang-format off
Expand Down Expand Up @@ -6006,7 +5976,6 @@ namespace chrono {
return _STD move(_Os).str();
}
} // namespace chrono
#endif // _HAS_CXX20

inline namespace literals {
inline namespace chrono_literals {
Expand Down
7 changes: 0 additions & 7 deletions stl/inc/compare
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
#if !_HAS_CXX20
_EMIT_STL_WARNING(STL4038, "The contents of <compare> are available only with C++20 or later.");
#else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv
#if _HAS_CXX20
#include <concepts>
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
#include <xtr1common>
#endif // ^^^ !_HAS_CXX20 ^^^

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down Expand Up @@ -295,7 +291,6 @@ struct common_comparison_category {
using type = common_comparison_category_t<_Types...>;
};

#if _HAS_CXX20
template <class _Ty, class _Cat>
concept _Compares_as = same_as<common_comparison_category_t<_Ty, _Cat>, _Cat>;

Expand Down Expand Up @@ -842,8 +837,6 @@ namespace _Compare_partial_order_fallback {
inline namespace _Cpos {
_EXPORT_STD inline constexpr _Compare_partial_order_fallback::_Cpo compare_partial_order_fallback;
}

#endif // _HAS_CXX20
_STD_END

#pragma pop_macro("new")
Expand Down
4 changes: 0 additions & 4 deletions stl/inc/coroutine
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ _EXPORT_STD _NODISCARD constexpr bool operator==(
#if _HAS_CXX20
_EXPORT_STD _NODISCARD constexpr strong_ordering operator<=>(
const coroutine_handle<> _Left, const coroutine_handle<> _Right) noexcept {
#if _HAS_CXX20
return compare_three_way{}(_Left.address(), _Right.address());
#else // ^^^ no workaround / workaround vvv
return _Left.address() <=> _Right.address();
#endif // ^^^ workaround ^^^
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_NODISCARD constexpr bool operator!=(const coroutine_handle<> _Left, const coroutine_handle<> _Right) noexcept {
Expand Down
111 changes: 0 additions & 111 deletions stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,9 @@ _NODISCARD _CONSTEXPR20 _Mem_fn<_Rx _Ty::*> mem_fn(_Rx _Ty::*_Pm) noexcept {

#if _HAS_CXX17
#if _HAS_CXX20
#if _HAS_CXX20
template <class _Callable, class... _Types>
concept _Can_invoke_then_negate = requires(
_Callable&& _Fx, _Types&&... _Args) { !_STD invoke(_STD forward<_Callable>(_Fx), _STD forward<_Types>(_Args)...); };
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
template <class _Void, class _Callable, class... _Types>
inline constexpr bool _Can_invoke_then_negate_impl = false;
template <class _Callable, class... _Types>
inline constexpr bool _Can_invoke_then_negate_impl<
void_t<decltype(!_STD invoke(_STD declval<_Callable>(), _STD declval<_Types>()...))>, _Callable, _Types...> = true;

template <class _Callable, class... _Types>
inline constexpr bool _Can_invoke_then_negate = _Can_invoke_then_negate_impl<void, _Callable, _Types...>;
#endif // ^^^ !_HAS_CXX20 ^^^
#endif // _HAS_CXX20

struct _Not_fn_tag {
Expand Down Expand Up @@ -660,42 +649,6 @@ public:

template <class... _Types>
void operator()(_Types&&...) const&& = delete;
#elif _HAS_CXX20 // ^^^ _HAS_CXX20 && defined(__cpp_lib_concepts) / _HAS_CXX20 && !defined(__cpp_lib_concepts) vvv
template <class... _Types, enable_if_t<_Can_invoke_then_negate<_Decayed&, _Types...>, int> = 0>
constexpr decltype(auto) operator()(_Types&&... _Args) & noexcept(
noexcept(!_STD invoke(this->_Get_val(), _STD forward<_Types>(_Args)...))) {
return !_STD invoke(this->_Get_val(), _STD forward<_Types>(_Args)...);
}

template <class... _Types, enable_if_t<_Can_invoke_then_negate<const _Decayed&, _Types...>, int> = 0>
constexpr decltype(auto) operator()(_Types&&... _Args) const& noexcept(
noexcept(!_STD invoke(this->_Get_val(), _STD forward<_Types>(_Args)...))) {
return !_STD invoke(this->_Get_val(), _STD forward<_Types>(_Args)...);
}

template <class... _Types, enable_if_t<_Can_invoke_then_negate<_Decayed, _Types...>, int> = 0>
constexpr decltype(auto) operator()(_Types&&... _Args) && noexcept(
noexcept(!_STD invoke(_STD move(this->_Get_val()), _STD forward<_Types>(_Args)...))) {
return !_STD invoke(_STD move(this->_Get_val()), _STD forward<_Types>(_Args)...);
}

template <class... _Types, enable_if_t<_Can_invoke_then_negate<const _Decayed, _Types...>, int> = 0>
constexpr decltype(auto) operator()(_Types&&... _Args) const&& noexcept(
noexcept(!_STD invoke(_STD move(this->_Get_val()), _STD forward<_Types>(_Args)...))) {
return !_STD invoke(_STD move(this->_Get_val()), _STD forward<_Types>(_Args)...);
}

template <class... _Types, enable_if_t<!_Can_invoke_then_negate<_Decayed&, _Types...>, int> = 0>
void operator()(_Types&&...) & = delete;

template <class... _Types, enable_if_t<!_Can_invoke_then_negate<const _Decayed&, _Types...>, int> = 0>
void operator()(_Types&&...) const& = delete;

template <class... _Types, enable_if_t<!_Can_invoke_then_negate<_Decayed, _Types...>, int> = 0>
void operator()(_Types&&...) && = delete;

template <class... _Types, enable_if_t<!_Can_invoke_then_negate<const _Decayed, _Types...>, int> = 0>
void operator()(_Types&&...) const&& = delete;
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
template <class... _Types>
auto operator()(_Types&&... _Args) & noexcept(
Expand Down Expand Up @@ -2259,26 +2212,11 @@ constexpr auto _Call_front_binder(index_sequence<_Ix...>, _Cv_FD&& _Obj, _Cv_tup
_STD forward<_Unbound>(_Unbargs)...);
}

#if _HAS_CXX20
template <class _IntSeq, class _CvFD, class _CvBoundTuple, class... _Unbound>
concept _Can_call_front_binder = requires(_CvFD&& _Fx, _CvBoundTuple&& _Bound_tuple, _Unbound&&... _Unbound_args) {
_STD _Call_front_binder(_IntSeq{}, _STD forward<_CvFD>(_Fx), _STD forward<_CvBoundTuple>(_Bound_tuple),
_STD forward<_Unbound>(_Unbound_args)...);
};
#else // ^^^ concept available / concept unavailable vvv
template <class, class _IntSeq, class _CvFD, class _CvBoundTuple, class... _Unbound>
inline constexpr bool _Can_call_front_binder_impl = false;

template <class _IntSeq, class _CvFD, class _CvBoundTuple, class... _Unbound>
inline constexpr bool
_Can_call_front_binder_impl<void_t<decltype(_STD _Call_front_binder(_IntSeq{}, _STD declval<_CvFD>(),
_STD declval<_CvBoundTuple>(), _STD declval<_Unbound>()...))>,
_IntSeq, _CvFD, _CvBoundTuple, _Unbound...> = true;

template <class _IntSeq, class _CvFD, class _CvBoundTuple, class... _Unbound>
inline constexpr bool _Can_call_front_binder =
_Can_call_front_binder_impl<void, _IntSeq, _CvFD, _CvBoundTuple, _Unbound...>;
#endif // ^^^ concept unavailable ^^^

template <class _Fx, class... _Types>
class _Front_binder { // wrap bound callable object and arguments
Expand All @@ -2296,7 +2234,6 @@ public:
constexpr explicit _Front_binder(_FxInit&& _Func, _TypesInit&&... _Args)
: _Mypair(_One_then_variadic_args_t{}, _STD forward<_FxInit>(_Func), _STD forward<_TypesInit>(_Args)...) {}

#if _HAS_CXX20
template <class... _Unbound>
requires _Can_call_front_binder<_Seq, _Fx&, tuple<_Types...>&, _Unbound...>
constexpr decltype(auto) operator()(_Unbound&&... _Unbargs) & noexcept(noexcept(
Expand Down Expand Up @@ -2340,54 +2277,6 @@ public:

template <class... _Unbound>
void operator()(_Unbound&&...) const&& = delete;
#else // ^^^ requires available / requires unavailable vvv
template <class... _Unbound,
enable_if_t<_Can_call_front_binder<_Seq, _Fx&, tuple<_Types...>&, _Unbound...>, int> = 0>
constexpr decltype(auto) operator()(_Unbound&&... _Unbargs) & noexcept(noexcept(
_STD _Call_front_binder(_Seq{}, _Mypair._Get_first(), _Mypair._Myval2, _STD forward<_Unbound>(_Unbargs)...))) {
return _STD _Call_front_binder(
_Seq{}, _Mypair._Get_first(), _Mypair._Myval2, _STD forward<_Unbound>(_Unbargs)...);
}

template <class... _Unbound,
enable_if_t<!_Can_call_front_binder<_Seq, _Fx&, tuple<_Types...>&, _Unbound...>, int> = 0>
void operator()(_Unbound&&...) & = delete;

template <class... _Unbound,
enable_if_t<_Can_call_front_binder<_Seq, const _Fx&, const tuple<_Types...>&, _Unbound...>, int> = 0>
constexpr decltype(auto) operator()(_Unbound&&... _Unbargs) const& noexcept(noexcept(
_STD _Call_front_binder(_Seq{}, _Mypair._Get_first(), _Mypair._Myval2, _STD forward<_Unbound>(_Unbargs)...))) {
return _STD _Call_front_binder(
_Seq{}, _Mypair._Get_first(), _Mypair._Myval2, _STD forward<_Unbound>(_Unbargs)...);
}

template <class... _Unbound,
enable_if_t<!_Can_call_front_binder<_Seq, const _Fx&, const tuple<_Types...>&, _Unbound...>, int> = 0>
void operator()(_Unbound&&...) const& = delete;

template <class... _Unbound, enable_if_t<_Can_call_front_binder<_Seq, _Fx, tuple<_Types...>, _Unbound...>, int> = 0>
constexpr decltype(auto) operator()(_Unbound&&... _Unbargs) && noexcept(noexcept(_STD _Call_front_binder(
_Seq{}, _STD move(_Mypair._Get_first()), _STD move(_Mypair._Myval2), _STD forward<_Unbound>(_Unbargs)...))) {
return _STD _Call_front_binder(
_Seq{}, _STD move(_Mypair._Get_first()), _STD move(_Mypair._Myval2), _STD forward<_Unbound>(_Unbargs)...);
}

template <class... _Unbound,
enable_if_t<!_Can_call_front_binder<_Seq, _Fx, tuple<_Types...>, _Unbound...>, int> = 0>
void operator()(_Unbound&&...) && = delete;

template <class... _Unbound,
enable_if_t<_Can_call_front_binder<_Seq, const _Fx, const tuple<_Types...>, _Unbound...>, int> = 0>
constexpr decltype(auto) operator()(_Unbound&&... _Unbargs) const&& noexcept(noexcept(_STD _Call_front_binder(
_Seq{}, _STD move(_Mypair._Get_first()), _STD move(_Mypair._Myval2), _STD forward<_Unbound>(_Unbargs)...))) {
return _STD _Call_front_binder(
_Seq{}, _STD move(_Mypair._Get_first()), _STD move(_Mypair._Myval2), _STD forward<_Unbound>(_Unbargs)...);
}

template <class... _Unbound,
enable_if_t<!_Can_call_front_binder<_Seq, const _Fx, const tuple<_Types...>, _Unbound...>, int> = 0>
void operator()(_Unbound&&...) const&& = delete;
#endif // ^^^ requires unavailable ^^^
};

_EXPORT_STD template <class _Fx, class... _Types>
Expand Down
43 changes: 0 additions & 43 deletions stl/inc/numbers
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
#if !_HAS_CXX20
_EMIT_STL_WARNING(STL4038, "The contents of <numbers> are available only with C++20 or later.");
#else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv
#if _HAS_CXX20
#include <concepts>
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
#include <xtr1common>
#endif // ^^^ !_HAS_CXX20 ^^^

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand All @@ -25,7 +21,6 @@ _STL_DISABLE_CLANG_WARNINGS

_STD_BEGIN
namespace numbers {
#if _HAS_CXX20
template <class _Ty>
struct _Invalid {
static_assert(_Always_false<_Ty>, "A program that instantiates a primary template of a mathematical constant "
Expand Down Expand Up @@ -85,44 +80,6 @@ namespace numbers {
inline constexpr _Floating egamma_v<_Floating> = static_cast<_Floating>(0.5772156649015329);
template <floating_point _Floating>
inline constexpr _Floating phi_v<_Floating> = static_cast<_Floating>(1.618033988749895);
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
template <class _Ty>
struct _Reject_invalid {
static_assert(is_floating_point_v<_Ty>, "A program that instantiates a primary template of a mathematical "
"constant variable template is ill-formed. (N4950 [math.constants]/3)");
using type = _Ty;
};

template <class _Ty>
using _Reject_invalid_t = _Reject_invalid<_Ty>::type;

_EXPORT_STD template <class _Ty>
inline constexpr _Ty e_v = static_cast<_Reject_invalid_t<_Ty>>(2.718281828459045);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty log2e_v = static_cast<_Reject_invalid_t<_Ty>>(1.4426950408889634);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty log10e_v = static_cast<_Reject_invalid_t<_Ty>>(0.4342944819032518);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty pi_v = static_cast<_Reject_invalid_t<_Ty>>(3.141592653589793);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty inv_pi_v = static_cast<_Reject_invalid_t<_Ty>>(0.3183098861837907);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty inv_sqrtpi_v = static_cast<_Reject_invalid_t<_Ty>>(0.5641895835477563);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty ln2_v = static_cast<_Reject_invalid_t<_Ty>>(0.6931471805599453);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty ln10_v = static_cast<_Reject_invalid_t<_Ty>>(2.302585092994046);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty sqrt2_v = static_cast<_Reject_invalid_t<_Ty>>(1.4142135623730951);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty sqrt3_v = static_cast<_Reject_invalid_t<_Ty>>(1.7320508075688772);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty inv_sqrt3_v = static_cast<_Reject_invalid_t<_Ty>>(0.5773502691896257);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty egamma_v = static_cast<_Reject_invalid_t<_Ty>>(0.5772156649015329);
_EXPORT_STD template <class _Ty>
inline constexpr _Ty phi_v = static_cast<_Reject_invalid_t<_Ty>>(1.618033988749895);
#endif // ^^^ !_HAS_CXX20 ^^^

_EXPORT_STD inline constexpr double e = e_v<double>;
_EXPORT_STD inline constexpr double log2e = log2e_v<double>;
Expand Down
Loading

0 comments on commit 7687eec

Please sign in to comment.