1

I use boost a lot in my code but have so far refrained from using std::tr1. Now I need a more sophisticated function pointer, like those two can provide. Unfortunately C+11 is not an option yet. I read that boost::function can be tricky with certain compilers e.g. (Visual Studio before 7.1 needs a special portable syntax) but have not found any information on std::tr1::function regarding this subject. Are there any important differences concerning memory usage, speed and compatibility between the two ?

Edit: I am currently using gcc 4.7 but the code should also compile on Visual Studio and preferably also slightly more dated versions like 2005

Martin
  • 4,738
  • 4
  • 28
  • 57
  • Differences regarding memory usage and speed are certainly implementation dependent, so answering that without knowing your platform/compiler is kind of hard. Besides both have a non trivial overhead, so if the performance/memory are really tight you might not want to use either, otherwise I doubt the differences will be big enough to matter. And what exactly do you mean with compatibility? – Grizzly Jul 30 '12 at 20:18

1 Answers1

3

What did you read? What do you mean by tricky? Are you referring to some ancient compilers only supporting the boost::function1<void, int> form rather than boost::function<void(int)> form?

std::tr1::function should be provided by your compiler, so if your compiler provides it at all then it should work perfectly, and not be "tricky" (whatever you mean by that.)

Asking if there are differences between Boost's specific implementation and an interface specification, which is not an implementation, doesn't make sense. One implementation could be similar to Boost's and have no substantial differences and another implementation could be completely different. GCC's std::tr1::function was contributed by the author of Boost.Function, so it's very similar.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • Many thanks, you make good guesses on inaccurate questions. You are quite right about the difference between interface and implementation. Boost is boost but tr1.... Should have given it a second thought – Martin Jul 30 '12 at 21:21
  • 2
    In my experience `boost`, `tr1` and `cxx11` function objects are rather easy to exchange. All of them provide compatibility with the deprecated `unary/binary_function` templates. If you are aiming for pre VS2005, `boost::function` is the way to go. – pmr Jul 30 '12 at 21:22
  • @pmr makes a very good point, I was a bit pedantic - `tr1::function` was based on `boost::function` so they are conceptually very similar, and in practice you probably won't notice differences between most TR1 implementations and Boost.Function. – Jonathan Wakely Jul 30 '12 at 21:43