Recker
Recker

Reputation: 1973

boost::mpl::string size error messages

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?

Upvotes: 1

Views: 229

Answers (1)

Arunmu
Arunmu

Reputation: 6901

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.

Upvotes: 1

Related Questions