boost::mpl::string 尺寸错误信息
boost::mpl::string size error messages
这是我正在处理的用例的较小版本。
#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;
}
更新::
考虑到每个长度为 4 的模板参数,使用宏 BOOST_MPL_LIMIT_STRING_SIZE
。因此,在您的情况下,预期的字符串大小为 number of template arguments * 4
。所以,128应该是一个很好的价值。
这是我正在处理的用例的较小版本。
#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;
}
更新::
考虑到每个长度为 4 的模板参数,使用宏 BOOST_MPL_LIMIT_STRING_SIZE
。因此,在您的情况下,预期的字符串大小为 number of template arguments * 4
。所以,128应该是一个很好的价值。