0

In order to add new functionality to an old C++ application I need to include code that uses std::unique_ptr. The application is built with VS2008 and the included version of the c++-standard library does not include std::unique_ptr.

Is there a version of c++-standard library that compiles on VS2008 and does include std::unique_ptr?

Alternatively, is there a way to replicate its functionality?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
sdmorris
  • 339
  • 1
  • 7
  • 18
  • 2
    Use an up to date compiler, that supports the c++11 standard. – πάντα ῥεῖ Feb 06 '17 at 19:05
  • 2
    You can't - unique_ptr is not implementable in older versions of C++. –  Feb 06 '17 at 19:07
  • Upgrade to MSVS 2015 update 3 at least. – NathanOliver Feb 06 '17 at 19:07
  • Use `boost::unique_ptr`. The boost library has many facilities that become available to VS 2008 that exist for C++ 11 and above. Not everything mind you, but for unique_ptr, it is there. – PaulMcKenzie Feb 06 '17 at 19:08
  • @NeilButterworth Nitpick: To be precise, it's not **fully** implementable with pre c++11 standards, because of lacking the `std::move()` feature. No? – πάντα ῥεῖ Feb 06 '17 at 20:07
  • Unfortunately, updating the compiler is not an option. I started to convert the application to 2015. However, that required newer versions of several of the support libraries. One, wxWidgets, is no longer compatible with the original code and I found that I was having to make extensive changes that risk the stability of the product. – sdmorris Feb 07 '17 at 12:46

1 Answers1

0

In order to add new functionality to an old C++ application I need to include code that uses std::unique_ptr.

You cannot do that directly. Your only option is to backport that code. I'll mention your options to do that below.

Is there a version of STL that compiles on VS2008 and does include std::unique_ptr?

Not that I'm aware of one (see here as well please). Also I suppose you mean the c++-standard library and not the STL (which is a pre-standard c++ implementation that was provided back in the 90ies of the last century).

Alternatively, is there a way to replicate its functionality?

There are two (reasonable) options for creating a backport of code using std::unique_ptr:

  1. A similar functionality is provided with the old standards std::auto_ptr, but it has some deficiencies compared to std::uniqe_ptr.

  2. You may try boost::unique_ptr which was a pre c++11 standard implementation.
    This implementation fixes a number of the flaws provided with the std::auto_ptr, but lacks real moving still (with older boost versions that are VS2008 compatible).

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190