c++ - boost::fusion::zip 函数与 boost::fusion::zip_view

标签 c++ boost boost-fusion

我正在努力学习 boost fusion,但我不清楚 zip_view 和 zip 函数结果之间的区别。

namespace fuz = boost::fusion;

typedef fuz::vector<int,int> vec1;
typedef fuz::vector<char,char> vec2;
typedef fuz::vector<vec1&, vec2&> sequences;

typedef fuz::zip_view<sequences> zip_view_type;

typedef fuz::result_of::zip<vec1, vec2>::type zip_result_type;

BOOST_MPL_ASSERT((boost::is_same<zip_view_type, zip_result_type>));
  • 我原以为这两种类型是相同的,但事实并非如此。为什么?

  • zip_view 和 zip 函数似乎关系密切,但我不知道 查看何时/为何使用 View 而不是函数。

最佳答案

我希望我能回答你的第二个问题(为什么使用 zip_view 而不是 zip )。

问题是zip生成一个元组序列,其中包含对压缩序列的各个元素的常量 引用。在您的示例中,它是 vector2<const int&, const char&>

相比之下,zip_view 生成的元组中的引用对于每个元素都具有与 View 构造函数中的压缩序列相同的 const 限定符。它将是 vector<int&, char&>在你的情况下。

因此,zip_view允许 zip 的东西不支持:

  1. 修改压缩序列的元素;
  2. 选择要修改的序列。

关于c++ - boost::fusion::zip 函数与 boost::fusion::zip_view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20196558/

相关文章:

c++ - 常见对话框 Win32

c++ - vkGetPhysicalDeviceQueueFamilyProperties 段错误

c++ - 如何抑制 boost serialization::archive 中的额外信息?

c++ - 在使用 boost::fusion 迭代时将 pretty-print 绑定(bind)到 boost::phoenix actors

c++ - 如何在运行时填充 boost::fusion::vector?

c++ 识别参数包中的第一个参数是否为与类型 T 分配兼容的指针

c++ - 如何使用 WinPcap 发送/注入(inject)数据包

c++ - booster::noncopyable 的用例是什么?

c++ - 调试错误 R6010 - 已调用 abort()

c++ - 单成员结构的灵气属性传播问题