Is Boost.Phoenix slower than the lambdas equivalent of C ++ 11 (does it use virtual calls, "mutable" usage, etc.)?

I always thought Boost.Phoenix used type-output to do 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 received a warning:

warning C4239: non-standard extension is used: 'argument': conversion from const char [3] to volatile const boost::proto::detail::anyns::any &
A non-constant link can only be bound to an lvalue

It surprised me. I did not expect to see any anywhere, much less volatile !

Does this mean that Boost.Phoenix is ​​actually inherently slower than its equivalent C ++ 11 lambdas (ignoring the specific compiler that I use here)?

+6
source share
2 answers

This is not Boost.Any , it is any of the Boost.Proto implementation details - see boost/proto/detail/decltype.hpp . It has zero overhead.

+2
source

I would expect Boost.Phoenix to be slower than the equivalent C ++ 11 lambda. The bind function takes the address of the function to call later, so the compiler will have a much more complicated time inserting the resulting function call than if you were using a lambda that directly called the required function.

The overhead that I have in mind here is the overhead of indirectly calling a function, a compiler with enough confidence can remove it, but I'm not sure if any compiler really does this for Boost.Phoenix.

0
source

Source: https://habr.com/ru/post/921037/


All Articles