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 @@
#include <string>
#include "../sockets.h"
#include "sockets_extensions_abstract.h"
#include "../smart_pointers.h"
#include "../smart_pointers/scoped_ptr.h"
#include <iosfwd>
namespace dlib
......
......@@ -32,7 +32,7 @@
#include "../threads.h"
#include "../algs.h"
#include "../smart_pointers.h"
#include "../smart_pointers/scoped_ptr.h"
......
......@@ -6,12 +6,14 @@
#include "sqlite_abstract.h"
#include <iostream>
#include <limits>
#include <memory>
#include <vector>
#include "../algs.h"
#include <sqlite3.h>
#include "../smart_pointers.h"
#include "../serialize.h"
#include <limits>
// --------------------------------------------------------------------------------------------
......@@ -105,7 +107,7 @@ namespace dlib
friend class statement;
std::string filename;
shared_ptr<sqlite3> db;
std::shared_ptr<sqlite3> db;
};
// --------------------------------------------------------------------------------------------
......@@ -593,7 +595,7 @@ namespace dlib
int step_status;
bool at_first_step;
shared_ptr<sqlite3> db;
std::shared_ptr<sqlite3> db;
sqlite3_stmt* stmt;
std::string sql_string;
};
......
......@@ -12,7 +12,7 @@
#include "kcentroid.h"
#include "kkmeans_abstract.h"
#include "../noncopyable.h"
#include "../smart_pointers.h"
#include "../smart_pointers/scoped_ptr.h"
#include <vector>
namespace dlib
......
......@@ -10,7 +10,7 @@
#include "kernel.h"
#include "kcentroid.h"
#include <iostream>
#include "../smart_pointers.h"
#include <memory>
namespace dlib
{
......@@ -460,7 +460,7 @@ namespace dlib
const sample_vector_type* samples;
shared_ptr<cache_type> cache;
std::shared_ptr<cache_type> cache;
mutable unsigned long counter;
unsigned long counter_threshold;
long cache_size;
......
......@@ -3,20 +3,19 @@
#ifndef 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_problem.h"
#include "../bridge.h"
#include "../smart_pointers.h"
#include "../misc_api.h"
#include "../statistics.h"
#include "../threads.h"
#include "../pipe.h"
#include "../type_safe_union.h"
#include <iostream>
#include <vector>
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_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;
std::vector<shared_ptr<bridge> > bridges;
std::vector<std::shared_ptr<bridge> > bridges;
long num_dims;
};
......
......@@ -3,21 +3,21 @@
#ifndef DLIB_SVm_THREADED_
#define DLIB_SVm_THREADED_
#include "svm_threaded_abstract.h"
#include "svm.h"
#include <cmath>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>
#include "svm_threaded_abstract.h"
#include "svm.h"
#include "../matrix.h"
#include "../algs.h"
#include "../serialize.h"
#include "function.h"
#include "kernel.h"
#include "../threads.h"
#include <vector>
#include "../smart_pointers.h"
#include "../pipe.h"
#include <iostream>
namespace dlib
{
......
......@@ -125,7 +125,6 @@ set (tests
set.cpp
sldf.cpp
sliding_buffer.cpp
smart_pointers.cpp
sockets2.cpp
sockets.cpp
sockstreambuf.cpp
......
// Copyright (C) 2007 Davis E. King (davis@dlib.net)
// 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 <sstream>
......
......@@ -10,7 +10,7 @@
#include <dlib/misc_api.h>
#include <dlib/sockstreambuf.h>
#include <vector>
#include <dlib/smart_pointers.h>
#include <dlib/smart_pointers/scoped_ptr.h>
#include "tester.h"
......
......@@ -7,7 +7,7 @@
#include "threads_kernel.h"
#include "auto_mutex_extension.h"
#include "threaded_object_extension.h"
#include "../smart_pointers.h"
#include "../smart_pointers/scoped_ptr.h"
namespace dlib
{
......
......@@ -4,6 +4,7 @@
#define DLIB_THREAD_POOl_CPPh_
#include "thread_pool_extension.h"
#include <memory>
namespace dlib
{
......@@ -287,7 +288,7 @@ namespace dlib
uint64 thread_pool_implementation::
add_task_internal (
const bfp_type& bfp,
shared_ptr<function_object_copy>& item
std::shared_ptr<function_object_copy>& item
)
{
auto_mutex M(m);
......
......@@ -12,9 +12,9 @@
#include "../uintn.h"
#include "../array.h"
#include "../smart_pointers_thread_safe.h"
#include "../smart_pointers.h"
#include <exception>
#include <thread>
#include <memory>
namespace dlib
{
......@@ -314,7 +314,7 @@ namespace dlib
uint64 add_task_internal (
const bfp_type& bfp,
shared_ptr<function_object_copy>& item
std::shared_ptr<function_object_copy>& item
);
/*!
ensures
......@@ -326,7 +326,7 @@ namespace dlib
uint64 add_task_internal (
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
- adds a task to call the given bfp object.
......@@ -452,7 +452,7 @@ namespace dlib
member_function_pointer<long,long> mfp2;
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
void propagate_exception() const
......@@ -596,7 +596,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
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;
......@@ -627,7 +627,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
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;
temp.set(ptr->item,funct);
......@@ -644,7 +644,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
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;
temp.set(ptr->item,funct);
......@@ -693,7 +693,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
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;
temp.set(ptr->item, arg1.get());
......@@ -731,7 +731,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
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;
temp.set(ptr->item,funct,arg1.get());
......@@ -770,7 +770,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
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;
temp.set(ptr->item,funct,arg1.get());
......@@ -831,7 +831,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
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;
temp.set(ptr->item, arg1.get(), arg2.get());
......@@ -877,7 +877,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
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;
temp.set(ptr->item, funct, arg1.get(), arg2.get());
......@@ -923,7 +923,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
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;
temp.set(ptr->item, funct, arg1.get(), arg2.get());
......@@ -994,7 +994,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
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;
temp.set(ptr->item, arg1.get(), arg2.get(), arg3.get());
......@@ -1048,7 +1048,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
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;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get());
......@@ -1102,7 +1102,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
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;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get());
......@@ -1183,7 +1183,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<F>* ptr = 0;
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;
temp.set(ptr->item, arg1.get(), arg2.get(), arg3.get(), arg4.get());
......@@ -1245,7 +1245,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<T>* ptr = 0;
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;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get(), arg4.get());
......@@ -1307,7 +1307,7 @@ namespace dlib
{
thread_pool_implementation::function_object_copy_instance<const T>* ptr = 0;
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;
temp.set(ptr->item, funct, arg1.get(), arg2.get(), arg3.get(), arg4.get());
......
......@@ -27,7 +27,7 @@
#include <dlib/directed_graph.h>
#include <dlib/string.h>
#include <dlib/bayes_utils.h>
#include <dlib/smart_pointers.h>
#include <dlib/smart_pointers/scoped_ptr.h>
#include <dlib/set.h>
#include <dlib/graph_utils.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