diff --git a/modules/juce_core/misc/juce_Functional.h b/modules/juce_core/misc/juce_Functional.h index 79482894ef..466f830d75 100644 --- a/modules/juce_core/misc/juce_Functional.h +++ b/modules/juce_core/misc/juce_Functional.h @@ -23,24 +23,41 @@ namespace juce { +namespace detail +{ + template + using Void = void; + + template + struct EqualityComparableToNullptr + : std::false_type {}; + + template + struct EqualityComparableToNullptr() != nullptr)>> + : std::true_type {}; +} // namespace detail + +//============================================================================== /** Some helper methods for checking a callable object before invoking with the specified arguments. - If the object is a std::function it will check for nullptr before - calling. For a callable object it will invoke the function call operator. + If the object provides a comparison operator for nullptr it will check before + calling. For other objects it will just invoke the function call operator. @tags{Core} */ struct NullCheckedInvocation { - template - static void invoke (const std::function& fn, Args&&... args) + template ::value, int> = 0> + static void invoke (Callable&& fn, Args&&... args) { if (fn != nullptr) fn (std::forward (args)...); } - template + template ::value, int> = 0> static void invoke (Callable&& fn, Args&&... args) { fn (std::forward (args)...);