ldionne on gh-pages
Update benchmarks to 490dbf6 fo… (compare)
ldionne on gh-pages
Update benchmarks to 490dbf6 fo… (compare)
ldionne on gh-pages
Update benchmarks to 490dbf6 fo… (compare)
ldionne on gh-pages
Update benchmarks to 490dbf6 fo… (compare)
ldionne on gh-pages
Update benchmarks to 490dbf6 fo… (compare)
Undefined symbols for architecture x86_64
std::get<Type>(tuple)
will be map[hana::type_c<Type>]
.
std::tuple
with Hana’s algorithms by including <boost/hana/ext/std/tuple.hpp>
, and std::pair
by including <boost/hana/ext/std/pair.hpp>
. See the documentation section on external adapters.
std::tuple
, hana::to<hana::ext::std::tuple_tag>(some_hana_tuple)
will do the trick. The other way around, hana::to<hana::tuple_tag>(some_std_tuple)
should also work.
index_of
function, find_if
seems to return only by copy and map is not ordered.
auto tuple = hana::make_tuple(1, 1.0f, 1.0);
auto types = hana::tuple_t<float, double, int>;
hana::sort(tuple, [](auto x, auto y) {
return hana::index_of(types, hana::decltype_(x)) <
hana::index_of(types, hana::decltype_(y));
});
#include<boost/hana.hpp>
namespace hana = boost::hana;
auto rearrange = [](auto xs, auto spec) {
auto type_map = hana::unpack(
hana::range_c<int, 0, hana::length(xs)>,
[&](auto... i) {
return hana::make_map(hana::make_pair(
hana::decltype_(xs[i]), i)...);
});
return hana::unpack(spec,
[&](auto... x) {
return hana::make_tuple(xs[type_map[hana::decltype_(x)]]...);
});
};
int main()
{
BOOST_HANA_RUNTIME_ASSERT(
rearrange(
hana::make_tuple(1, 1.0f, 1.0),
hana::tuple_t<double, int, float>)
== hana::make_tuple(1.0, 1, 1.0f));
}
spec
. I decided to play around with making different implementations of the following psuedo code (from wikipedia :P):function is_prime(n : integer)
if n ≤ 1
return false
else if n ≤ 3
return true
else if n mod 2 = 0 or n mod 3 = 0
return false
let i ← 5
while i×i ≤ n
if n mod i = 0 or n mod (i + 2) = 0
return false
i ← i + 6
return true
if_
s#include<boost/hana.hpp>
namespace hana = boost::hana;
constexpr auto if_ = hana::if_;
template<int c>
constexpr auto int_c = hana::int_c<c>;
template<bool c>
constexpr auto bool_c = hana::bool_c<c>;
auto primality_test = [](auto n)
{
return
if_(n <= int_c<1>, hana::nothing,
if_(n <= int_c<3>, hana::just(n),
if_(n % int_c<2> == int_c<0> || n % int_c<3> == int_c<0>, hana::nothing,
if_(hana::is_just(hana::while_(
[&](auto just_i) {
return hana::maybe(bool_c<false>,
[&](auto i) {
return bool_c<i * i <= n>;
}, just_i);
},
hana::just(int_c<5>),
[&](auto just_i) {
return hana::maybe(hana::nothing,
[&](auto i) {
return if_(n % i == int_c<0> || n % (i + int_c<2>) == int_c<0>, hana::nothing,
hana::just(i + int_c<6>));
}, just_i);
})), hana::just(n), hana::nothing)))); //practically lisp!
};
int main()
{
static_assert(decltype(primality_test(int_c<1009>)){} == hana::just(int_c<1009>), "");
static_assert(decltype(primality_test(int_c<1010>)){} == hana::nothing, "");
}
while_
the best choice here?