Move only function helper
This commit is contained in:
parent
25141195fc
commit
61ad41a28b
1 changed files with 19 additions and 0 deletions
19
nano/lib/function.hpp
Normal file
19
nano/lib/function.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
// TODO: Replace with std::move_only_function in C++23
|
||||
template <typename F>
|
||||
auto wrap_move_only (F && f)
|
||||
{
|
||||
using fn_type = decltype (std::function{ std::declval<F> () });
|
||||
auto ptr = std::make_shared<std::decay_t<F>> (std::forward<F> (f));
|
||||
return fn_type ([ptr] (auto &&... args) {
|
||||
return (*ptr) (std::forward<decltype (args)> (args)...);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue