1

Here is the smaller version of a use case that I am working on.

#ifndef BOOST_MPL_LIMIT_STRING_SIZE
# define BOOST_MPL_LIMIT_STRING_SIZE 64
#endif

#include <boost/mpl/string.hpp>
#include <iostream>

using str = boost::mpl::string<'a','b','c','d','e','f','.','g','h','i','j','k','l','m','n','.','o','p','q','r','s','t','u','v','w','x','y','z'>;

int main()
{
    std::cout<<"String is "<<boost::mpl::c_str<str>::value<<std::endl;
}

Using gcc 4.9.3 gave me following error messages.

source2.cpp:19:143: error: wrong number of template arguments (28, should be 16)
 using str = boost::mpl::string<'a','b','c','d','e','f','.','g','h','i','j','k','l','m','n','.','o','p','q','r','s','t','u','v','w','x','y','z'>;
                                                                                                                                               ^
In file included from source2.cpp:16:0:
/boost/include/boost/mpl/string.hpp:135:12: error: provided for ‘template<int C0, int C1, int C2, int C3, int C4, int C5, int C6, int C7, int C8, int C9, int C10, int C11, int C12, int C13, int C14, int C15> struct boost::mpl::string’
     struct string;
            ^
source2.cpp: In function ‘int main()’:
source2.cpp:23:48: error: ‘str’ was not declared in this scope
     std::cout<<"String is "<<boost::mpl::c_str<str>::value<<std::endl;
                                                ^
source2.cpp:23:51: error: template argument 1 is invalid
     std::cout<<"String is "<<boost::mpl::c_str<str>::value<<std::endl;

I have already consulted a bunch questions related to boost::mpl::string and it did not solve my issue.

Why is compiler giving me error messages even when I have overridden the size?

Am I missing something pretty obvious?

cpplearner
  • 13,776
  • 2
  • 47
  • 72
Recker
  • 1,915
  • 25
  • 55

1 Answers1

1

You have to pass it as a multi character constant and which cannot be more than 4 bytes.

#include <boost/mpl/string.hpp>
#include <iostream>


using str1 = boost::mpl::string<'abcd','ef.g','hijk','lmn.','opqr','stuv','wxyz'>;

int main()
{
    std::cout<<"String is "<<boost::mpl::c_str<str1>::value<<std::endl;
}

UPDATE:: The macro BOOST_MPL_LIMIT_STRING_SIZE is used considering each template argument of length 4. So in your case, the expected string size is number of template arguments * 4. So, 128 should be a good value.

Arunmu
  • 6,837
  • 1
  • 24
  • 46
  • It appears that I cant even have 1, 2 or 3 bytes, i.e `a` or `ab` or `abc` will not work. It has to be `abcd`. :( – Recker Jun 03 '16 at 08:47
  • @Recker You can, upto 4 bytes. I do not get any error when I use 'ab' or 'abc'. Its' just that count of your template parameters when divided by four should not be greater than BOOST_MPL_LIMIT_STRING_SIZE – Arunmu Jun 03 '16 at 09:09
  • Nope. No luck for me on clang compiler 3.8. I am trying `<'a','ab','abc','abcd'>` with BOOST_MPL_LIMIT_STRING_SIZE as 128. But it fails to compile. with `error : multi-character character constant`. – Recker Jun 03 '16 at 11:27
  • You will have to add '-Wmultichar' flag while compiling it. – Arunmu Jun 03 '16 at 11:35