实现find相关功能的boost::mpl模块测试程序

353 篇文章 ¥29.90 ¥99.00
本文介绍了如何利用Boost的mpl模块实现find功能的元编程,通过定义metafunction查找序列中的特定类型,并给出测试程序示例,展示了在C++中进行元编程的可能性。

实现find相关功能的boost::mpl模块测试程序

Boost是C++社区中非常流行的一个开源库,其中的mpl模块为元编程提供了丰富的工具和支持。在这篇文章中,我们将使用mpl模块实现find相关的功能,并提供测试程序。

在mpl模块中,我们可以使用find算法来查找序列中的元素。它的使用方法如下:

#include <boost/mpl/find.hpp>
#include <boost/mpl/vector.hpp>

using namespace boost::mpl;

typedef vector<int, char, float> vec;
typedef find<vec, char>::type iterator; // 返回char所在的迭代器类型

上述代码中,我们定义了一个包含int、char和float三种类型的vector,然后使用find算法来查找其中的char类型,并返回其迭代器类型。

下面,我们来看看如何实现一个类似的find算法。我们需要定义一个metafunction,接受两个参数——一个序列和一个查找类型。该metafunction会返回查找类型在序列中的迭代器类型。具体代码如下:

#include <boost/mpl/find.hpp>
#include <boost/mpl/iterator_range.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/distance.hpp>

using namespac
一直出现这种报错是为什么/usr/include/boost/mpl/aux_/preprocessed/gcc/plus.hpp:68:8: note:boost::mpl::plus’ 68 | struct plus | ^~~~ In file included from /usr/include/pcl-1.10/pcl/point_types.h:44, from /usr/include/pcl-1.10/pcl/common/impl/copy_point.hpp:41, from /usr/include/pcl-1.10/pcl/common/copy_point.h:58, from /usr/include/pcl-1.10/pcl/common/impl/io.hpp:45, from /usr/include/pcl-1.10/pcl/common/io.h:586, from /usr/include/pcl-1.10/pcl/io/file_io.h:41, from /usr/include/pcl-1.10/pcl/io/pcd_io.h:44, from /opt/ros/noetic/include/pcl_conversions/pcl_conversions.h:70, from /home/nonobody/catkin_ws/src/grid_path_searcher/src/demo_node.cpp:4: /usr/include/pcl-1.10/pcl/point_types.h:535:1: error: ‘plus’ is not a member of ‘pcl::traits’ 535 | POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::MomentInvariants, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/pcl-1.10/pcl/point_types.h:535:1: note: suggested alternatives: In file included from /usr/include/c++/9/string:48, from /usr/include/c++/9/bits/locale_classes.h:40, from /usr/include/c++/9/bits/ios_base.h:41, from /usr/include/c++/9/ios:42, from /usr/include/c++/9/ostream:38, from /usr/include/c++/9/iostream:39, from /home/nonobody/catkin_ws/src/grid_path_searcher/src/demo_node.cpp:1: /usr/include/c++/9/bits/stl_function.h:167:12: note: ‘std::plus’ 167 | struct plus : public binary_function<_Tp, _Tp, _Tp> | ^~~~ In file included from /usr/include/boost/mpl/aux_/include_preprocessed.hpp:37, from /usr/include/boost/mpl/aux_/arithmetic_op.hpp:34, from /usr/include/boost/mpl/plus.hpp:19, from /usr/include/boost/mpl/vector/aux_/iterator.hpp:19, from /usr/include/boost/mpl/vector/aux_/vector0.hpp:22, from /usr/include/boost/mpl/vector/aux_/clear.hpp:18, from /usr/include/boost/mpl/vector/vector0.hpp:24, from /usr/include/boost/mpl/vector/vector10.hpp:18, from /usr/include/boost/mpl/vector/vector20.hpp:18, from /usr/include/boost/mpl/vector.hpp:36, from /usr/include/boost/math/policies/policy.hpp:14, from /usr/include/boost/math/policies/error_handling.hpp:21, from /usr/include/boost/math/special_functions/round.hpp:14, from /opt/ros/noetic/include/ros/time.h:58, from /opt/ros/noetic/include/ros/ros.h:38, from /opt/ros/noetic/include/pcl_conversions/pcl_conversions.h:42, from /home/nonobody/catkin_ws/src/grid_path_searcher/src/demo_node.cpp:4:
08-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值