On Wed, Feb 22, 2017 at 3:21 AM, Jared Grubb wrote:
I'm not really sure I fully understand your comparison to Hana.
It sounds like you're saying that "Metal is smaller and simpler than
Hana", in that Metal (1) has simpler/fewer concepts and (2) has a more
restricted focus.
Thanks for your feedback, I'll add a section to the documentation comparing
Metal to Hana and MPL: https://github.com/brunocodutra/metal/issues/55
It seems that Metal probably does something Hana does not, but I'm not
sure what it is from this overview.
Indeed there is something one can't do with Hana and that is exactly the
very most important use case for Metal: control template overload
resolution through SFINAE.
Consider the following very simple toy example.
~~~
#include
namespace hana = boost::hana;
template<typename X>
constexpr auto fun(X const& x) -> decltype(void(hana::reverse(x)), true) {
return true;
}
constexpr bool fun(...) {
return false;
}
static_assert(fun(hana::tuple_t<>), "");
static_assert(!fun(0), "");
~~~
fun() here doesn't mean anything or have any practical use, the only thing
that matters in this example is that the static assertions should hold.
Unfortunately however, because Hana does not provide any SFINAE guarantees,
this example simply does not compile. As soon as fun(0) is instantiated, a
hard error is triggered from within Hana in the first overload and there is
nothing the user can do about it. That effectively means, one cannot
control overload resolution using Hana. I should mention that this is not a
flaw in Hana, it was just a design choice.
Metal on the other hand is crafted exactly for that use case. It guarantees
never to trigger a hard error, unless of course user provided metafunctions
do that internally. This toy example looks like the following using Metal.
~~~
#include
template<typename X>
constexpr auto fun(X const& x) -> decltype(void(metal::reverse<X>{}), true)
{
return true;
}
constexpr bool fun(...) {
return false;
}
static_assert(fun(metal::list<>{}), "");
static_assert(!fun(0), "");
~~~
And compiles just fine.