Boost Hana Concepts implementation

390 views Asked by At

Boost Hana doesn't seems to document this aspect of the library, so I'd like to know if what I'm doing is legit at least.

I have started to add a bunch of concepts into my code, and I had to use some hana concepts. There is a example :

#include <boost/hana.hpp>

namespace hana = boost::hana;

template < typename T >
concept bool C_Type = requires(T object) {
    typename decltype(object)::type;
};

template < typename T >
concept bool C_Functor = hana::Functor<T>::value;

constexpr decltype(auto)  applySignatureOn(auto storageSig,
                                           C_Functor innerTypes) {
    return hana::transform(
          innerTypes,
          [=] (C_Type type)
          { return hana::make_pair(
              hana::make_tuple(type),
              storageSig(type));
          });
  }

Is that okay to make an "alias" of the Boost Hana Functor concept like that? Or it's something that could be change at anytime?

By the way, the error is not really precise. Probably because Hana is using C++14 and can't use concepts. But is there any plan to upgrade to C++20 one day?

1

There are 1 answers

2
Louis Dionne On BEST ANSWER

Boost Hana doesn't seems to document this aspect of the library, so I'd like to know if what I'm doing is legit at least.

Hana documents its emulation of concepts here.

Is that okay to make an "alias" of the Boost Hana Functor concept like that?

Yes, that's okay. The documentation defines that it means to be a Concept in Hana, and then it says Functor is a concept. You're using things that are all documented, hence it is safe and it won't break until Hana makes a breaking change.

Probably because Hana is using C++14 and can't use concepts. But is there any plan to upgrade to C++20 one day?

As you say, Hana is not using "C++ concepts" because it is a C++14 library and what we like to call "C++ concepts" is not part of any published language specification yet. Hana may start using C++20 concepts when the language is published, we'll see. However, it would have to bring significant improvements because it's a major change in compiler requirements for users.