Blender  V3.3
Public Types | Public Member Functions | List of all members
blender::FunctionRef< Ret(Params...)> Class Template Reference

#include <BLI_function_ref.hh>

Public Types

using OptionalReturnValue = std::conditional_t< std::is_void_v< Ret >, void, std::optional< Ret > >
 

Public Member Functions

 FunctionRef ()=default
 
 FunctionRef (std::nullptr_t)
 
template<typename Callable , BLI_ENABLE_IF(( !std::is_same_v< std::remove_cv_t< std::remove_reference_t< Callable >>, FunctionRef >)) >
 FunctionRef (Callable &&callable)
 
Ret operator() (Params... params) const
 
OptionalReturnValue call_safe (Params... params) const
 
 operator bool () const
 

Detailed Description

template<typename Ret, typename... Params>
class blender::FunctionRef< Ret(Params...)>

Definition at line 75 of file BLI_function_ref.hh.

Member Typedef Documentation

◆ OptionalReturnValue

template<typename Ret , typename... Params>
using blender::FunctionRef< Ret(Params...)>::OptionalReturnValue = std::conditional_t<std::is_void_v<Ret>, void, std::optional<Ret> >

Definition at line 135 of file BLI_function_ref.hh.

Constructor & Destructor Documentation

◆ FunctionRef() [1/3]

template<typename Ret , typename... Params>
blender::FunctionRef< Ret(Params...)>::FunctionRef ( )
default

◆ FunctionRef() [2/3]

template<typename Ret , typename... Params>
blender::FunctionRef< Ret(Params...)>::FunctionRef ( std::nullptr_t  )
inline

Definition at line 101 of file BLI_function_ref.hh.

◆ FunctionRef() [3/3]

template<typename Ret , typename... Params>
template<typename Callable , BLI_ENABLE_IF(( !std::is_same_v< std::remove_cv_t< std::remove_reference_t< Callable >>, FunctionRef >)) >
blender::FunctionRef< Ret(Params...)>::FunctionRef ( Callable &&  callable)
inline

A FunctionRef itself is a callable as well. However, we don't want that this constructor is called when Callable is a FunctionRef. If we would allow this, it would be easy to accidentally create a FunctionRef that internally calls another FunctionRef. Usually, when assigning a FunctionRef to another, we want that both contain a reference to the same underlying callable afterwards.

It is still possible to reference another FunctionRef by first wrapping it in another lambda.

Definition at line 118 of file BLI_function_ref.hh.

Member Function Documentation

◆ call_safe()

template<typename Ret , typename... Params>
OptionalReturnValue blender::FunctionRef< Ret(Params...)>::call_safe ( Params...  params) const
inline

Calls the referenced function if it is available. The return value is of type std::optional<Ret> if Ret is not void. Otherwise the return type is void.

Definition at line 142 of file BLI_function_ref.hh.

References params.

◆ operator bool()

template<typename Ret , typename... Params>
blender::FunctionRef< Ret(Params...)>::operator bool ( ) const
inline

Returns true, when the FunctionRef references a function currently. If this returns false, the FunctionRef must not be called.

Definition at line 162 of file BLI_function_ref.hh.

◆ operator()()

template<typename Ret , typename... Params>
Ret blender::FunctionRef< Ret(Params...)>::operator() ( Params...  params) const
inline

Call the referenced function and forward all parameters to it.

This invokes undefined behavior if the FunctionRef does not reference a function currently.

Definition at line 129 of file BLI_function_ref.hh.

References BLI_assert, and params.


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