Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate self-recursive lambdas #19

Open
ericniebler opened this issue Mar 19, 2015 · 2 comments
Open

Integrate self-recursive lambdas #19

ericniebler opened this issue Mar 19, 2015 · 2 comments

Comments

@ericniebler
Copy link
Owner

namespace meta_detail
{
    template<typename Ts, int = 0>
    struct lambda_rec_;

    template<typename ...Ts>
    struct lambda_rec_<list<Ts...>>
    {
        template<typename...Us>
        using apply = apply<let<var<_self, lambda_rec_>, lambda<Ts...>>, Us...>;
    };
}

////////////////////////////////////////////////////////////////////////////////////
// lambda_rec
/// For defining a self-recursive lambda. In the body of a lambda, the placeholder
/// `_self` refers to the nearest enclosing `lambda_rec`
///
/// \code
/// // Define a factorial template in terms of a recursive lambda
/// using factorial_ = lambda_rec<_a,
///     lazy::if_<lazy::greater<_a, meta::size_t<0>>,
///               lazy::multiplies<_a, lazy::apply<_self, lazy::dec<_a>>>,
///               meta::size_t<1>>>;
/// template<std::size_t N>
/// using factorial = apply<factorial_, meta::size_t<N>>;
///
/// static_assert(factorial<0>::value == 1, "");
/// static_assert(factorial<1>::value == 1, "");
/// static_assert(factorial<2>::value == 2, "");
/// static_assert(factorial<3>::value == 6, "");
/// static_assert(factorial<4>::value == 24, "");
/// \endcode
template<typename ...Ts>
using lambda_rec = meta_detail::lambda_rec_<list<Ts...>>;
@ericniebler ericniebler changed the title Integral self-recursive lambdas Integrate self-recursive lambdas Mar 19, 2015
@gnzlbg
Copy link
Collaborator

gnzlbg commented Mar 19, 2015

Is this in range-v3 master already?

@ericniebler
Copy link
Owner Author

Use the source, Luke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants