uint_not_usable_without_attribute 在 karma 规则中使用数字生成器时静态断言失败
uint_not_usable_without_attribute static assert failed when using numeric generator in karma rule
我无法在业力规则中使用数字提升业力生成器,似乎是因为我以某种方式为规则使用了错误的迭代器模板参数:
#include <iostream>
#include <iterator>
#include <string>
#include <boost/spirit/include/karma.hpp>
template <typename OutputIterator>
boost::spirit::karma::rule<OutputIterator, uint_fast16_t>
int_rule{
boost::spirit::karma::int_
};
int main(int argc, char* argv[])
{
std::string output;
boost::spirit::karma::generate(std::back_inserter(output),
int_rule<std::back_insert_iterator<std::string>>, 5);
std::cout << "\"" << output << "\"\n";
return 0;
}
clang 和 gcc 失败
error: static_assert failed due to requirement
'!boost::is_same
, int_<15>, unused_type>, output_iterator >, int_<15>,
unused_type> >::value' "int_not_usable_without_attribute"
BOOST_SPIRIT_ASSERT_FAIL(OutputIterator, int_not_usable_without_attribute, ());
当通过 boost::spirit::karma::generate(std::back_inserter(output),
boost::spirit::karma::int_, 5);
直接使用生成器编译并工作时,我做错了什么?为了将数字提升业力生成器封装到业力生成器规则中,我必须使用哪个迭代器而不是 std::back_insert_iterator<std::string>
?
您在规则定义中忘记了括号。它应该是 uint_fast16_t()
,而不是 the rule documentation 的 Signature
部分中描述的普通 uint_fast16_t
。
我无法在业力规则中使用数字提升业力生成器,似乎是因为我以某种方式为规则使用了错误的迭代器模板参数:
#include <iostream>
#include <iterator>
#include <string>
#include <boost/spirit/include/karma.hpp>
template <typename OutputIterator>
boost::spirit::karma::rule<OutputIterator, uint_fast16_t>
int_rule{
boost::spirit::karma::int_
};
int main(int argc, char* argv[])
{
std::string output;
boost::spirit::karma::generate(std::back_inserter(output),
int_rule<std::back_insert_iterator<std::string>>, 5);
std::cout << "\"" << output << "\"\n";
return 0;
}
clang 和 gcc 失败
error: static_assert failed due to requirement '!boost::is_same
, int_<15>, unused_type>, output_iterator >, int_<15>, unused_type> >::value' "int_not_usable_without_attribute" BOOST_SPIRIT_ASSERT_FAIL(OutputIterator, int_not_usable_without_attribute, ());
当通过 boost::spirit::karma::generate(std::back_inserter(output),
boost::spirit::karma::int_, 5);
直接使用生成器编译并工作时,我做错了什么?为了将数字提升业力生成器封装到业力生成器规则中,我必须使用哪个迭代器而不是 std::back_insert_iterator<std::string>
?
您在规则定义中忘记了括号。它应该是 uint_fast16_t()
,而不是 the rule documentation 的 Signature
部分中描述的普通 uint_fast16_t
。