Skip to content

Instantly share code, notes, and snippets.

@ricejasonf

ricejasonf/Makefile

Last active Dec 3, 2015
Embed
What would you like to do?
Precompiled Header Experiment
#error Precompiled header not used
#ifndef EXPENSIVE_HPP
#define EXPENSIVE_HPP
#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>;
template<int n_>
struct PrimalityTest
{
auto helper()
{
auto n = hana::int_c<n_>;
auto tests = hana::make_tuple(
hana::make_pair(n <= int_c<1>,
bool_c<false>),
hana::make_pair(n <= int_c<3>,
bool_c<true>),
hana::make_pair(n % int_c<2> == int_c<0> || n % int_c<3> == int_c<0>,
bool_c<false>),
hana::make_pair(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);
})), bool_c<true>),
hana::make_pair(bool_c<true>, bool_c<true>));
auto results = hana::unpack(tests,
[](auto... x) {
return hana::make_tuple(if_(hana::first(x), hana::just(hana::second(x)), hana::nothing)...);
});
return if_(**hana::find_if(results, hana::is_just), hana::just(n), hana::nothing);
}
constexpr bool operator()()
{
return hana::is_just(helper());
}
};
auto is_prime_map_() {
return hana::unpack(hana::range_c<int, 0, 50>,
[](auto... x) {
return hana::make_tuple(hana::make_pair(x, PrimalityTest<x>{}())...);
});
}
constexpr auto is_prime_map = hana::to<hana::map_tag>(decltype((is_prime_map_())){});
#endif
//#include "all.hpp"
int main()
{
static_assert(!is_prime_map[hana::int_c<25>], "");
}
CC=clang++ -std=c++14
all: main
main: main.cpp all.hpp.pch
$(CC) main.cpp -include-pch all.hpp.pch -o main
all.hpp.pch: expensive.hpp
$(CC) expensive.hpp -o all.hpp.pch
clean:
rm main *.hpp.pch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.