1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #include <boost/hana/functional/fix.hpp>
7 #include <boost/hana/assert.hpp>
8 #include <boost/hana/config.hpp>
9 #include <boost/hana/equal.hpp>
10 #include <boost/hana/eval_if.hpp>
11 #include <boost/hana/functional/always.hpp>
12 #include <boost/hana/integral_constant.hpp>
13 #include <boost/hana/minus.hpp>
14 #include <boost/hana/mult.hpp>
15 namespace hana
= boost::hana
;
18 BOOST_HANA_CONSTEXPR_LAMBDA
auto fact
= hana::fix([](auto fact
, auto n
) {
19 return hana::eval_if(hana::equal(n
, hana::ullong_c
<0>),
20 hana::always(hana::ullong_c
<1>),
21 [=](auto _
) { return hana::mult(n
, fact(_(n
) - hana::ullong_c
<1>)); }
25 constexpr unsigned long long reference(unsigned long long n
)
26 { return n
== 0 ? 1 : n
* reference(n
- 1); }
30 BOOST_HANA_CONSTANT_CHECK(hana::equal(
31 fact(hana::ullong_c
<n
>),
32 hana::ullong_c
<reference(n
)>
37 template <> void test
<-1>() { }