Browse Source

FixedSizeFunction: Allow sinking of rvalue arguments for functions returning void

v7.0.9
reuk 2 years ago
parent
commit
a4dfd8d6c6
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
2 changed files with 16 additions and 4 deletions
  1. +1
    -1
      modules/juce_core/containers/juce_FixedSizeFunction.h
  2. +15
    -3
      modules/juce_core/containers/juce_FixedSizeFunction_test.cpp

+ 1
- 1
modules/juce_core/containers/juce_FixedSizeFunction.h View File

@@ -56,7 +56,7 @@ namespace detail
template <typename Fn, typename Ret, typename... Args> template <typename Fn, typename Ret, typename... Args>
std::enable_if_t<std::is_same_v<Ret, void>, Ret> call (void* s, Args... 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> template <typename Fn, typename Ret, typename... Args>


+ 15
- 3
modules/juce_core/containers/juce_FixedSizeFunction_test.cpp View File

@@ -312,14 +312,26 @@ public:
{ {
JUCE_FAIL_ON_ALLOCATION_IN_SCOPE; 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 value = 5;
auto ptr = std::make_unique<int> (value); 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"); beginTest ("Functions be converted from smaller functions");


Loading…
Cancel
Save