1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

FixedSizeFunction: Allow sinking of rvalue arguments for functions returning void

This commit is contained in:
reuk 2023-09-20 16:13:02 +01:00
parent 7d45d498b9
commit a4dfd8d6c6
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
2 changed files with 16 additions and 4 deletions

View file

@ -56,7 +56,7 @@ namespace detail
template <typename Fn, typename Ret, typename... Args>
std::enable_if_t<std::is_same_v<Ret, void>, Ret> call (void* s, Args... args)
{
(*reinterpret_cast<Fn*> (s)) (args...);
(*reinterpret_cast<Fn*> (s)) (std::forward<Args> (args)...);
}
template <typename Fn, typename Ret, typename... Args>

View file

@ -312,14 +312,26 @@ public:
{
JUCE_FAIL_ON_ALLOCATION_IN_SCOPE;
using Fn = FixedSizeFunction<64, int (std::unique_ptr<int>)>;
using FnA = FixedSizeFunction<64, int (std::unique_ptr<int>)>;
auto value = 5;
auto ptr = std::make_unique<int> (value);
Fn fn = [] (std::unique_ptr<int> p) { return *p; };
FnA fnA = [] (std::unique_ptr<int> p) { return *p; };
expect (value == fn (std::move (ptr)));
expect (value == fnA (std::move (ptr)));
using FnB = FixedSizeFunction<64, void (std::unique_ptr<int>&&)>;
FnB fnB = [&value] (std::unique_ptr<int>&& p)
{
auto x = std::move (p);
value = *x;
};
const auto newValue = 10;
fnB (std::make_unique<int> (newValue));
expect (value == newValue);
}
beginTest ("Functions be converted from smaller functions");