2

当我运行下面的代码时,出现以下错误(在 kubuntu 12.04 上运行的提升版本 1.46.1-7ubuntu3):

test_param_bug.cpp:34:1: error: wrong number of template arguments (6, should be 5)
/usr/include/boost/parameter/parameters.hpp:714:8: error: provided for ‘template<class PS0, class PS1, class PS2, class PS3, class PS4> struct boost::parameter::parameters’
In file included from test_param_bug.cpp:2:0:
/usr/include/boost/parameter/preprocessor.hpp: In instantiation of ‘boost::parameter::aux::argument_pack<boost_param_params_34func<int> >’:
test_param_bug.cpp:34:1:   instantiated from here
/usr/include/boost/parameter/preprocessor.hpp:157:13: error: no type named ‘parameter_spec0’ in ‘struct boost_param_params_34func<int>’
/usr/include/boost/parameter/preprocessor.hpp:158:47: error: no type named ‘parameter_spec0’ in ‘struct boost_param_params_34func<int>’
test_param_bug.cpp:34:1: error: template argument 1 is invalid
test_param_bug.cpp:34:1: error: expected initializer before ‘func’
test_param_bug.cpp:34:1: error: wrong number of template arguments (7, should be 6)
/usr/include/boost/parameter/preprocessor.hpp:148:8: error: provided for ‘template<class Parameters, class A0, class A1, class A2, class A3, class A4> struct boost::parameter::aux::argument_pack’
test_param_bug.cpp:34:1: error: template argument 1 is invalid
test_param_bug.cpp:34:1: error: wrong number of template arguments (7, should be 6)
/usr/include/boost/parameter/preprocessor.hpp:98:8: error: provided for ‘template<class Parameters, class A0, class A1, class A2, class A3, class A4> struct boost::parameter::aux::match’
test_param_bug.cpp: In function ‘int main()’:
test_param_bug.cpp:41:10: error: no matching function for call to ‘func()’
test_param_bug.cpp:41:10: note: candidates are:
 ...CUT....

不过,它最多可以使用五个参数。让它运行会很好,因为我认为这是一个方便的功能。这是一个众所周知的限制还是我没有正确使用它?

BOOST_PARAMETER_FUNCTION(
  (void),
  func,
  tag, 
  (optional
   (param1, (int), 0)
   (param2, (int), 0)
   (param3, (int), 0)
   (param4, (int), 0)
   (param5, (int), 0)
   (param6, (int), 0) //<- won't work. too many arguments?
   )
  )
{
}
4

1 回答 1

0

在包含标头之前,可以使用#define BOOST_PARAMETER_MAX_ARITY n(在您的情况下为 n = 6)配置 Boost.Parameter 中函数中的最大参数数。5此参数在 boost 1.49 之前的默认值。值8在那之后。我相信增加这个数字会影响程序的编译时间,所以你应该将它设置为你需要的,而不是任意高。

于 2012-12-30T11:52:33.927 回答