Boost logo

Boost Users :

Subject: Re: [Boost-users] compile-time string literal manipulation?
From: Stiles Watson (watson_at_[hidden])
Date: 2010-10-28 09:50:17


Eric Niebler wrote:
> On 10/27/2010 2:46 PM, Stiles Watson wrote:
>
>> I'm a new to metaprogramming so please bare with the stupid questions:
>>
>> I have a requirement to convert string literals to a specified format at
>> compile-time. In otherwords, given a literal like "3A689", I need to
>> verify the value and, if not valid, generate a correct value such that:
>>
>> //pseudocode
>> const char ch[] = verify<"3A689">::valid_value;
>>
>> would result in something like:
>>
>> const char ch[] = "03A689X";
>>
>> Can I use Boost to write a template to do this?
>>
>> I know that is extremely vague, but does anyone have any thoughts?
>>
>
> Use mpl::string:
>
> http://www.boost.org/doc/libs/1_44_0/libs/mpl/doc/refmanual/string.html
>
> You might find the interface less than ideal. C++ doesn't allow strings
> as template parameters.
>
>
Thanks Eric.

Question. For the example given at the link above, it has

typedef mpl::string<'hell','o wo','rld'> hello;

Why would it not be

typedef mpl::string<'h','e','l','l','o',' ','w','o','r','l','d'> hello;

OR if the example is correct, why could you not simply do

typedef mpl::string<'hello world'> hello;

Like I said, I'm new to this so I'm sure there is something fundamental
that I'm missing.

Stiles


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net