Extending namespace std to implement make_unique when using C++11

No, this is forbidden—even though, via

#define make_unique ? ? ?

a conforming C++11 program can be quite sure that the library never mentions the name (outside of a stringization) and would thus be unable to detect the extension.


The approach I've taken in this case is slightly different:

#if __cplusplus < 201402L

namespace std14 {
  ...
}

#else
     using namespace std14 = std;
#endif

Then you write your code like:

auto foo = std14::make_unique<T>(whatever);

...and for now it'll use your implementation of make_unique, but when/if you start using a C++14 compiler, it'll use the implementation provided by the compiler.

Tags:

C++

C++11

C++14