mpl::c_str<mpl::string<>> compile error

Hello,
the code here doesn't compile:
#include

On 5/4/2013 12:24 PM, Olaf Peter wrote:
Hello,
the code here doesn't compile:
#include
#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
::value << '\n'; std::cout << BOOST_MPL_LIMIT_STRING_SIZE << '\n'; } As usual, the example from docs works. The error is:
$ LANG=en g++ t.cpp -o t && ./t t.cpp:6:64: error: wrong number of template arguments (11, should be 8) /usr/local/include/boost/mpl/string.hpp:102:12: error: provided for 'template
struct boost::mpl::string' t.cpp:6:72: error: expected initializer before 'my_hello' t.cpp: In function 'int main()': t.cpp:10:26: error: 'my_hello' was not declared in this scope t.cpp:10:34: error: template argument 1 is invalid why does it complain about wrong number of template arguments? BOOST_MPL_LIMIT_STRING_SIZE is 32?
$ svn info ... Path: . URL: http://svn.boost.org/svn/boost/trunk Repository Root: http://svn.boost.org/svn/boost Repository UUID: b8fc166d-592f-0410-95f2-cb63ce0dd405 Revision: 83988 ... $ LANG=en g++ --version g++ (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2) ...
Have you tried: typedef mpl::string<'hell','o wo','rld'>::type my_hello; ? BOOST_MPL_LIMIT_STRING_SIZE is a count of "characters" in the mpl::string, which is 4X the number of template parameters, since mpl::string uses multi-character literals to pack 4 characters into an int. HTH, -- Eric Niebler Boost.org http://www.boost.org

Have you tried:
typedef mpl::string<'hell','o wo','rld'>::type my_hello;
? BOOST_MPL_LIMIT_STRING_SIZE is a count of "characters" in the mpl::string, which is 4X the number of template parameters, since mpl::string uses multi-character literals to pack 4 characters into an int.
Thanks, Eric. This is from the examples and works. But there rises the
question how to use slightly longer mpl strings. Further more, using
this emits a compiler warning about multichar literal (or similar) on
gcc. Generally disabling this warning may prevent detection of issues on
other places.
A similar compile problem I have with
typedef mpl::char<'A'>::type my_A;
int main()
{
std::cout << mpl::c_str

On 13-05-06 10:44 PM, Olaf Peter wrote:
Have you tried:
typedef mpl::string<'hell','o wo','rld'>::type my_hello;
? BOOST_MPL_LIMIT_STRING_SIZE is a count of "characters" in the mpl::string, which is 4X the number of template parameters, since mpl::string uses multi-character literals to pack 4 characters into an int.
Thanks, Eric. This is from the examples and works. But there rises the question how to use slightly longer mpl strings.
I don't understand the problem you're having. If you want a longer string, you just add more characters: typedef mpl::string<'hell','o wo','rld ','abcd','efgh'>::type my_hello; If you want to append piecemeal, use mpl::push_back, which will do the right thing.
Further more, using this emits a compiler warning about multichar literal (or similar) on gcc. Generally disabling this warning may prevent detection of issues on other places.
Because you're using multichar literals in so many other places? ;-)
A similar compile problem I have with
typedef mpl::char<'A'>::type my_A;
int main() { std::cout << mpl::c_str
::value << '\n'; } but I haven't a compiler at the hand here.
mpl::c_str only works on mpl::strings. -- Eric Niebler Boost.org
participants (2)
-
Eric Niebler
-
Olaf Peter