rangeless::fn
Util

Functions

template<typename F >
impl::memoizer< F > rangeless::fn::make_memoized (F fn)
 Memoizing wrapper for non-recursive non-mutable unary lambdas (not synchronized). More...
 
template<typename F >
impl::scope_guard< F > rangeless::fn::make_scope_guard (F fn)
 Basic scope guard - execute some code in guard`s destructor. More...
 

Detailed Description

Function Documentation

◆ make_memoized()

template<typename F >
impl::memoizer<F> rangeless::fn::make_memoized ( fn)

Memoizing wrapper for non-recursive non-mutable unary lambdas (not synchronized).

size_t exec_count = 0;
auto fn = make_memoized([&](int x){ exec_count++; return x*2; });
VERIFY(fn(1) == 2);
VERIFY(fn(2) == 4);
VERIFY(fn(1) == 2);
VERIFY(exec_count == 2);

Definition at line 4492 of file fn.hpp.

◆ make_scope_guard()

template<typename F >
impl::scope_guard<F> rangeless::fn::make_scope_guard ( fn)

Basic scope guard - execute some code in guard`s destructor.

{{
// ...
auto on_exit = fn::make_scope_guard([&]
{
std::cerr << "Executing clean-up or roll-back...\n";
});
on_exit.dismiss(); // Cancel if no longer applicable.
}}

Definition at line 4514 of file fn.hpp.