Commit 74f9f2fb authored by elelel's avatar elelel Committed by Davis E. King
Browse files

Replace shared_ptr/weak_ptr with STL's versions (#588)

* Replace shared_ptr/weak_ptr with stdlib counterparts

* Fix ptr usage through tests compilation

* Bring back dlib smart ptrs as legacy

* Include scoped_ptr directly

* Add explanation about smart_ptr deprecation
parent fe3e86a1
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <string> #include <string>
#include "../sockets.h" #include "../sockets.h"
#include "sockets_extensions_abstract.h" #include "sockets_extensions_abstract.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include <iosfwd> #include <iosfwd>
namespace dlib namespace dlib
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "../threads.h" #include "../threads.h"
#include "../algs.h" #include "../algs.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
#include "sqlite_abstract.h" #include "sqlite_abstract.h"
#include <iostream> #include <iostream>
#include <limits>
#include <memory>
#include <vector> #include <vector>
#include "../algs.h" #include "../algs.h"
#include <sqlite3.h> #include <sqlite3.h>
#include "../smart_pointers.h"
#include "../serialize.h" #include "../serialize.h"
#include <limits>
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
...@@ -105,7 +107,7 @@ namespace dlib ...@@ -105,7 +107,7 @@ namespace dlib
friend class statement; friend class statement;
std::string filename; std::string filename;
shared_ptr<sqlite3> db; std::shared_ptr<sqlite3> db;
}; };
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
...@@ -593,7 +595,7 @@ namespace dlib ...@@ -593,7 +595,7 @@ namespace dlib
int step_status; int step_status;
bool at_first_step; bool at_first_step;
shared_ptr<sqlite3> db; std::shared_ptr<sqlite3> db;
sqlite3_stmt* stmt; sqlite3_stmt* stmt;
std::string sql_string; std::string sql_string;
}; };
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "kcentroid.h" #include "kcentroid.h"
#include "kkmeans_abstract.h" #include "kkmeans_abstract.h"
#include "../noncopyable.h" #include "../noncopyable.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
#include <vector> #include <vector>
namespace dlib namespace dlib
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "kernel.h" #include "kernel.h"
#include "kcentroid.h" #include "kcentroid.h"
#include <iostream> #include <iostream>
#include "../smart_pointers.h" #include <memory>
namespace dlib namespace dlib
{ {
...@@ -460,7 +460,7 @@ namespace dlib ...@@ -460,7 +460,7 @@ namespace dlib
const sample_vector_type* samples; const sample_vector_type* samples;
shared_ptr<cache_type> cache; std::shared_ptr<cache_type> cache;
mutable unsigned long counter; mutable unsigned long counter;
unsigned long counter_threshold; unsigned long counter_threshold;
long cache_size; long cache_size;
......
...@@ -3,20 +3,19 @@ ...@@ -3,20 +3,19 @@
#ifndef DLIB_STRUCTURAL_SVM_DISTRIBUTeD_Hh_ #ifndef DLIB_STRUCTURAL_SVM_DISTRIBUTeD_Hh_
#define DLIB_STRUCTURAL_SVM_DISTRIBUTeD_Hh_ #define DLIB_STRUCTURAL_SVM_DISTRIBUTeD_Hh_
#include <memory>
#include <iostream>
#include <vector>
#include "structural_svm_distributed_abstract.h" #include "structural_svm_distributed_abstract.h"
#include "structural_svm_problem.h" #include "structural_svm_problem.h"
#include "../bridge.h" #include "../bridge.h"
#include "../smart_pointers.h"
#include "../misc_api.h" #include "../misc_api.h"
#include "../statistics.h" #include "../statistics.h"
#include "../threads.h" #include "../threads.h"
#include "../pipe.h" #include "../pipe.h"
#include "../type_safe_union.h" #include "../type_safe_union.h"
#include <iostream>
#include <vector>
namespace dlib namespace dlib
{ {
...@@ -678,9 +677,9 @@ namespace dlib ...@@ -678,9 +677,9 @@ namespace dlib
typedef type_safe_union<impl::oracle_request<matrix_type> > tsu_out; typedef type_safe_union<impl::oracle_request<matrix_type> > tsu_out;
typedef type_safe_union<impl::oracle_response<matrix_type>, long> tsu_in; typedef type_safe_union<impl::oracle_response<matrix_type>, long> tsu_in;
std::vector<shared_ptr<pipe<tsu_out> > > out_pipes; std::vector<std::shared_ptr<pipe<tsu_out> > > out_pipes;
mutable pipe<tsu_in> in; mutable pipe<tsu_in> in;
std::vector<shared_ptr<bridge> > bridges; std::vector<std::shared_ptr<bridge> > bridges;
long num_dims; long num_dims;
}; };
......
...@@ -3,21 +3,21 @@ ...@@ -3,21 +3,21 @@
#ifndef DLIB_SVm_THREADED_ #ifndef DLIB_SVm_THREADED_
#define DLIB_SVm_THREADED_ #define DLIB_SVm_THREADED_
#include "svm_threaded_abstract.h"
#include "svm.h"
#include <cmath> #include <cmath>
#include <iostream>
#include <limits> #include <limits>
#include <sstream> #include <sstream>
#include <vector>
#include "svm_threaded_abstract.h"
#include "svm.h"
#include "../matrix.h" #include "../matrix.h"
#include "../algs.h" #include "../algs.h"
#include "../serialize.h" #include "../serialize.h"
#include "function.h" #include "function.h"
#include "kernel.h" #include "kernel.h"
#include "../threads.h" #include "../threads.h"
#include <vector>
#include "../smart_pointers.h"
#include "../pipe.h" #include "../pipe.h"
#include <iostream>
namespace dlib namespace dlib
{ {
......
...@@ -125,7 +125,6 @@ set (tests ...@@ -125,7 +125,6 @@ set (tests
set.cpp set.cpp
sldf.cpp sldf.cpp
sliding_buffer.cpp sliding_buffer.cpp
smart_pointers.cpp
sockets2.cpp sockets2.cpp
sockets.cpp sockets.cpp
sockstreambuf.cpp sockstreambuf.cpp
......
// Copyright (C) 2007 Davis E. King (davis@dlib.net) // Copyright (C) 2007 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license. // License: Boost Software License See LICENSE.txt for the full license.
// This is a legacy test for old dlib smart pointers which is excluded
// from CMakeLists.txt. Including this test will pull legacy smart_pointers.h
// code which is uncompilable on C++17 compilers
#include <dlib/smart_pointers.h> #include <dlib/smart_pointers.h>
#include <sstream> #include <sstream>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <dlib/misc_api.h> #include <dlib/misc_api.h>
#include <dlib/sockstreambuf.h> #include <dlib/sockstreambuf.h>
#include <vector> #include <vector>
#include <dlib/smart_pointers.h> #include <dlib/smart_pointers/scoped_ptr.h>
#include "tester.h" #include "tester.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "threads_kernel.h" #include "threads_kernel.h"
#include "auto_mutex_extension.h" #include "auto_mutex_extension.h"
#include "threaded_object_extension.h" #include "threaded_object_extension.h"
#include "../smart_pointers.h" #include "../smart_pointers/scoped_ptr.h"
namespace dlib namespace dlib
{ {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#define DLIB_THREAD_POOl_CPPh_ #define DLIB_THREAD_POOl_CPPh_
#include "thread_pool_extension.h" #include "thread_pool_extension.h"
#include <memory>
namespace dlib namespace dlib
{ {
...@@ -287,7 +288,7 @@ namespace dlib ...@@ -287,7 +288,7 @@ namespace dlib
uint64 thread_pool_implementation:: uint64 thread_pool_implementation::
add_task_internal ( add_task_internal (
const bfp_type& bfp, const bfp_type& bfp,
shared_ptr<function_object_copy>& item std::shared_ptr<function_object_copy>& item
) )
{ {
auto_mutex M(m); auto_mutex M(m);
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#include "../uintn.h" #include "../uintn.h"
#include "../array.h" #include "../array.h"
#include "../smart_pointers_thread_safe.h" #include "../smart_pointers_thread_safe.h"
#include "../smart_pointers.h"
#include <exception> #include <exception>
#include <thread> #include <thread>
#include <memory>
namespace dlib namespace dlib
{ {
...@@ -314,7 +314,7 @@ namespace dlib ...@@ -314,7 +314,7 @@ namespace dlib
uint64 add_task_internal ( uint64 add_task_internal (
const bfp_type& bfp, const bfp_type& bfp,
shared_ptr<function_object_copy>& item std::shared_ptr<function_object_copy>& item
); );
/*! /*!
ensures ensures
...@@ -326,7 +326,7 @@ namespace dlib ...@@ -326,7 +326,7 @@ namespace dlib
uint64 add_task_internal ( uint64 add_task_internal (
const bfp_type& bfp const bfp_type& bfp
) { shared_ptr<function_object_copy> temp; return add_task_internal(bfp, temp); } ) { std::shared_ptr<function_object_copy> temp; return add_task_internal(bfp, temp); }
/*! /*!
ensures ensures
- adds a task to call the given bfp object. - adds a task to call the given bfp object.
...@@ -452,7 +452,7 @@ namespace dlib ...@@ -452,7 +452,7 @@ namespace dlib
member_function_pointer<long,long> mfp2; member_function_pointer<long,long> mfp2;
bfp_type bfp; bfp_type bfp;
shared_ptr<function_object_copy> function_copy; std::shared_ptr<function_object_copy> function_copy;
mutable std::exception_ptr eptr; // non-null if the task threw an exception mutable std::exception_ptr eptr; // non-null if the task threw an exception
void propagate_exception() const void propagate_exception() const
...@@ -596,7 +596,7 @@ namespace dlib ...@@ -596,7 +596,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0; thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object); ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
...@@ -627,7 +627,7 @@ namespace dlib ...@@ -627,7 +627,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item,funct); temp.set(ptr->item,funct);
...@@ -644,7 +644,7 @@ namespace dlib ...@@ -644,7 +644,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item,funct); temp.set(ptr->item,funct);
...@@ -693,7 +693,7 @@ namespace dlib ...@@ -693,7 +693,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0; thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object); ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, arg1.get()); temp.set(ptr->item, arg1.get());
...@@ -731,7 +731,7 @@ namespace dlib ...@@ -731,7 +731,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item,funct,arg1.get()); temp.set(ptr->item,funct,arg1.get());
...@@ -770,7 +770,7 @@ namespace dlib ...@@ -770,7 +770,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item,funct,arg1.get()); temp.set(ptr->item,funct,arg1.get());
...@@ -831,7 +831,7 @@ namespace dlib ...@@ -831,7 +831,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0; thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object); ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, arg1.get(), arg2.get()); temp.set(ptr->item, arg1.get(), arg2.get());
...@@ -877,7 +877,7 @@ namespace dlib ...@@ -877,7 +877,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, funct, arg1.get(), arg2.get()); temp.set(ptr->item, funct, arg1.get(), arg2.get());
...@@ -923,7 +923,7 @@ namespace dlib ...@@ -923,7 +923,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, funct, arg1.get(), arg2.get()); temp.set(ptr->item, funct, arg1.get(), arg2.get());
...@@ -994,7 +994,7 @@ namespace dlib ...@@ -994,7 +994,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0; thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object); ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, arg1.get(), arg2.get(), arg3.get()); temp.set(ptr->item, arg1.get(), arg2.get(), arg3.get());
...@@ -1048,7 +1048,7 @@ namespace dlib ...@@ -1048,7 +1048,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get()); temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get());
...@@ -1102,7 +1102,7 @@ namespace dlib ...@@ -1102,7 +1102,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get()); temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get());
...@@ -1183,7 +1183,7 @@ namespace dlib ...@@ -1183,7 +1183,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0; thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object); ptr = new thread_pool_implementation::function_object_copy_instance<F>(function_object);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, arg1.get(), arg2.get(), arg3.get(), arg4.get()); temp.set(ptr->item, arg1.get(), arg2.get(), arg3.get(), arg4.get());
...@@ -1245,7 +1245,7 @@ namespace dlib ...@@ -1245,7 +1245,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get(), arg4.get()); temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get(), arg4.get());
...@@ -1307,7 +1307,7 @@ namespace dlib ...@@ -1307,7 +1307,7 @@ namespace dlib
{ {
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0; thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj); ptr = new thread_pool_implementation::function_object_copy_instance<const T>(obj);
shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr); std::shared_ptr<thread_pool_implementation::function_object_copy> function_copy(ptr);
bfp_type temp; bfp_type temp;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get(), arg4.get()); temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get(), arg4.get());
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <dlib/directed_graph.h> #include <dlib/directed_graph.h>
#include <dlib/string.h> #include <dlib/string.h>
#include <dlib/bayes_utils.h> #include <dlib/bayes_utils.h>
#include <dlib/smart_pointers.h> #include <dlib/smart_pointers/scoped_ptr.h>
#include <dlib/set.h> #include <dlib/set.h>
#include <dlib/graph_utils.h> #include <dlib/graph_utils.h>
#include <dlib/stl_checked.h> #include <dlib/stl_checked.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment