Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does unique_ptr have an overload for auto_ptr?

I got a compiler error and noticed something interesting. For some reason unique_ptr has an overload for auto_ptr, but I thought auto_ptr was deprecated:

/usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2: 
note:template<class _Up, class> 
std::unique_ptr<_Tp, _Dp>::unique_ptr(std::auto_ptr<_Up>&&)
  unique_ptr(auto_ptr<_Up>&& __u) noexcept;

/usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2: 
note: template argument deduction/substitution failed:
main.cpp:41:67: note:  mismatched types 'std::auto_ptr<T>' and 'char*'

Is this because of backwards compatibility with code that used auto_ptr?

like image 362
user4085715 Avatar asked Oct 31 '22 16:10

user4085715


1 Answers

Yes, it's for interop with auto_ptr, and deprecated means (according to the standard)

Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions.

like image 150
Johan Lundberg Avatar answered Nov 15 '22 03:11

Johan Lundberg