使用 boost.phoenix 容器算法

using boost.phoenix container algorithms

本文关键字:算法 phoenix boost 使用      更新时间:2023-10-16

我有一个使用 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 的情况下解决这个问题。