gpt4 book ai didi

c++ - boost fusion : strange problem depending on number of elements on a vector

转载 作者:搜寻专家 更新时间:2023-10-31 01:59:55 25 4
gpt4 key购买 nike

我正在尝试在个人项目中使用 Boost::Fusion (Boost v1.42.0)。这段代码出现了一个有趣的错误:

#include "boost/fusion/include/sequence.hpp"
#include "boost/fusion/include/make_vector.hpp"
#include "boost/fusion/include/insert.hpp"
#include "boost/fusion/include/invoke_procedure.hpp"
#include "boost/fusion/include/make_vector.hpp"
#include <iostream>

class Class1
{
public:
typedef boost::fusion::vector<int,float,float,char,int,int> SequenceType;
SequenceType s;
Class1(SequenceType v):s(v){}
};

class Class2
{
public:
Class2(){}
void met(int a,float b ,float c ,char d ,int e,int f)
{
std::cout << a << " " << b << " " << c << " " << d << " " << e << std::endl;
}
};

int main(int argn, char**)
{
Class2 p;
Class1 t(boost::fusion::make_vector(9,7.66f,8.99f,'s',7,6));
boost::fusion::begin(t.s); //OK
boost::fusion::insert(t.s, boost::fusion::begin(t.s), &p); //OK
boost::fusion::invoke_procedure(&Class2::met,boost::fusion::insert(t.s, boost::fusion::begin(t.s), &p)); //FAILS
}

编译失败(gcc 4.4.1):

In file included from /home/thechaos/Escriptori/of_preRelease_v0061_linux_FAT/addons/ofxTableGestures/ext/boost/fusion/include/invoke_procedur
e.hpp:10,
from problema concepte.cpp:11:
/home/thechaos/Escriptori/of_preRelease_v0061_linux_FAT/addons/ofxTableGestures/ext/boost/fusion/functional/invocation/invoke_procedure.hpp: I
n function ‘void boost::fusion::invoke_procedure(Function, const Sequence&) [with Function = void (Class2::*)(int, float, float, char, int, in
t), Sequence = boost::fusion::joint_view<boost::fusion::joint_view<boost::fusion::iterator_range<boost::fusion::vector_iterator<const boost::f
usion::vector<int, float, float, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_>, 0>,
boost::fusion::vector_iterator<boost::fusion::vector<int, float, float, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fus
ion::void_, boost::fusion::void_>, 0> >, const boost::fusion::single_view<Class2*> >, boost::fusion::iterator_range<boost::fusion::vector_iter
ator<boost::fusion::vector<int, float, float, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion:
:void_>, 0>, boost::fusion::vector_iterator<const boost::fusion::vector<int, float, float, char, int, int, boost::fusion::void_, boost::fusion
::void_, boost::fusion::void_, boost::fusion::void_>, 6> > >]’:
problema concepte.cpp:39: instantiated from here
/home/thechaos/Escriptori/of_preRelease_v0061_linux_FAT/addons/ofxTableGestures/ext/boost/fusion/functional/invocation/invoke_procedure.hpp:88
: error: incomplete type ‘boost::fusion::detail::invoke_procedure_impl<void (Class2::*)(int, float, float, char, int, int), const boost::fusio
n::joint_view<boost::fusion::joint_view<boost::fusion::iterator_range<boost::fusion::vector_iterator<const boost::fusion::vector<int, float, f
loat, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_>, 0>, boost::fusion::vector_itera
tor<boost::fusion::vector<int, float, float, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::
void_>, 0> >, const boost::fusion::single_view<Class2*> >, boost::fusion::iterator_range<boost::fusion::vector_iterator<boost::fusion::vector<
int, float, float, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_>, 0>, boost::fusion:
:vector_iterator<const boost::fusion::vector<int, float, float, char, int, int, boost::fusion::void_, boost::fusion::void_, boost::fusion::voi
d_, boost::fusion::void_>, 6> > >, 7, true, false>’ used in nested name specifier

但是,如果我将 vector 和方法中的参数数量从 6 更改为 5 从 int,float,float,char,int,intint,float,float ,char,int,我可以毫无问题地编译它。

我怀疑参数的最大数量是一个限制,但我试图通过定义 FUSION_MAX_VECTOR_SIZE 来更改它,但没有成功。

我看不出我做错了什么。你能重现这个吗?会不会是 boost 错误(我怀疑但并非不可能)?

最佳答案

确实是的,您需要更改一些迭代限制。你只是换错了。 :)

你需要定义的是BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY;默认情况下,它是 6。您显然需要 7(但也可以将其增加到 10):

#define BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY 10

#include "boost/fusion/include/sequence.hpp"
#include "boost/fusion/include/make_vector.hpp"
#include "boost/fusion/include/insert.hpp"
#include "boost/fusion/include/invoke_procedure.hpp"
#include "boost/fusion/include/make_vector.hpp"
#include <iostream>
.
.
.

three total在调用域内。

每当您要查找某物的极限时,请在 documentation 上搜索“极限” .选择与您正在做的事情相关的一项。从那里,它会告诉您默认值和选项。


就代码本身而言,我应该指出有一个 push_front功能:

#include "boost/fusion/include/push_front.hpp"

// ...

boost::fusion::invoke_procedure(&Class2::met,
boost::fusion::push_front(t.s, &p));

因此您无需执行更冗长的 insert-at-begin。

关于c++ - boost fusion : strange problem depending on number of elements on a vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2547787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com