增强融合:奇怪的问题取决于向量上的元素数量

发布于 2024-08-27 11:49:32 字数 4291 浏览 9 评论 0 原文

我正在尝试在个人项目中使用 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

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

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

我看不出我做错了什么。你能重现这个吗?这可能是一个提升错误(我对此表示怀疑,但并非不可能)?

I am trying to use Boost::Fusion (Boost v1.42.0) in a personal project. I get an interesting error with this code:

#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
}

It fails to compile (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

However, if I change the number of arguments in the vectors and the method from 6 to 5 from int,float,float,char,int,int to int,float,float,char,int,I can compile it without problems.

I suspected about the maximum number of arguments being a limitation, but I tried to change it through defining FUSION_MAX_VECTOR_SIZE without success.

I am unable to see what am I doing wrong. Can you reproduce this? Can it be a boost bug (i doubt it but is not impossible)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不离久伴 2024-09-03 11:49:32

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

您需要定义的是 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>
.
.
.

调用域内总共三个

每当您寻找某物的极限时,请在 文档。选择与您正在做的事情相关的一项。从那里,它会告诉您默认值以及选项是什么。


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

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

// ...

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

所以你不需要在开始时执行更详细的插入操作。

Yes indeed, you need to change some iteration limits. You're just changing the wrong one. :)

What you need to define is BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY; by default, it is 6. You obviously need 7 (but might as well bump it to 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>
.
.
.

There are three total within the invocation domain.

Whenever you're looking for the limit of something, search for "Limits" on the documentation. Choose the one relevant to what you're doing. From there, it tells you the defaults and what the options are.


Just concerning the code itself, I should point out there is a push_front function:

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

// ...

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

So you don't need to do the more verbose insert-at-begin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文