使用 boost.phoenix 容器算法
using boost.phoenix container algorithms
我有一个使用 boost 1.47 phoenix 的 Visual Studio 2008 C++03 应用程序(更新:也使用 1.49)。我想定义一个 boost::function 来从列表中删除元素。例如:
#include <boost/phoenix.hpp>
#include <boost/function.hpp>
#include <boost/phoenix/stl/container.hpp>
#include <boost/phoenix/stl/algorithm/transformation.hpp>
#include <algorithm>
#include <list>
int main()
{
namespace bp = boost::phoenix;
namespace bpa = boost::phoenix::arg_names;
std::list< int > a;
boost::function< void( int ) > RemoveFromList = bp::remove( bp::ref( a ), bpa::arg1 );
return 0;
}
但我在RemoveFromList
定义上收到一系列编译器错误。
Error 1 error C2504: 'boost::phoenix::impl::remove::result<Sig>' : base class undefined boostutilityresult_of.hpp 80
Error 2 error C2039: 'type' : is not a member of 'boost::result_of<F>' boostphoenixcoredetailpreprocessedfunction_eval_10.hpp 121
Error 3 error C2146: syntax error : missing ';' before identifier 'type' boostphoenixcoredetailpreprocessedfunction_eval_10.hpp 122
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int boostphoenixcoredetailpreprocessedfunction_eval_10.hpp 122
Error 5 error C2602: 'boost::phoenix::detail::function_eval::result<Sig>::type' is not a member of a base class of 'boost::phoenix::detail::function_eval::result<Sig>' boostphoenixcoredetailpreprocessedfunction_eval_10.hpp 122
Error 6 error C2868: 'boost::phoenix::detail::function_eval::result<Sig>::type' : illegal syntax for using-declaration; expected qualified-name boostphoenixcoredetailpreprocessedfunction_eval_10.hpp 122
一个类似的函数AddToList
编译干净:
boost::function< void( int ) > AddToList = bp::push_back( bp::ref( a ), bpa::arg1 );
这也工作正常(但不太优雅):
boost::function< void( int ) > RemoveFromList = bp::bind( &std::remove< std::list< int >::iterator, int >, a.begin(), a.end(), bpa::arg1 );
实现此功能的正确方法是什么?
谢谢
使用
Boost 1.48,您的代码片段使用 GCC 4.7 进行编译,前提是我有正确的包含,并且至关重要的是,前提是定义了宏BOOST_RESULT_OF_USE_DECLTYPE
。没有后者,它就会失败。
不知道如何在没有 C++11 的情况下解决这个问题。
相关文章:
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 基于ELO的团队匹配算法
- C++选择排序算法中的逻辑错误
- 有没有办法将谓词中的元素偏移量传递给 std 算法?
- C++A*算法并不总是在路径中具有目标节点
- 排序算法c++
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 算法问题:查找从堆栈中弹出的所有序列
- 下面是排序算法O(n)吗
- KMP算法和LPS表构造的运行时间
- 为什么我的排序算法会更改数组值
- 求最大元素位置的分治算法
- 具有非整数边容量的最大流量的Dinic算法
- 到连接组件算法的问题(递归)
- STL算法函数在多个一维容器上的使用
- 读取最后一行代码算法 - c++ 时出现问题
- 括号更改 O(n) 算法
- std::unordered_map 搜索算法是如何实现的?
- 如何实现高效的算法来计算大型数据集的多个不同值?
- 使用 boost.phoenix 容器算法