35 template <
typename Ret,
typename... Args>
52 template <
typename Fn>
53 void move (
void* from,
void* to)
55 new (to) Fn (std::move (*
reinterpret_cast<Fn*
> (from)));
58 template <
typename Fn,
typename Ret,
typename... Args>
59 typename std::enable_if<std::is_same<Ret, void>::value, Ret>
::type call (
void*
s, Args... args)
61 (*
reinterpret_cast<Fn*
> (
s)) (args...);
64 template <
typename Fn,
typename Ret,
typename... Args>
65 typename std::enable_if<! std::is_same<Ret, void>::value, Ret>
::type call (
void*
s, Args... args)
67 return (*
reinterpret_cast<Fn*
> (
s)) (std::forward<Args> (args)...);
70 template <
typename Fn>
73 auto&
fn = *
reinterpret_cast<Fn*
> (
s);
79 template <
typename Fn,
typename Ret,
typename... Args>
86template <
size_t len,
typename T>
101template <
size_t len,
typename Ret,
typename... Args>
105 using Storage =
typename std::aligned_storage<len>::type;
107 template <
typename Item>
108 using Decay =
typename std::decay<Item>::type;
110 template <
typename Item,
typename Fn = Decay<Item>>
112 &&
alignof (Fn) <=
alignof (
Storage)
113 && ! std::is_same<FixedSizeFunction, Fn>::value,
127 template <
typename Callable,
132 static_assert (
sizeof (Fn) <= len,
133 "The requested function cannot fit in this FixedSizeFunction");
134 static_assert (
alignof (Fn) <=
alignof (
Storage),
135 "FixedSizeFunction cannot accommodate the requested alignment requirements");
138 vtable = &vtableForCallable;
140 auto*
ptr =
new (&
storage) Fn (std::forward<Callable> (callable));
148 move (std::move (other));
152 template <
size_t otherLen,
typename std::enable_if<(otherLen < len),
int>::type = 0>
153 FixedSizeFunction (FixedSizeFunction<otherLen, Ret (Args...)>&& other) noexcept
154 : vtable (other.vtable)
156 move (std::move (other));
160 FixedSizeFunction& operator= (std::
nullptr_t) noexcept
162 return *this = FixedSizeFunction();
165 FixedSizeFunction& operator= (const FixedSizeFunction&) = delete;
168 template <
typename Callable, IntIfVal
idConversion<Callable> = 0>
175 template <
size_t otherLen,
typename std::enable_if<(otherLen < len),
int>::type = 0>
176 FixedSizeFunction& operator= (FixedSizeFunction<otherLen, Ret (Args...)>&& other) noexcept
178 return *this = FixedSizeFunction (std::move (other));
182 FixedSizeFunction& operator= (FixedSizeFunction&& other) noexcept
185 vtable = other.vtable;
186 move (std::move (other));
191 ~FixedSizeFunction() noexcept { clear(); }
196 Ret operator() (Args... args) const
198 if (vtable !=
nullptr)
199 return vtable->call (&
storage, std::forward<Args> (args)...);
201 throw std::bad_function_call();
208 template <
size_t,
typename>
217 template <
size_t otherLen,
typename T>
228template <
size_t len,
typename T>
231template <
size_t len,
typename T>
234template <
size_t len,
typename T>
237template <
size_t len,
typename T>
#define noexcept
Definition DistrhoDefines.h:72
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
void clear() noexcept
Definition juce_FixedSizeFunction.h:211
FixedSizeFunction(FixedSizeFunction &&other) noexcept
Definition juce_FixedSizeFunction.h:145
FixedSizeFunction(const FixedSizeFunction &)=delete
FixedSizeFunction() noexcept=default
typename std::decay< Item >::type Decay
Definition juce_FixedSizeFunction.h:108
FixedSizeFunction(Callable &&callable)
Definition juce_FixedSizeFunction.h:130
void move(FixedSizeFunction< otherLen, T > &&other) noexcept
Definition juce_FixedSizeFunction.h:218
typename std::enable_if< sizeof(Fn)<=len &&alignof(Fn)<=alignof(Storage) &&! std::is_same< FixedSizeFunction, Fn >::value, int >::type IntIfValidConversion
Definition juce_FixedSizeFunction.h:111
friend class FixedSizeFunction
Definition juce_FixedSizeFunction.h:209
typename std::aligned_storage< len >::type Storage
Definition juce_FixedSizeFunction.h:105
const detail::Vtable< Ret, Args... > * vtable
Definition juce_FixedSizeFunction.h:224
Storage storage
Definition juce_FixedSizeFunction.h:225
Definition juce_FixedSizeFunction.h:87
unsigned s
Definition inflate.c:1555
Definition juce_FixedSizeFunction.h:34
void clear(void *s)
Definition juce_FixedSizeFunction.h:71
std::enable_if< std::is_same< Ret, void >::value, Ret >::type call(void *s, Args... args)
Definition juce_FixedSizeFunction.h:59
constexpr Vtable< Ret, Args... > makeVtable()
Definition juce_FixedSizeFunction.h:80
void move(void *from, void *to)
Definition juce_FixedSizeFunction.h:53
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t port void func jack_client_t const char const char unsigned long flags const jack_port_t port jack_client_t jack_port_id_t port_id const jack_port_t const char port_name const jack_port_t port void * ptr
Definition juce_linux_JackAudio.cpp:79
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
Definition juce_Uuid.h:141
Definition juce_FixedSizeFunction.h:37
void * Storage
Definition juce_FixedSizeFunction.h:38
Move move
Definition juce_FixedSizeFunction.h:47
constexpr Vtable(Move moveIn, Call callIn, Clear clearIn) noexcept
Definition juce_FixedSizeFunction.h:44
Call call
Definition juce_FixedSizeFunction.h:48
Clear clear
Definition juce_FixedSizeFunction.h:49
Ret(*)(Storage, Args...) Call
Definition juce_FixedSizeFunction.h:41
void(*)(Storage) Clear
Definition juce_FixedSizeFunction.h:42
void(*)(Storage, Storage) Move
Definition juce_FixedSizeFunction.h:40
const char const char const char const char char * fn
Definition swell-functions.h:168
#define void
Definition unzip.h:396
#define const
Definition zconf.h:137