Most of the metaprogramming tricks that we saw in this chapter were invented long before C++11. Probably, you've already heard about some of that stuff.
How about something brand new? How about implementing the previous recipe in C++14 with a library that puts the metaprogramming upside down and makes your eyebrows go up? Fasten your seatbelts, we're diving into the world of Boost.Hana
.
This recipe requires knowledge of C++11 and C++14, especially lambdas. You will need a truly C++14 compatible compiler to compile the example.
Now, let's make everything in the Boost.Hana
way:
- Start with including the header:
#include <boost/hana/traits.hpp>
- We create an
is_arithmetic_
functional object:
constexpr auto is_arithmetic_ = [](const auto& v) { auto type = boost::hana::typeid_(v); return boost::hana::traits::is_arithmetic(type); };
- Now, we implement the
get_nonarithmetics
function:
#include <boost/hana/remove_if...