callonce  1.0.0
Header-only memoized call-once wrapper for any C++ callable
fedem::utility Namespace Reference

Small, self-contained utility vocabulary types. More...

Namespaces

 detail
 Implementation details. Not part of the public API; do not use directly.
 

Classes

class  single_threaded
 Execution policy with no synchronisation overhead. The CTAD default. More...
 
class  lock_free
 Thread-safe, lock-free execution policy. More...
 
class  memoized_invoke
 Wraps a callable + argument set, runs it at most once, caches the result. More...
 

Functions

template<typename F >
 memoized_invoke (F) -> memoized_invoke< single_threaded, F >
 CTAD guide: a nullary callable deduces memoized_invoke<single_threaded, F>. More...
 
template<typename F , typename... Args>
 requires (sizeof...(Args) > 0 &&std::is_invocable_v< F, Args... >) memoized_invoke(F
 CTAD guide: a callable + arguments deduces single_threaded with decayed Args. More...
 
template<typename ExecutionPolicy , typename F , typename... Args>
requires std::is_invocable_v< F, Args... > auto make_memoized (F &&func, Args &&... args)
 Build a memoized_invoke with an explicit execution policy. More...
 

Detailed Description

Small, self-contained utility vocabulary types.

Function Documentation

◆ memoized_invoke()

template<typename F >
fedem::utility::memoized_invoke ( ) -> memoized_invoke< single_threaded, F >

CTAD guide: a nullary callable deduces memoized_invoke<single_threaded, F>.

◆ requires()

template<typename F , typename... Args>
fedem::utility::requires ( sizeof...  Args,
0 &&std::is_invocable_v< F, Args... >   
)

CTAD guide: a callable + arguments deduces single_threaded with decayed Args.

◆ make_memoized()

template<typename ExecutionPolicy , typename F , typename... Args>
requires std::is_invocable_v< F, Args... > auto fedem::utility::make_memoized ( F &&  func,
Args &&...  args 
)

Build a memoized_invoke with an explicit execution policy.

CTAD always selects single_threaded, so this factory is the way to ask for lock_free (or a custom policy) while still letting F and Args be deduced.

Template Parameters
ExecutionPolicyThe policy to use — named explicitly.
Parameters
funcThe callable. Perfect-forwarded, then decayed and stored.
argsThe arguments. Perfect-forwarded, then decayed and stored.
Returns
A memoized_invoke<ExecutionPolicy, std::decay_t<F>, std::decay_t<Args>...>.
auto once = fedem::utility::make_memoized< fedem::utility::lock_free >(
&init_hardware, gpio_pin );