@@ -58,10 +58,6 @@ template <typename FunctionT> class unique_function;
5858
5959namespace detail {
6060
61- template <typename T>
62- using EnableIfTrivial =
63- std::enable_if_t <std::is_trivially_move_constructible<T>::value &&
64- std::is_trivially_destructible<T>::value>;
6561template <typename CallableT, typename ThisT>
6662using EnableUnlessSameType =
6763 std::enable_if_t <!std::is_same<remove_cvref_t <CallableT>, ThisT>::value>;
@@ -236,17 +232,17 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
236232 // type erased behaviors needed. Create a static instance of the struct type
237233 // here and each instance will contain a pointer to it.
238234 // Wrap in a struct to avoid https://gcc.gnu.org/PR71954
239- template <typename CallableT, typename CalledAs, typename Enable = void >
240- struct CallbacksHolder {
241- inline static NonTrivialCallbacks Callbacks = {
242- &CallImpl<CalledAs>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
243- };
244- // See if we can create a trivial callback. We need the callable to be
245- // trivially moved and trivially destroyed so that we don't have to store
246- // type erased callbacks for those operations.
247- template < typename CallableT, typename CalledAs>
248- struct CallbacksHolder <CallableT, CalledAs, EnableIfTrivial <CallableT>> {
249- inline static TrivialCallback Callbacks = {&CallImpl<CalledAs>} ;
235+ template <typename CallableT, typename CalledAs> struct CallbacksHolder {
236+ inline static auto Callbacks = []() constexpr {
237+ // For trivial callables, we don't need to store move and destroy
238+ // callbacks.
239+ if constexpr (std::is_trivially_move_constructible_v<CallableT> &&
240+ std::is_trivially_destructible_v<CallableT>)
241+ return TrivialCallback{&CallImpl<CalledAs>};
242+ else
243+ return NonTrivialCallbacks{&CallImpl< CalledAs>, &MoveImpl<CallableT>,
244+ &DestroyImpl <CallableT>};
245+ }() ;
250246 };
251247
252248 // A simple tag type so the call-as type to be passed to the constructor.
0 commit comments