Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost-users Digest, Vol 3442, Issue 1
From: Dan Searles (dansearles_at_[hidden])
Date: 2013-05-11 11:52:20


>>> 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. Does the wrapping include handling 'qwer' on platforms where int is not 4 bytes? It may, I don't have a way to test it. > >> 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. Opinions may differ on the readability of:     typedef mpl::string<'hell','o wo','rld'> ...... vs:     typedef mpl::string<'h','e','l','l','o',' ','w','o','r','l','d'>..... But increasing compile time would be bad. That's why I'm asking if it would be possible for there to be an mpl::string<> that takes BOOST_MPL_LIMIT_STRING_SIZE 'char's? [It looks like 'x' started being a char in C++11, so it may be complicated supporting prior versions] > >> 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? My opinion is that most programmers would expect BOOST_MPL_LIMIT_STRING_SIZE single character constants to work. I know that multi-character constants are not always portable, so I try not to use them, even if a particular instance may be portable. > >-- >Eric Niebler >Boost.org >http://www.boost.org Dan Searles


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