0

What is the equivalent of Boost::Phoenix's ref in Boost::Lambda? I can't find it in the online docs.

#include <algorithm>
#include <string>
#include <boost/lambda/bind.hpp>
using namespace boost::lambda;

int main()
{
    std::string a, b;
    std::for_each(b.begin(), b.end(), ref(a) += _1);  // how do I do this?
}

boost::ref and boost::lambda::var don't seem to work (they don't have the operator overloads, apparently).

user541686
  • 205,094
  • 128
  • 528
  • 886
  • I hope you know that Boost.Lambda is superseded by Boost.Bind which, in turn, is superseded by Boost.Phoenix. So, why are you using Boost.Lambda? – Xeo Sep 02 '12 at 02:56
  • @Xeo: Yes, I definitely know. I use BLL because Boost.Bind isn't a substitute for BLL at all, as far as I can see. And Boost.Phoenix is *very* slow at compiling (and it also pauses the IDE for long periods if there is highlighted text). BLL has all the features I need without the slowness. How do you cope with Phoenix's compile times? – user541686 Sep 02 '12 at 03:11
  • Boost.Bind's placeholders are improved versions of BLL's ones, IIRC. And fact is, I didn't use Phoenix yet, so good to know about its slow compile tile (though it's kinda expected, it's part of Spirit after all...). – Xeo Sep 02 '12 at 04:05
  • @Xeo: The only thing Bind can do is, well, `bind`. I don't think you can do anything like `ref(a)` in Bind, and it only gets worse from there. And yeah, Phoenix is slow. It's better if you have it in a precompiled header, but the IDE (Visual Studio in my case) can still slow down and get very annoying. And I change my precompiled header often enough that it's still annoying. IMO don't tell people to switch to a library (or make them explain why they aren't switching) if you haven't actually used it. ;) – user541686 Sep 02 '12 at 04:19
  • Oh, I like to tell people what the docs say and then ask why they are doing something else - brings insight. :) It wasn't meant in any negative way. – Xeo Sep 02 '12 at 12:52

1 Answers1

1

D'oh, I just figured it out...

Just #include <boost/lambda/lambda.hpp> and then var will work!

Community
  • 1
  • 1
user541686
  • 205,094
  • 128
  • 528
  • 886