@@ -58,10 +58,6 @@ template <typename FunctionT> class unique_function;
58
58
59
59
namespace detail {
60
60
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>;
65
61
template <typename CallableT, typename ThisT>
66
62
using EnableUnlessSameType =
67
63
std::enable_if_t <!std::is_same<remove_cvref_t <CallableT>, ThisT>::value>;
@@ -236,17 +232,17 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
236
232
// type erased behaviors needed. Create a static instance of the struct type
237
233
// here and each instance will contain a pointer to it.
238
234
// 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
+ }() ;
250
246
};
251
247
252
248
// A simple tag type so the call-as type to be passed to the constructor.
0 commit comments