r...@zedat.fu-berlin.de (Stefan Ram) wrote in news:make_unique-
2015042...@ram.dialup.fu-berlin.de:
> Victor Bazarov <v.ba...@comcast.invalid> writes:
>>On 4/19/2015 7:30 PM, Stefan Ram wrote:
>>>Can one define a function only in the case that a function
>>>is not declared?
> ...
>>What problem are you trying to solve?
>
> I want to write my code (e.g. for my tutorial) already in
> the C++14 style, e.g., using »::std::make_unique« instead
> of »::std::unique( new ...«.
>
> Some implementations do not already supply »make_unique«,
> so I thought about adding some lines at the top that define
> »make_unique« if it's not declared at this point.
>
This is typically done by a lot of preprocessor hackery. Here is a small
excerpt from such a hackery, meant for defining std::move when it is not
present. Such a mechanism provides a way to cope also with other mising
features, not only missing function definitions.
#ifdef __GNUC__
#define HAVE_COMPILER_GCC
#endif
// ...
#ifdef HAVE_COMPILER_GCC
#if __GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3) // gcc 4.3
#define HAVE_C11_STATIC_ASSERT
// ...
#endif
#if __GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=4) // gcc 4.4
#define HAVE_C11_RVALUE_REFERENCES
// ...
#endif
#if __GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=5) // gcc 4.5
#define HAVE_C11_LAMBDA
// ...
#endif
// ...
#endif
// ...
#ifndef HAVE_C11_RVALUE_REFERENCES
// provide dummy std::move() for pre-c++1x compilers
// which do not have one.
namespace std {
template<class T> T move(const T& x) {return x;}
}
#endif