Orrery
A GPU-accelerated N-body gravitational simulator
Toggle main menu visibility
Loading...
Searching...
No Matches
function_ref.hpp
Go to the documentation of this file.
1
#pragma once
2
28
29
#include <functional>
30
#include <memory>
31
#include <type_traits>
32
#include <utility>
33
34
namespace
orrery::core {
35
36
template
<
typename
Signature>
class
FunctionRef
;
37
43
template
<
typename
Result,
typename
... Args>
class
FunctionRef
<Result(Args...)> {
44
public
:
60
template
<
typename
Callable,
typename
Erased = std::remove_reference_t<Callable>>
61
requires
(!std::is_same_v<Erased, FunctionRef> && !std::is_const_v<Erased> &&
62
std::is_invocable_r_v<Result, Erased&, Args...>)
63
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload,cppcoreguidelines-missing-std-forward)
64
constexpr
FunctionRef
(Callable&& callable) noexcept
65
: object_(std::addressof(callable)), invoke_(&invoke_erased<Erased>) {}
66
67
constexpr
Result operator()(Args... args)
const
{
68
return
invoke_(object_, std::forward<Args>(args)...);
69
}
70
71
private
:
73
template
<
typename
Erased>
static
Result invoke_erased(
void
*
object
, Args... args) {
74
return
std::invoke(*
static_cast<
Erased*
>
(
object
), std::forward<Args>(args)...);
75
}
76
77
void
* object_;
78
Result (*invoke_)(
void
*, Args...);
79
};
80
81
}
// namespace orrery::core
orrery::core::FunctionRef< Result(Args...)>::FunctionRef
constexpr FunctionRef(Callable &&callable) noexcept
Refer to callable, which must outlive this reference.
Definition
function_ref.hpp:64
orrery::core::FunctionRef
Definition
function_ref.hpp:36
orrery
core
function_ref.hpp
Generated by
1.17.0