OpenShot Audio Library | OpenShotAudio: juce_Functional.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_Functional.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26#ifndef DOXYGEN
27namespace detail
28{
29 template <typename...>
30 using Void = void;
31
32 template <typename, typename = void>
33 constexpr auto equalityComparableToNullptr = false;
34
35 template <typename T>
36 constexpr auto equalityComparableToNullptr<T, Void<decltype (std::declval<T>() != nullptr)>> = true;
37} // namespace detail
38#endif
39
40//==============================================================================
49 struct NullCheckedInvocation
50{
51 template <typename Callable, typename... Args>
52 static void invoke (Callable&& fn, Args&&... args)
53 {
54 if constexpr (detail::equalityComparableToNullptr<Callable>)
55 {
56 JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Waddress")
57
58 if (fn != nullptr)
59 fn (std::forward<Args> (args)...);
60
61 JUCE_END_IGNORE_WARNINGS_GCC_LIKE
62 }
63 else
64 {
65 fn (std::forward<Args> (args)...);
66 }
67 }
68
69 template <typename... Args>
70 static void invoke (std::nullptr_t, Args&&...) {}
71};
72
78template <typename A, typename B>
79using DisableIfSameOrDerived = std::enable_if_t<! std::is_base_of_v<A, std::remove_reference_t<B>>>;
80
82template <typename Object, typename OtherObject, typename Member, typename Other>
83[[nodiscard]] Object withMember (Object copy, Member OtherObject::* member, Other&& value)
84{
85 copy.*member = std::forward<Other> (value);
86 return copy;
87}
88
89#ifndef DOXYGEN
90namespace detail
91{
92template <typename Functor, typename Return, typename... Args>
93static constexpr auto toFnPtr (Functor functor, Return (Functor::*) (Args...) const)
94{
95 return static_cast<Return (*) (Args...)> (functor);
96}
97} // namespace detail
98#endif
99
101template <typename Functor>
102static constexpr auto toFnPtr (Functor functor) { return detail::toFnPtr (functor, &Functor::operator()); }
103
104} // namespace juce
juce::NullCheckedInvocation
Definition juce_Functional.h:50