我正在尝试使用boost :: fusion :: vector。但是,我遇到了这个非常简单的问题。apply boost :: fusion :: for_each boost :: fusion :: vector with mutable function object
#include <iostream>
#include <string>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/algorithm.hpp>
using namespace std;
struct A{
template <class T>
void operator()(const T& t) {
x++;
cout << t << endl;
}
int x = 0;
};
int main(){
A a;
boost::fusion::vector<int, int, int> tuple{3,4,5};
boost::fusion::for_each(tuple, a);
}
注意的struct A
的operator()
修改了struct A
x
。 gcc 4.7.2警告...... \ include \ boost \ fusion \ algorithm \ iteration \ detail \ for_each.hpp:77:error:将'const A'作为'void'传递给'void A :: operator() (const T &)[with T = int]'丢弃限定符[-fpermissive]
有没有解决方案?
感谢。其实,问题是关于迭代元组并应用可以修改的函数对象。从你的回答中,我想我不能使用boost :: fusion来达到这个目的。我对吗? – Sungmin 2013-02-27 05:25:55
@Sungmin:解决方法是可能的,检查出更新 – 2013-02-27 07:37:21
感谢您的帮助:) – Sungmin 2013-02-27 08:06:24