BOOST_PARAMETER_FUNCTION最多可以处理5个参数?

时间:2012-12-30 07:08:56

标签: boost parameters

当我运行下面的代码时,我得到以下错误(在kubuntu 12.04上运行的boost版本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?
   )
  )
{
}

1 个答案:

答案 0 :(得分:0)

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