Boost.Phoenix本质上比等效的C ++ 11 lambdas慢(它使用虚拟调用,'volatile'用法等)吗?

时间:2012-07-21 20:39:04

标签: c++ visual-c++ boost lambda boost-phoenix

我一直认为Boost.Phoenix使用类型推断来静态推断所有内容,直到我尝试这段代码:

#include <vector>
#include <boost/phoenix/phoenix.hpp>

using namespace boost::phoenix;
using namespace boost::phoenix::placeholders;

struct Foo { int x; };

int main()
{
    std::vector<int> bar;
    bind(&Foo::x, ref(bar)[_1])("invalid index");   // oops
    return 0;
}

并收到警告:

  

警告C4239:使用非标准扩展名:&#39;参数&#39; :从const char [3]转换为volatile const boost::proto::detail::anyns::any &
         非const引用只能绑定到左值

这令我感到惊讶。我没想到会any看到volatile,更不用说了{{1}}!

这是否意味着Boost.Phoenix实际上本质上比其等效的C ++ 11 lambdas慢(忽略我在这里使用的特定编译器)?

2 个答案:

答案 0 :(得分:2)

它不是Boost.Anyany来自Boost.Proto实施细节 - 请参阅boost/proto/detail/decltype.hpp。它没有运行时开销。

答案 1 :(得分:0)

我希望Boost.Phoenix比同等的C ++ 11 lambda慢。 bind函数将稍后调用函数的地址,因此编译器在内联函数调用时比使用直接调用所需函数的lambda要困难得多。

我在这里引用的开销是对函数的间接调用的开销,Sufficiently Smart Compiler可以删除它,但我不确定是否有任何编译器实际上为Boost.Phoenix执行此操作。