Boost logo

Boost :

Subject: Re: [boost] compile time parser generator
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2012-01-08 18:45:09


From: Of John Bytheway

>>> Literals can be extended in both raw and cooked forms, with the
>>> exception of string literals, which can only be processed in cooked
>>> form. This exception is due to the fact that strings have prefixes
>>> that affect the specific meaning and type of the characters in
>>> question.' - source: wikipedia -
>>> http://en.wikipedia.org/wiki/C%2B%2B11#User-defined_literals .
>> Right below that Wikipedia describes a variadic template-based
>> mechanism, where the compiler instantiates a template operator and
>> passes the characters as template arguments to it. The return type of
>> that operator could be an MPL list of boxed characters and we could
>> access it using decltype - at least this is the idea.
>That interface is only available for integer and floating-point
>literals, not string literals (which that page also says). The only way
>to get at characters of a string literal at compile time is through
>constexpr functions.

So the question is, is there any way to get from a literal string to an MPL list of literal char for each character. From there it is just simple metaprogramming to do whatever with the string. It seems the constexper approach promises this, but I'd like to see the code example for what it looks like to use it and also how it works.

Regards,
Luke


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