Hi Louis, 2014-08-26 0:01 GMT+08:00 Louis Dionne <ldionne.2@gmail.com>:
This is genius, thanks a lot for posting. I've been searching for a way to do this to implement compile-time strings in Boost.Hana[1].
Glad to hear :) Actually I've found an even simpler way: ``` template<char...> struct str {}; template<std::size_t... Ns, class S> auto make_str_impl(std::index_sequence<Ns...>, S s) { return str<s.get()[Ns]...>(); } template<class S> auto make_str(S s) { return make_str_impl(std::make_index_sequence<sizeof(s.get()) - 1>(), s); } #define LIT(s) make_str([] \ { \ struct \ { \ static constexpr decltype(auto) get() \ { \ return s; \ } \ } _; \ return _; \ }()) ``` Cheers