5

I'm currently migrating from Visual Studio 2008 to 2010. My software makes heavy use of Boost and its TR1 features. I now get a lot of compiler errors, because VC10 has it's own TR1 implementation.

I know I can disable Microsoft's TR1 implementation with the _HAS_CPP0X switch (see here), but I'm not sure if this also disables other features that could be interesting in the future.

So, I'm wondering which is the better implementation of TR1: the one from Boost or the one from Microsoft? Are there any differences at all? Does disabling the Microsoft implementation have any disadvantages?

Community
  • 1
  • 1
Michel Krämer
  • 14,197
  • 5
  • 32
  • 32
  • Not that this is the answer you are looking for... If you disable the Microsoft tr1, you can't compile without boost. If you use boost, you can be assured you'll have a steady upgrade path, and your code will compile outside MSVC. That, and boost has way more features than just the ones in TR1 :) – Merlyn Morgan-Graham Aug 17 '10 at 20:45
  • What's the precise error, duplicate definitions? – MSalters Aug 18 '10 at 08:55
  • Yes, the precise error is duplicate definitions. It also has something to do with ADL. If I qualify every occurance of bind or _1 (std::bind and std::tr1::placeholders::_1) the code will soon become very nasty :) – Michel Krämer Aug 18 '10 at 16:20
  • @Michael: See [this answer](http://stackoverflow.com/questions/2879555/c-stl-how-to-write-wrappers-for-cout-cerr-cin-and-endl/2880136#2880136) for why I think explicitly qualifying identifiers with their namespaces is seriously underrated and easier than most people (who have never tried it) think. – sbi Aug 19 '10 at 05:44

2 Answers2

1

If your code doesn't compile with VC10's standard library, then that might indicate that it isn't standard-conforming. The standard library in VC10 comes from Dinkumware, and these guys aren't bad when it comes to implementing a standard library. (PJP used to be the lib working group's chair.) I'd look very closely at each issue, before dismissing it as a VC-specific problem, lest you might not be future-compatible.

Also, TTBOMK, VC10 doesn't just come with TR1, but with C++1x (e.g., std::shared_ptr instead of std::tr1::shared_ptr; ICBWT), so boost's and VC10's libraries actually aren't fully comparable.

sbi
  • 219,715
  • 46
  • 258
  • 445
  • Have you checked their list implementation? I have not looked the one came with vs2010, but before that all had linear complicity for splicing. – leiz Aug 17 '10 at 21:41
  • 1
    @leiz: No , I haven't. (I rarely ever ended up using a list, even when I started doing so. Usually, vector turns out to be better.) But I was saying that, when code doesn't even _compile_ using it, I would look really closely before dismissing this as a problem with the library implementation, rather than a problem with the code, because, _generally_, their implementation is pretty good. That doesn't mean, however, that I think there are _no problems at all_ in Dinkumware's implementation. Dinkumware is run by humans. – sbi Aug 17 '10 at 22:22
  • @leiz: C++0x now specifies that `splice` should be O(1) and authorizes `size` to be O(n) for list (because the two are incompatible), I don't know whether or not it was the case for C++03. – Matthieu M. Aug 18 '10 at 08:26
  • "If your code doesn't compile with VC10's standard library, then that might indicate that it isn't standard-conforming." It conforms to neither C++03 or C++11. There are completely absurd stuff in the C++11 side (`multimap::emplace_hint` doesn't return a pair, the `emplace_back` is broken, `std::result_of` doesn't use `decltype`, etc), and on the C++03 side, well it can't be conformant since eg. `std::vector` [has changed behaviour](http://stackoverflow.com/questions/5759232/stdvector-default-construction-c11-and-breaking-changes). However things have improved (eg. set iterators) since VC8. – Alexandre C. Jul 30 '12 at 20:38
0

First of:
You should be able to use Boost and TR1 side by side. If everything is configured correctly and you're not messing around with using namespace you won't get any errors.

C++11 provides features like the auto keyword (more info) or initialization of class attributes during their declaration (more info) that Boost can't provide.

On the other side Boost provides a lot more than just their implementation of C++11 features. Essentially Boost is a collection of libraries which are considered to be added to the C++ standard.

When it comes to features which both provide (like shared_ptr) I would recommend using Boost:

  • Boost compiles with compilers which do not support certain C++11 features
  • You have a clear dependency instead of just relaying on C++11 (which most compilers implement different)
  • Boost datatypes (e.g. shared_ptr) are compatible with other Boost features like serialization.

My suggestion is to use C++11 just if you absolutely need it and Boost in all other cases.

MOnsDaR
  • 8,401
  • 8
  • 49
  • 70