Is Boost.Phoenix inherently slower than the equivalent C++11 lambdas (does it use virtual calls, 'volatile' usage, etc.)?
Asked Answered
Y

2

6

I always thought Boost.Phoenix used type-inference to infer everything statically, until I tried this code:

#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;
}

and got the warning:

warning C4239: nonstandard extension used : 'argument' : conversion from const char [3] to volatile const boost::proto::detail::anyns::any &
A non-const reference may only be bound to an lvalue

That surprised me. I didn't expect to see any anywhere, much less volatile!

Does that mean Boost.Phoenix is therefore actually inherently slower than its equivalent C++11 lambdas (ignoring the particular compiler I'm using here)?

Yeomanry answered 21/7, 2012 at 20:39 Comment(0)
B
2

It's not Boost.Any, it's any from Boost.Proto implementation details - please see boost/proto/detail/decltype.hpp . It has zero run-time overhead.

Boneset answered 22/7, 2012 at 13:22 Comment(1)
+1 thanks for pointing that out. What about volatile though?Yeomanry
E
0

I would expect Boost.Phoenix to be slower than the equivalent C++11 lambda. The bind function takes the address of a function to call later on, so the compiler would have a much harder time inlining the resulting function call than if a lambda were used that directly called the required function.

The overhead that I am referring to here is the overhead of an indirect call to a function, a Sufficiently Smart Compiler could remove it, but I'm not sure if any compiler actually does this for of Boost.Phoenix.

Endplay answered 28/2, 2013 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.