融合矢量投影
Fusion vector projection
我有一个融合向量,其中包含具有多个不同类型成员数据的元素,我想创建一个新的融合向量,该向量将只投影特定的数据成员。我对此已经研究了一段时间,但没有任何进展。
#include <iostream>
#include <string>
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <boost/fusion/include/fold.hpp>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/algorithm.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/bind.hpp>
namespace phx = boost::phoenix;
namespace fusion = boost::fusion;
using namespace phx::arg_names;
struct mprint
{
template<typename T>
void operator()(T& t) const
{
std::cout << t << std::endl;
}
};
struct TStruct
{
std::string val1_;
double val2_;
int val3_;
bool val4_;
TStruct( const std::string &val1, double val2, int val3, bool val4 ) :
val1_(val1), val2_(val2), val3_(val3), val4_(val4) { }
};
template <typename Sequence>
void viewVal1( const std::string &dummy,const Sequence& args )
{
fusion::for_each( boost::tie(phx::bind(&TStruct::val1_, arg1)(args)), mprint() );
}
template <typename Sequence>
void viewVal2( const std::string &dummy,const Sequence& args )
{
//fusion::for_each( boost::tie(phx::bind(&TStruct::val2_, arg1)(args)), mprint() );
}
int main( int argc, char* argv[] )
{
auto mdata = fusion::make_vector(
TStruct( "test1", 2.3, 1, true ),
TStruct( "test2", 3.3, 2, false ),
TStruct( "test3", 4.3, 3, true )
);
viewVal1( "dummy", mdata );
viewVal2( "dummy", mdata );
return 0;
}
我认为(意思是我不确定)您需要使用的是fusion::transform_view
:
在Coliru:上运行
#include <iostream>
#include <string>
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <boost/fusion/include/fold.hpp>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/algorithm.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/bind.hpp>
namespace phx = boost::phoenix;
namespace fusion = boost::fusion;
using namespace phx::arg_names;
struct mprint
{
template<typename T>
void operator()(const T& t) const
{
std::cout << t << std::endl;
}
};
struct get_val1
{
template <typename T>
std::string operator()(const T& t) const
{
return t.val1_;
}
};
struct TStruct
{
std::string val1_;
double val2_;
int val3_;
bool val4_;
TStruct( const std::string &val1, double val2, int val3, bool val4 ) :
val1_(val1), val2_(val2), val3_(val3), val4_(val4) { }
};
template <typename Sequence>
void viewVal1( const std::string &dummy, Sequence& args )
{
typedef fusion::transform_view<Sequence, get_val1> project;
fusion::for_each(project(args,get_val1()), mprint() );
}
template <typename Sequence>
void viewVal2( const std::string &dummy, Sequence& args )
{
typedef fusion::transform_view<Sequence,decltype(phx::bind(&TStruct::val2_,arg1))> project;
fusion::for_each( project(args,phx::bind(&TStruct::val2_, arg1)), mprint() );
}
int main( int argc, char* argv[] )
{
auto mdata = fusion::make_vector(
TStruct( "test1", 2.3, 1, true ),
TStruct( "test2", 3.3, 2, false ),
TStruct( "test3", 4.3, 3, true )
);
viewVal1( "dummy", mdata );
viewVal2( "dummy", mdata );
return 0;
}
相关文章:
- 应用投影矩阵后对象消失
- 使用融合乘法累加实现双精度有多大优势?
- 在其特征向量上投影点云
- 在 OpenGL 中使用透视与正交投影时的光线投射(鼠标拾取)
- 使用加速融合获取结构名称
- 如何检查助推融合序列是否为自适应结构
- 正交投影设置
- 将大端格式的位融合为预期的十进制值,同时忽略第一个位
- 使用 CGAL 将多面体投影到 xy 平面
- 将粒子投影到立方体的表面
- 缩小在正交投影中不起作用
- 使用 GDAL/OGR C++将 GeoTiff 的 XY 点重新投影到纬度/经度
- OpenGL 透视投影裁剪多边形与顶点在视锥体之外 = 错误的纹理映射?
- 生成器用于提升::融合::使用不可复制的值类型进行映射初始化
- 用枚举场和STL容器解析结构,并使用增强精神/融合轻松
- 融合有尾部功能吗?
- 对象 ** 到对象 * 之间的融合
- 增强融合和运行时收集
- OPENCV球形投影:翘曲和不折磨
- 融合矢量投影