qxLib
Classes | Functions
recursive_lambda.h File Reference

Go to the source code of this file.

Classes

struct  qx::recursive_lambda< lambda_t >
 

Functions

template<class lambda_t >
recursive_lambda< std::decay_t< lambda_t > > qx::make_recursive_lambda (lambda_t &&lambda)
 Create lambda that can be called recursively. More...
 

Detailed Description

Author
Khrapov
Date
3.08.2022

Definition in file recursive_lambda.h.

Function Documentation

◆ make_recursive_lambda()

template<class lambda_t >
recursive_lambda<std::decay_t<lambda_t> > qx::make_recursive_lambda ( lambda_t &&  lambda)

Create lambda that can be called recursively.

Template Parameters
lambda_t- lambda type: see code example
Parameters
lambda- lambda object
Return values
-lambda that can be called recursively
auto calc_fibonacci = qx::make_recursive_lambda(
[](const auto& calc_fibonacci, int n) -> int // return value is required
{
if (n == 1 || n == 2)
return 1;
if (n == 0)
return 0;
return calc_fibonacci(n - 1) + calc_fibonacci(n - 2);
});
int nResult = calc_fibonacci(6);
recursive_lambda< std::decay_t< lambda_t > > make_recursive_lambda(lambda_t &&lambda)
Create lambda that can be called recursively.

Definition at line 59 of file recursive_lambda.h.