omni::function< TReturn(TArgs…)>
Defined in omni/Function.h
-
template<typename TReturn, typename ...TArgs>
class function<TReturn(TArgs...)> : private omni::detail::FunctionData A polymorphic function wrapper which is compatible with
std::function
.For most usage, it is equivalent to the
std::function
API, but there are a few minor changes for ABI stability and C interoperation.The
target
andtarget_type
functions are not available. These rely on RTTI, which is not required for Omniverse builds and is not ABI safe.No support for allocators, as these were removed in C++17. The
carbReallocate
function is used for all memory management needs.A local buffer for storing functors. While the C++ Standard encourages this, this implementation keeps the size and alignment fixed.
An
omni::function
is trivially-relocatable.
Public Types
-
using result_type = typename traits::result_type
The return type of this function.
Public Functions
-
inline function() noexcept
Create an unbound instance.
-
function(function const &other) = default
Create an instance as a copy of other.
If other was bound before the call, then the created instance will be bound to the same target.
-
function(function &&other) noexcept = default
Create an instance by moving from other.
If other was bound before the call, then the created instance will be bound to the same target. After this call, other will be unbound.
-
function &operator=(function const &other) = default
Copy the other instance into this one.
If copying the function fails, both instances will remain unchanged.
-
template<typename F, typename Assigner = ::omni::detail::FunctionAssigner<traits, F>>
inline function(F &&f) The binding constructor for function, which wraps f for invocation.
The created instance will have a “target type” (referred to as
Target
here) ofstd::decay_t<Target>
which is responsible for invoking the function. The following descriptions use a common set of symbols to describe types:UReturn
— A return type which is the same as or implicitly convertible fromTReturn
. IfUReturn
isvoid
, thenTReturn
must be implicitly discardable.UArgs
… — An argument pack where all arguments are implicitly convertible toTArgs
… .UArg0Obj
— The object type of the possibly-dereferenced first type in theTArgs
… pack. In other words, ifTArgs
… was{Object*, int}
, thenUArg0Obj
would beObject
. Any cv-qualifiers follow the dereference (e.g.: ifTArg0
isObject const*
, thenUArg0Obj
isObject const
).UArg1N
… — Same asUArgs
… but do not include the first type in the pack.
The
Target
can be one of the following:A function pointer —
UReturn(*)
(UArgs…)A pointer to a member function —
UReturn UArg0Obj::*(UArg1N...)
A pointer to member data —
UReturn UArg0Obj::*
whensizeof(TArgs...) == 1
Another
omni::function
—omni::function<UReturn(UArgs...)>
whereUReturn
andUArgs
… are different fromTReturn
andTArgs
… (the exact same type uses a copy or move operation)An
std::function
—std::function<UReturn(UArgs...)>
, butUReturn
andUArgs
… can all matchTReturn
andTArgs
…A functor with
operator()
acceptingUArgs
… and returningUReturn
If the
Target
does not match any of preceding possibilities, this function does not participate in overload resolution in a SFINAE-safe manner. IfTarget
is non-copyable, then the program is ill-formed.For cases 1-5, if
f == nullptr
, then the function is initialized as unbound. Note the quirky case on #6, where the compositeomni::function<void()>{std::function<void()>{}}
will create an unbound function. But this is not commutative, asstd::function<void()>{omni::function<void()>{}}
will create a bound function which throws when called.
-
template<typename F, typename Assigner = ::omni::detail::FunctionAssigner<traits, F>>
inline function &operator=(F &&f) Bind this instance to f according to the rules in the binding constructor.
If the process of binding a
function
to f fails, this instance will remain unchanged.
-
~function() noexcept = default
If this function has context it needs to destroy, then perform that cleanup.
-
inline TReturn operator()(TArgs... args) const
Invoke this function with the provided args.
If this function is not bound (see
operator bool() const
), the program will throwbad_function_call
if exceptions are enabled or panic if they are not.
-
inline explicit operator bool() const noexcept
Check that this function is bound.