Boost logo

Boost Users :

Subject: Re: [Boost-users] mpl::c_str<mpl::string<>> compile error
From: Eric Niebler (eniebler_at_[hidden])
Date: 2013-05-11 01:47:18


On 5/9/2013 7:11 AM, Dan Searles wrote:
>> Hello,
>>
>> the code here doesn't compile:
>>
>> #include <boost/mpl/string.hpp>
>> #include <iostream>
>>
>> namespace mpl = boost::mpl;
>>
>> typedef mpl::string<'h','e','l','l','o',' ','w','o','r','l','d'>::type
>> my_hello;
>>
>> int main()
>> {
>> std::cout << mpl::c_str<my_hello>::value << '\n';
>> std::cout << BOOST_MPL_LIMIT_STRING_SIZE << '\n';
>> }
>>
>> As usual, the example from docs works. The error is:
<snip>
>
> I'm surprised multi-character character constants are being used at all in Boost, they
> are not supposed to be portable:
>
> http://stackoverflow.com/questions/6944730/multiple-characters-in-a-character-constant

Boost has never shied away from non-portable constructs. However, it
*does* wrap non-portable constructs in config macros to ensure a
consistent cross-platform experience, which is what mpl::string does
with multichar literals.

> If you only want to use single character constants, you could place the following #define before any includes:
>
> #define BOOST_MPL_LIMIT_STRING_SIZE (32*4)
>
> That would allow up to 32, provided your compiler supports it (yet another portability issue).

That would increase the compile time and decrease readability for no
benefit, IMO.

> Since in C++, the type of 'x' is char, it should be possible to create another overload of
> mpl::string<> that takes BOOST_MPL_LIMIT_STRING_SIZE 'char's, which would work
> the way most people would expect.

How do you think most people expect it to work?

-- 
Eric Niebler
Boost.org
http://www.boost.org

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