These are chat archives for boostorg/hana

25th
Jun 2016
Louis Dionne
@ldionne
Jun 25 2016 15:48 UTC
Wuuuuut! I’m so going to play around with them!
Jason Rice
@ricejasonf
Jun 25 2016 21:33 UTC
constexpr_if.cpp:11:13: error: expected unqualified-id
  constexpr if (T::value < 5)
:cry:
test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:      if constexpr (sizeof(n) == 4) // expected-note 2{{constexpr if}}
that's weird
if constexpr(blah) works
#include<boost/hana.hpp>

namespace hana = boost::hana;

struct a_tag { };
struct b_tag { };

template <typename T>
constexpr auto get(T)
{
  if constexpr(T::value < 5)
    return hana::type_c<a_tag>;
  else
    return hana::type_c<b_tag>;
}

int main()
{
  static_assert(get(hana::int_c<0>) == hana::type_c<a_tag>);
  static_assert(get(hana::int_c<5>) == hana::type_c<b_tag>);
}
Jason Rice
@ricejasonf
Jun 25 2016 22:26 UTC
Based on the compile time, it appears to be instantiating the "expensive" statement even though the condition is false (which I think is incorrect)
#include<boost/hana.hpp>

namespace hana = boost::hana;

struct a_tag { };
struct b_tag { };
template <int max>
struct c_tag
{
  static constexpr auto xs = hana::sum<int>(hana::to_tuple(hana::range_c<int, 0, max>));
};

template <typename T>
constexpr auto get(T)
{
  if constexpr(T::value > 9)
    return c_tag<250>::xs;
  else if constexpr(T::value > 4)
    return hana::type_c<b_tag>;
  else
    return hana::type_c<a_tag>;
}

int main()
{
  static_assert(get(hana::int_c<0>)   == hana::type_c<a_tag>);
  static_assert(get(hana::int_c<5>)   == hana::type_c<b_tag>);
  //static_assert(get(hana::int_c<10>)  == c_tag<250>::xs);
}
if I remove the first condition c_tag does not get instantiated.
Is it too early to file a bug for that? :P
Jason Rice
@ricejasonf
Jun 25 2016 22:41 UTC
This message was deleted