boost::mpl::字符串大小错误消息

boost::mpl::string size error messages

本文关键字:错误 消息 字符串 mpl boost      更新时间:2023-10-16

这是我正在处理的用例的较小版本。

#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;
}

使用 gcc 4.9.3 给了我以下错误消息。

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;

我已经咨询了一堆与boost::mpl::string有关的问题,但它并没有解决我的问题。

为什么编译器在我覆盖了大小的情况下也会给我错误消息?

我错过了一些很明显的东西吗?

您必须将其作为多字符常量传递,并且不能超过 4 个字节。

#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;
}

更新::使用宏BOOST_MPL_LIMIT_STRING_SIZE时考虑长度为 4 的每个模板参数。因此,在您的情况下,预期的字符串大小为 number of template arguments * 4 。因此,128 应该是一个不错的值。