views:

101

answers:

2

My company doesn't allow the use of boost (for many stupid reasons, but that's off-topic).

I feel very frustrated having to use raw pointers when I'm used to shared_ptr, weak_ptr and scoped_ptr for personal development.

We're working exclusively with Microsoft compilers (Visual Studio 2010) and I wonder if there was an alternative to those templates that would decrease my pain.

I once heard of std::tr1 but I'm not sure what this is. I believe it is some kind of Microsoft implementation of the next standard but can we rely on it ? What does it provide ? Is there any guarantees ? What headers should be included ?

+7  A: 

With VC10 just use the shared_ptr, weak_ptr and unique_ptr implementations it already provides. All you have to do is to include <memory>.

Georg Fritzsche
Thanks, it seems to work (despite the fact that I had to specify `std::tr1` while the documentation states that `shared_ptr` is in `std`). What will happen when the next `C++` will be implemented by Microsoft. Will they suddenly drop support for `tr1` ? Should I use an alias for the namespace ?
ereOn
@ereOn: That is strange, i don't have any problem using `std::shared_ptr` in VC10 - there should be no need for work-arounds.
Georg Fritzsche
I'm compiling using command-line, with "locally-optimized" makefiles... I wouldn't be surprised if one somehow disabled some features in the common makefiles. Or perhaps it is still using VC8 compiler. Is there a way to bring `std::tr1` into `std` ? (Is it even a good idea ?)
ereOn
Don't mess around with `std::tr1`. It will continue to serve as a warning to future readers that you're still using a pre-standard version of `shared_ptr`.
MSalters
@ereOn: I'd investigate the VC version first via e.g. `_MSC_VER`. In the absence of template aliases there is no completely satisfying solution as far as i know.
Georg Fritzsche
@MSalters: Thanks, it make sense. @Georg Fritzsche: Thanks again for everything.
ereOn
+3  A: 

TR1 is short for Technical Report 1 and are recommendations to the standard committee for new features in the C++ standard. take a look at the header (or other headers that it includes). and if VS2010 implements TR1 there is a good chance you will have the tr1 smart pointers. These should be identical to the Boost smart pointers.

doron
Thanks for the highlights. Indeed, it seems that it provides `shared_ptr`.
ereOn