[cfe-dev] Using unique_ptr in both C++03 and C++11 mode?

Jeffrey Walton noloader at gmail.com
Mon Jul 27 07:43:14 PDT 2015


On Mon, Jul 27, 2015 at 10:37 AM, Jeffrey Walton <noloader at gmail.com> wrote:
> On Mon, Jul 27, 2015 at 10:37 AM, David Chisnall
> <David.Chisnall at cl.cam.ac.uk> wrote:
>> On 27 Jul 2015, at 15:23, Jeffrey Walton <noloader at gmail.com> wrote:
>>>
>>> How do we manage auto_ptr/unique_ptr on Apple platforms under Clang?
>>> What is the secret sauce I am missing?
>>
>> Why are you trying to special-case __APPLE__ at all?  You might want to have different things for libstdc++ / libc++, but that’s not an Apple/everyone else distinction.
>
> Because Apple fiddles with things. I.e., its broke without the Apple
> defines, too.

My apologies if you were implying I should check based on Clang. Here
are the results based on that, too:

// http://marshall.calepin.co/c-and-xcode-46.html
#if (__cplusplus >= 201103L) // C++11
# include <memory>
#elif defined(__clang__) // C++03 and Clang
# include <tr1/memory>
#else // C++03 and everyone else
# include <memory>
#endif

// Manage auto_ptr warnings and deprecation in C++11
#if (__cplusplus >= 201103L) // C++11
  template<typename T>
    using auto_ptr = std::unique_ptr<T>;
#else
# if defined(__clang__)
  using std::tr1::auto_ptr;
# else
  using std::auto_ptr;
# endif // lang
#endif // C++11

Results in:

./smartptr.h:23:27: error: no type named 'unique_ptr' in namespace 'std'
    using auto_ptr = std::unique_ptr<T>;
                     ~~~~~^
./smartptr.h:23:37: error: expected ';' after alias declaration
    using auto_ptr = std::unique_ptr<T>;

So its the same issue....




More information about the cfe-dev mailing list