Subject: Re: [boost] Compile Time String in C++14
From: Abel Sinkovics (abel_at_[hidden])
Date: 2014-08-26 14:45:39


Hi,

On 2014-08-26 04:22, TONGARI J wrote:
> 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 _;
> \
> }())
> ```

Compile time strings without the length limit would be great. The way
I'm using them is instantiating template classes with the string as a
template argument. So the way I'd use it would be something like:

----
template <class String>
struct metafunction_expecting_a_string;
metafunction_expecting_a_string<decltype(LIT("Hello"))>
----
I've tried your solutions with the latest Clang in svn, but the compiler 
complained about having a lambda expression in an unevaluated operand.
Did you manage to use these strings as template arguments somehow?
Regards,
   Ábel