Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl]... is there an mpl::string
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2009-04-08 12:09:52


Eric Niebler wrote:
> Noah Roberts wrote:
>> Eric Niebler wrote:
>>>>>> Andy Stevenson wrote:
>>>>>>>
>>>>>>> I recall some discussion of there being an mpl::string
>>>>>>> template..... Can't see it in the mpl library. Is it elsewhere?
>>>
>>> It has been added to trunk as of revision 52208:
>>>
>>> https://svn.boost.org/trac/boost/changeset/52208
>>>
>>> No doubt the regression tests will reveal portability problems. Once
>>> they have been worked out, we can move this to release.
>>
>> Why is this better than a metafunction c_str< Sequence >?
>>
>> typedef mpl::vector_c<char, 'h', 'e', 'l', 'l', 'o'> str;
>>
>> template < char const* sz >
>> struct x
>> {};
>>
>> x< c_str<str>::value > test;
>>
>> Is there some reason that's not possible or is prone to problems
>> avoided by mpl::string?
>
>
> That is certainly a valid design. It's somewhat subjective, but IMO
> multi-character literals give a nicer compile-time string interface.
> Consider:
>
> // With mpl::vector_c
> mpl::vector_c<char, 'h','e','l','l','o',' ','w','o','r','l','d'>
>
> // With mpl::string
> mpl::string<'hell','o wo','rld'>
>
> Neither will win a beauty contest, but my preference is strongly for the
> latter.
>

After reviewing the code it seems that all my concerns are taken care
of. It looks like it indeed iterates each individual character, not the
multicharacter literals. It also looks like iterating <'hel', 'lo w',
'orld', '!'> would be the same as iterating 'hell','o wo','rld!'>. So
pretty damn cool and some interesting techniques.

That said, I would still contemplate pulling the c_str out of the string
container proper. I would say that the mpl::string is not similar to
the std::string in that it actually has to be transformed (requiring
complete reconstruction) into a c_str; there's nothing about the
mpl::string that renders c_str easier or particular to this container
besides our prebias that it should be. That alone would indicate
separation to me but additionally if the c_str was a metafunction
separate from the string container, it could be used on any ForwardSequence.

Something to consider anyway. Thanks for adding this.


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