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....

ただし、最大 5 つのパラメーターで問題なく動作します。便利な機能だと思うので、これを実行するといいでしょう。これはよく知られた制限ですか、それとも正しく使用していませんか?

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

Boost.Parameterの関数の引数の最大数は#define BOOST_PARAMETER_MAX_ARITY n、ヘッダーを含める前に(この場合はn = 6)を使用して構成できます。このパラメーターのデフォルト値は5、ブースト1.49より前です。値は8その後です。この数を増やすと、プログラムのコンパイル時間に影響すると思います。したがって、任意に高くするのではなく、必要な値に設定する必要があります。

于 2012-12-30T11:52:33.927 に答える