dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
dispenso::OnceFunction Class Reference

#include <once_function.h>

Public Member Functions

 OnceFunction ()
 
template<typename F >
 OnceFunction (F &&f)
 
 OnceFunction (const OnceFunction &other)=delete
 
 OnceFunction (OnceFunction &&other)
 
OnceFunctionoperator= (OnceFunction &&other)
 
void operator() () const
 

Detailed Description

A class fullfilling the void() signature, and operator() must be called exactly once for valid OnceFunctions. This class can be much more efficient than std::function for type erasing functors without too much state (currently < ~250 bytes).

Note
The wrapped type-erased functor in OnceFunction is not deleted upon destruction, but rather when operator() is called. It is the user's responsibility to ensure that operator() is called.

Definition at line 37 of file once_function.h.

Constructor & Destructor Documentation

◆ OnceFunction() [1/3]

dispenso::OnceFunction::OnceFunction ( )
inline

Construct a OnceFunction with invalid state.

Definition at line 42 of file once_function.h.

◆ OnceFunction() [2/3]

template<typename F >
dispenso::OnceFunction::OnceFunction ( F &&  f)
inline

Construct a OnceFunction with a valid functor.

Parameters
fA functor with signature void(). Ideally this should be a concrete functor (e.g. from lambda), though it will work with e.g. std::function. The downside in the latter case is extra overhead for double type erasure.

Definition at line 57 of file once_function.h.

◆ OnceFunction() [3/3]

dispenso::OnceFunction::OnceFunction ( OnceFunction &&  other)
inline

Definition at line 61 of file once_function.h.

Member Function Documentation

◆ operator()()

void dispenso::OnceFunction::operator() ( ) const
inline

Invoke the type-erased functor. This function must be called exactly once. Fewer will result in a leak, while more will invoke on an invalid object.

Definition at line 81 of file once_function.h.

◆ operator=()

OnceFunction & dispenso::OnceFunction::operator= ( OnceFunction &&  other)
inline

Definition at line 67 of file once_function.h.


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