对 boost.fusion 向量中元素的引用
编辑 - 请忽略 - 问题是围绕一个简单的拼写错误解决的。我需要休息一下。
如何访问对 boost 融合向量元素的引用?
与 boost.tuples 的 tuples::get(variable)
(返回引用)不同,fusion::at_c(variable)
返回一个常量,并且此给我带来困难。
下面说明了我的问题
#include <iostream>
#include <boost/tuple/tuple.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
using namespace boost;
int
main (int ac, char **av)
{
fusion::vector<int, char, std::string> vec(1, 'x', "howdy");
tuples::tuple <int, char, std::string> tup(1, 'x', "howdy");
std::cout<< fusion::at_c<0>(vec)<<std::endl; //outputs 1
std::cout<< tuples::get<0> (tup) <<std::endl; //outputs 1
//fusion::at<0>(vec) = 2; //doesn't compile
tuples::get<0>(tup) = 2; //works fine
std::cout<< fusion::at_c<0>(vec) <<std::endl; //can't make this output 2.
std::cout<< tuples::get<0> (tup) <<std::endl; //outputs 2
}
EDIT - please ignore - the question resolved around a simple typo. I need a break.
How do I access a reference to an element of a boost fusion vector?
Unlike boost.tuples's tuples::get<i>(variable)
(returns a reference), the fusion::at_c<i>(variable)
returns a constant and this causing me difficulties.
The following illustrates my problem
#include <iostream>
#include <boost/tuple/tuple.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
using namespace boost;
int
main (int ac, char **av)
{
fusion::vector<int, char, std::string> vec(1, 'x', "howdy");
tuples::tuple <int, char, std::string> tup(1, 'x', "howdy");
std::cout<< fusion::at_c<0>(vec)<<std::endl; //outputs 1
std::cout<< tuples::get<0> (tup) <<std::endl; //outputs 1
//fusion::at<0>(vec) = 2; //doesn't compile
tuples::get<0>(tup) = 2; //works fine
std::cout<< fusion::at_c<0>(vec) <<std::endl; //can't make this output 2.
std::cout<< tuples::get<0> (tup) <<std::endl; //outputs 2
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能直接执行
fusion::at_c<0>(vec) = 2;
吗?Can't you just do
fusion::at_c<0>(vec) = 2;
?