Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use if constexpr dispatch for _Pass_fn #3389

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ _EXPORT_STD struct identity {
};
#endif // _HAS_CXX20

// TRANSITION, VSO-386225
template <class _Fx>
struct _Ref_fn { // pass function object by value as a reference
template <class... _Args>
Expand All @@ -376,17 +375,14 @@ struct _Ref_fn { // pass function object by value as a reference
};

template <class _Fn>
_INLINE_VAR constexpr bool _Pass_functor_by_value_v = conjunction_v<bool_constant<sizeof(_Fn) <= sizeof(void*)>,
is_trivially_copy_constructible<_Fn>, is_trivially_destructible<_Fn>>;

template <class _Fn, enable_if_t<_Pass_functor_by_value_v<_Fn>, int> = 0> // TRANSITION, if constexpr
constexpr _Fn _Pass_fn(_Fn _Val) { // pass functor by value
return _Val;
}

template <class _Fn, enable_if_t<!_Pass_functor_by_value_v<_Fn>, int> = 0>
constexpr _Ref_fn<_Fn> _Pass_fn(_Fn& _Val) { // pass functor by "reference"
return {_Val};
constexpr auto _Pass_fn(_Fn& _Func) noexcept {
constexpr bool _Pass_by_value = conjunction_v<bool_constant<sizeof(_Fn) <= sizeof(void*)>,
is_trivially_copy_constructible<_Fn>, is_trivially_destructible<_Fn>>;
if constexpr (_Pass_by_value) {
return _Func;
} else {
return _Ref_fn<_Fn>{_Func}; // pass functor by "reference"
}
}

#if _HAS_CXX23
Expand Down