【发布时间】:2013-01-13 16:15:21
【问题描述】:
你知道 boost、poco 中的一个库,它有一个带有签名的函数,例如:
template <typename T> auto vectorize(const std::vector<std::string> & mask, T & t) -> T::iterator
可以这样使用:
struct A {double x; double y; double z;};
auto a = A();
auto it = vectorize({"x","z"}, a);
//and here doing perturbations and increments on a; ideally it is for passing it to another function
我正在重新设计执行此类操作的现有代码(使用在结构内部进行序列化的方法),但我不得不承认我们的版本相当混乱:/
您对此有抽象的想法并使用元组吗? 我目前正在尝试使用枚举来映射元组的字段。
我很确定有人为这种自反容器迭代问题写了一些聪明的东西。 (我希望 boost::fusion 但它只按类型过滤,否则我错过了一个页面)
【问题讨论】:
-
您必须按原样使用
struct A吗?包含的类型是否总是统一的,例如所有双精度类型? -
目前我按原样使用
struct A加上serialize()函数作为成员。为了提供一些背景知识,我有一个与boost::numeric::odeint非常相似的库,并且某些算法必须能够操纵我系统的子状态,就像它是一个向量一样。目前我主要只有double或std::vector<double>(可能某些用户有特定需求),但我想使用boost::unit或带有constexpr 的单元作为其演示文稿中显示的Stroustrup。
标签: c++ boost struct iterator tuples