I recently switched from the Microsoft compiler to GCC. Among many things, I noticed that std::make_unique
became unavailable. This is apparently because make_unique
is not part of C++11 standard, and Microsoft just happened to include it as an extension.
We are planning to move to C++14 soon, but in the mean while I wrote this "shim" function, and put it into std
.
namespace std
{
template<typename T, typename... TArgs>
unique_ptr<T> make_unique(TArgs&&... args)
{
return std::unique_ptr<T>(new T(std::forward<TArgs>(args)...));
}
}
This solved that problem on gcc. However, I imagine it would cause problems back at Microsoft's side, since it would be a duplicate definition.
Is there a way to correctly shim functionality into std, so that it wouldn't cause trouble on different compilers / C++ standards? I looked around and didn't come up with anything. I thought maybe something like an include guard, for specific standard functions?
#ifndef MAKE_UNIQUE_DEFINED
#define MAKE_UNIQUE_DEFINED
// Define make_unique
#endif
Sadly it seems std
doesn't define include guards for specific functions. Is there anything else I can do to make this more correct and compiler / c++ standard agnostic?