1

我有一个使用 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  \boost\utility\result_of.hpp  80
Error  2  error C2039: 'type' : is not a member of 'boost::result_of<F>'  \boost\phoenix\core\detail\preprocessed\function_eval_10.hpp  121
Error  3  error C2146: syntax error : missing ';' before identifier 'type'  \boost\phoenix\core\detail\preprocessed\function_eval_10.hpp  122
Error  4  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  \boost\phoenix\core\detail\preprocessed\function_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>'  \boost\phoenix\core\detail\preprocessed\function_eval_10.hpp  122
Error  6  error C2868: 'boost::phoenix::detail::function_eval::result<Sig>::type' : illegal syntax for using-declaration; expected qualified-name  \boost\phoenix\core\detail\preprocessed\function_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 );

实现此功能的正确方法是什么?

谢谢

4

1 回答 1

1

使用 Boost 1.48,您的代码片段可以使用 GCC 4.7 编译,前提是我有正确的包含,并且至关重要的是,前提BOOST_RESULT_OF_USE_DECLTYPE是定义了宏。没有后者,它就会失败。

不知道如何在没有 C++11 的情况下解决这个问题。

于 2012-06-11T22:39:19.427 回答