static_assert with nonconstexpr objects in hana's tutorial

Viewed 50

Reading the hana's tutorial, I wonder how can that static_assert work as expected:

template <typename Any>
auto switch_(Any& a) {
  return [&a](auto ...cases_) {
    auto cases = hana::make_tuple(cases_...);

    auto default_ = hana::find_if(cases, [](auto const& c) {
      return hana::first(c) == hana::type_c<default_t>;
    });

    static_assert(default_ != hana::nothing,
      "switch is missing a default_ case");

    // ...
  };
}

The documentation explicitly states that default_ is not a constexpr object, so, even if the overload of operator!= for those types is a constexpr function, the expression default_ != hana::nothing cannot be a constant expression since one of its arguments isn't.

The tutorial says:

Notice how we can use static_assert on the result of the comparison with nothing, even though default_ is a non-constexpr object? Boldly, Hana makes sure that no information that's known at compile-time is lost to the runtime, which is clearly the case of the presence of a default_ case.

What does the tutorial refer to with that paragraph, or how does that expression work?

1 Answers
Related