dimanche 26 juillet 2015

"using" (or ther mechanism) to swap in unique_ptr for auto_ptr in C++11?

I'm catching a compile warning under Cygwin with -std=c++11:

cryptlib.cpp: In member function ‘virtual size_t PK_Signer::SignMessage(RandomNumberGenerator&, const byte*, size_t, byte*) const’:
cryptlib.cpp:770:41: warning: ‘auto_ptr’ is deprecated (declared at /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/backward/auto_ptr.h:87) [-Wdeprecated-declarations]
std::auto_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
                                       ^

I tried adding:

using auto_ptr = std::unique_ptr;
using std::auto_ptr;
auto_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));

But it resulted in the following, even with <memory> included.

$ make cryptlib.o 
c++ -std=c++11 -DNDEBUG -g2 -O3 -fPIC -march=native -DCRYPTOPP_DISABLE_ASM -Wall -Wextra -pipe -c cryptlib.cpp
cryptlib.cpp:770:27: error: no type named 'unique_ptr' in namespace 'std'
    using auto_ptr = std::unique_ptr;
                     ~~~~~^

I can't make a clean cut-over to unique_ptr because its a C++03 library.

Is it possible to use "using" to swap in unique_ptr? Or is there some other mechanism?

Aucun commentaire:

Enregistrer un commentaire