RPNX::DataStructures
Header-only C++ data structures and supporting utilities.
Loading...
Searching...
No Matches
rpnx::function< R(Args...) > Class Template Reference

Owning, copyable type-erased callable with small-buffer optimization. More...

#include <functional.hpp>

Classes

struct  function_tag
 Compile-time identity tag for a free function. More...
 

Public Member Functions

template<auto & fn>
constexpr function_tag< fn > tag_of (decltype(fn)&)
 Creates a compile-time identity tag for a free function.
 
template<typename Functor, typename = std::enable_if_t< !std::is_same_v< std::decay_t< Functor >, function > >>
 function (Functor &&f) noexcept(use_sbo< std::decay_t< Functor > >())
 Constructs a function from a compatible callable.
 
 function (function const &other)
 Copy-constructs a function and its stored callable.
 
 function (function &&other) noexcept
 Move-constructs a function, leaving other empty when it owns heap storage.
 
functionoperator= (function const &other)
 Copy-assigns a function and its stored callable.
 
functionoperator= (function &&other) noexcept
 Move-assigns a function.
 
 operator bool () const noexcept
 Tests whether a callable is stored.
 
operator() (Args... args)
 Invokes the stored callable.
 
bool operator== (std::nullptr_t) const noexcept
 Tests whether the function is empty.
 

Detailed Description

template<typename R, typename... Args>
class rpnx::function< R(Args...) >

Owning, copyable type-erased callable with small-buffer optimization.

Empty functions compare equal to nullptr and throw std::bad_function_call when invoked. Small nothrow-copyable callables are stored inline; other callables are heap allocated.

Template Parameters
RCallable return type.
ArgsCallable argument types.

Constructor & Destructor Documentation

◆ function() [1/3]

template<typename R, typename... Args>
template<typename Functor, typename = std::enable_if_t< !std::is_same_v< std::decay_t< Functor >, function > >>
rpnx::function< R(Args...) >::function ( Functor && f)
inlinenoexcept

Constructs a function from a compatible callable.

Template Parameters
FunctorCallable source type.
Parameters
fCallable to own.

◆ function() [2/3]

template<typename R, typename... Args>
rpnx::function< R(Args...) >::function ( function< R(Args...) > const & other)
inline

Copy-constructs a function and its stored callable.

Parameters
otherFunction to copy.

◆ function() [3/3]

template<typename R, typename... Args>
rpnx::function< R(Args...) >::function ( function< R(Args...) > && other)
inlinenoexcept

Move-constructs a function, leaving other empty when it owns heap storage.

Parameters
otherFunction to move.

Member Function Documentation

◆ operator bool()

template<typename R, typename... Args>
rpnx::function< R(Args...) >::operator bool ( ) const
inlinenoexcept

Tests whether a callable is stored.

Returns
true when invocation is valid.

◆ operator()()

template<typename R, typename... Args>
R rpnx::function< R(Args...) >::operator() ( Args... args)
inline

Invokes the stored callable.

Parameters
argsArguments forwarded according to the function signature.
Returns
The callable result when R is non-void.
Exceptions
std::bad_function_callif the function is empty.

◆ operator=() [1/2]

template<typename R, typename... Args>
function & rpnx::function< R(Args...) >::operator= ( function< R(Args...) > && other)
inlinenoexcept

Move-assigns a function.

Parameters
otherFunction to move.
Returns
Reference to this function.

◆ operator=() [2/2]

template<typename R, typename... Args>
function & rpnx::function< R(Args...) >::operator= ( function< R(Args...) > const & other)
inline

Copy-assigns a function and its stored callable.

Parameters
otherFunction to copy.
Returns
Reference to this function.

◆ operator==()

template<typename R, typename... Args>
bool rpnx::function< R(Args...) >::operator== ( std::nullptr_t ) const
inlinenoexcept

Tests whether the function is empty.

Returns
true when no callable is stored.

◆ tag_of()

template<typename R, typename... Args>
template<auto & fn>
function_tag< fn > rpnx::function< R(Args...) >::tag_of ( decltype(fn)& )
inlineconstexpr

Creates a compile-time identity tag for a free function.

Template Parameters
fnFunction to identify.
Returns
A stateless tag identifying fn.

The documentation for this class was generated from the following file: