Boost logo

Boost :

Subject: Re: [boost] Compile Time String in C++14
From: TONGARI J (tongari95_at_[hidden])
Date: 2014-08-25 22:22:56


Hi Louis,

2014-08-26 0:01 GMT+08:00 Louis Dionne <ldionne.2_at_[hidden]>:
>
> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk