My objective is to have a something like the following while writing the string "hello" as a regular string.
struct hello: element<hana::string<'h', 'e', 'l', 'l', 'o'>, std::int64_t>{};
I can have a function make a field of this type
template <typename ValueT, char... Cs>
element<boost::hana::string<Cs...>, ValueT> named_element(boost::hana::string<Cs...>&&, const ValueT& v = ValueT()){
return element<boost::hana::string<Cs...>, ValueT>(v);
}
// ...
auto hello_e = named_element<int>(BOOST_HANA_STRING("hello"));
But my objective is not to have an object of type element
. Instead subclass from it.
I need something like the following, that I can wrap inside a macro.Then I'll use the type hello
as template parameter.
struct hello: decltype(named_element<int>(BOOST_HANA_STRING("name"))){};
The above won't compile. But something similar would help.
I am using C++14
Because BOOST_HANA_STRING uses a lambda internally, it cannot be used in unevaluated context prior to C++20. You will need to give a name to either the string or the field:
If this is not workable, and you cannot upggrade to C++20 but are comfortable depending on a Clang / gcc compiler extension, you can use
boost::hana::literals::operator""_s
: