diff --git a/dlib/any/any.h b/dlib/any/any.h index b3c29b700..b5ef1bc8b 100644 --- a/dlib/any/any.h +++ b/dlib/any/any.h @@ -4,7 +4,9 @@ #define DLIB_AnY_H_ #include "any_abstract.h" -#include "../smart_pointers/scoped_ptr.h" +#include "../algs.h" + +#include #include namespace dlib @@ -136,7 +138,7 @@ namespace dlib virtual ~base() {} virtual void copy_to ( - scoped_ptr& dest + std::unique_ptr& dest ) const = 0; }; @@ -148,14 +150,14 @@ namespace dlib derived(const T& val) : item(val) {} virtual void copy_to ( - scoped_ptr& dest + std::unique_ptr& dest ) const { dest.reset(new derived(item)); } }; - scoped_ptr data; + std::unique_ptr data; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/any/any_decision_function.h b/dlib/any/any_decision_function.h index 3db685f63..771e9302b 100644 --- a/dlib/any/any_decision_function.h +++ b/dlib/any/any_decision_function.h @@ -147,7 +147,7 @@ namespace dlib virtual ~base() {} virtual void copy_to ( - scoped_ptr& dest + std::unique_ptr& dest ) const = 0; virtual result_type evaluate ( @@ -163,7 +163,7 @@ namespace dlib derived(const T& val) : item(val) {} virtual void copy_to ( - scoped_ptr& dest + std::unique_ptr& dest ) const { dest.reset(new derived(item)); @@ -177,7 +177,7 @@ namespace dlib } }; - scoped_ptr data; + std::unique_ptr data; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/any/any_function_impl.h b/dlib/any/any_function_impl.h index fb44f84df..fec66cde7 100644 --- a/dlib/any/any_function_impl.h +++ b/dlib/any/any_function_impl.h @@ -166,7 +166,7 @@ struct Tbase { virtual ~Tbase() {} virtual result_type evaluate () const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -177,7 +177,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate ( A1) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -188,7 +188,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -199,7 +199,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -211,7 +211,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -223,7 +223,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4,A5) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -235,7 +235,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4,A5,A6) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -248,7 +248,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4,A5,A6,A7) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -261,7 +261,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4,A5,A6,A7,A8) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -274,7 +274,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4,A5,A6,A7,A8,A9) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; template < @@ -288,7 +288,7 @@ struct Tbase { virtual ~Tbase() {} virtual T evaluate (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) const = 0; - virtual void copy_to ( scoped_ptr& dest) const = 0; + virtual void copy_to ( std::unique_ptr& dest) const = 0; }; typedef Tbase base; @@ -318,7 +318,7 @@ static typename disable_if,const T&>::type deref (const U& item) typename funct_type::type item; \ derived() {} \ derived(const T& val) : item(copy(val)) {} \ - virtual void copy_to ( scoped_ptr& dest) const \ + virtual void copy_to ( std::unique_ptr& dest) const \ { dest.reset(new derived(deref(item))); } template @@ -508,7 +508,7 @@ struct derived : public base !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ }; -scoped_ptr data; +std::unique_ptr data; #undef DLIB_ANY_FUNCTION_DERIVED_BOILERPLATE diff --git a/dlib/any/any_trainer.h b/dlib/any/any_trainer.h index 7ca17074e..4df10a140 100644 --- a/dlib/any/any_trainer.h +++ b/dlib/any/any_trainer.h @@ -156,7 +156,7 @@ namespace dlib ) const = 0; virtual void copy_to ( - scoped_ptr& dest + std::unique_ptr& dest ) const = 0; }; @@ -168,7 +168,7 @@ namespace dlib derived(const T& val) : item(val) {} virtual void copy_to ( - scoped_ptr& dest + std::unique_ptr& dest ) const { dest.reset(new derived(item)); @@ -183,7 +183,7 @@ namespace dlib } }; - scoped_ptr data; + std::unique_ptr data; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/bayes_utils/bayes_utils.h b/dlib/bayes_utils/bayes_utils.h index 4845f1723..33f9d5d9e 100644 --- a/dlib/bayes_utils/bayes_utils.h +++ b/dlib/bayes_utils/bayes_utils.h @@ -7,6 +7,7 @@ #include #include +#include #include #include "../string.h" @@ -17,7 +18,6 @@ #include "../set.h" #include "../algs.h" #include "../noncopyable.h" -#include "../smart_pointers/scoped_ptr.h" #include "../graph.h" namespace dlib @@ -1660,7 +1660,7 @@ namespace dlib private: - scoped_ptr impl; + std::unique_ptr impl; unsigned long num_nodes; }; diff --git a/dlib/bridge/bridge.h b/dlib/bridge/bridge.h index 0204f318f..da4e0bd7e 100644 --- a/dlib/bridge/bridge.h +++ b/dlib/bridge/bridge.h @@ -3,17 +3,19 @@ #ifndef DLIB_BRIDGe_Hh_ #define DLIB_BRIDGe_Hh_ -#include "bridge_abstract.h" +#include +#include #include + +#include "bridge_abstract.h" #include "../pipe.h" #include "../threads.h" -#include "../smart_pointers/scoped_ptr.h" #include "../serialize.h" #include "../sockets.h" #include "../sockstreambuf.h" #include "../logger.h" #include "../algs.h" -#include + namespace dlib { @@ -545,8 +547,8 @@ namespace dlib signaler s; bool receive_thread_active; bool transmit_thread_active; - scoped_ptr con; - scoped_ptr list; + std::unique_ptr con; + std::unique_ptr list; const unsigned short port; const std::string ip; transmit_pipe_type* const transmit_pipe; @@ -656,7 +658,7 @@ namespace dlib private: - scoped_ptr pimpl; + std::unique_ptr pimpl; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/bsp/bsp.cpp b/dlib/bsp/bsp.cpp index 383cf1f81..32e23519e 100644 --- a/dlib/bsp/bsp.cpp +++ b/dlib/bsp/bsp.cpp @@ -25,7 +25,7 @@ namespace dlib cons.clear(); for (unsigned long i = 0; i < hosts.size(); ++i) { - scoped_ptr con(new bsp_con(hosts[i])); + std::unique_ptr con(new bsp_con(hosts[i])); dlib::serialize(node_id, con->stream); // tell the other end our node_id unsigned long id = i+1; cons.add(id, con); @@ -44,7 +44,7 @@ namespace dlib { try { - scoped_ptr con(new bsp_con(hosts[i].addr)); + std::unique_ptr con(new bsp_con(hosts[i].addr)); dlib::serialize(node_id, con->stream); // tell the other end our node_id con->stream.flush(); unsigned long id = hosts[i].node_id; @@ -317,7 +317,7 @@ namespace dlib _cons.reset(); while (_cons.move_next()) { - scoped_ptr ptr(new thread_function(&impl2::read_thread, + std::unique_ptr ptr(new thread_function(&impl2::read_thread, _cons.element().value().get(), _node_id, _cons.element().key(), diff --git a/dlib/bsp/bsp.h b/dlib/bsp/bsp.h index 9e274d2a7..f0732c153 100644 --- a/dlib/bsp/bsp.h +++ b/dlib/bsp/bsp.h @@ -4,18 +4,19 @@ #define DLIB_BsP_Hh_ #include "bsp_abstract.h" + +#include +#include +#include + #include "../sockets.h" #include "../array.h" -#include "../smart_pointers/scoped_ptr.h" #include "../sockstreambuf.h" #include "../string.h" #include "../serialize.h" #include "../map.h" #include "../ref.h" #include "../vectorstream.h" -#include -#include -#include namespace dlib { @@ -42,7 +43,7 @@ namespace dlib } bsp_con( - scoped_ptr& conptr + std::unique_ptr& conptr ) : buf(conptr), stream(&buf), @@ -54,13 +55,13 @@ namespace dlib con->disable_nagle(); } - scoped_ptr con; + std::unique_ptr con; sockstreambuf buf; std::iostream stream; bool terminated; }; - typedef dlib::map >::kernel_1a_c map_id_to_con; + typedef dlib::map >::kernel_1a_c map_id_to_con; void connect_all ( map_id_to_con& cons, @@ -135,7 +136,7 @@ namespace dlib ) { cons.clear(); - scoped_ptr list; + std::unique_ptr list; const int status = create_listener(list, port); if (status == PORTINUSE) { @@ -149,13 +150,13 @@ namespace dlib port_notify_function(list->get_listening_port()); - scoped_ptr con; + std::unique_ptr con; if (list->accept(con)) { throw socket_error("Error occurred while accepting new connection"); } - scoped_ptr temp(new bsp_con(con)); + std::unique_ptr temp(new bsp_con(con)); unsigned long remote_node_id; dlib::deserialize(remote_node_id, temp->stream); @@ -198,7 +199,7 @@ namespace dlib while (cons2.size() > 0) { unsigned long id; - scoped_ptr temp; + std::unique_ptr temp; cons2.remove_any(id,temp); cons.add(id,temp); } @@ -534,7 +535,7 @@ namespace dlib impl1::map_id_to_con& _cons; const unsigned long _node_id; - array > threads; + array > threads; // ----------------------------------- diff --git a/dlib/gui_widgets/base_widgets.h b/dlib/gui_widgets/base_widgets.h index 7d97ccea1..76619338e 100644 --- a/dlib/gui_widgets/base_widgets.h +++ b/dlib/gui_widgets/base_widgets.h @@ -4,6 +4,7 @@ #ifndef DLIB_BASE_WIDGETs_ #define DLIB_BASE_WIDGETs_ +#include #include #include "base_widgets_abstract.h" @@ -19,9 +20,7 @@ #include "../image_transforms/assign_image.h" #include "../array.h" #include "style.h" -#include "../smart_pointers/scoped_ptr.h" #include "../unicode.h" -#include #include "../any.h" @@ -696,7 +695,7 @@ namespace dlib }; friend struct data; - scoped_ptr stuff; + std::unique_ptr stuff; @@ -954,7 +953,7 @@ namespace dlib any_function button_down_handler_self; any_function button_up_handler_self; - scoped_ptr style; + std::unique_ptr style; protected: @@ -1417,7 +1416,7 @@ namespace dlib timer top_filler_timer; timer bottom_filler_timer; long delayed_pos; - scoped_ptr style; + std::unique_ptr style; // restricted functions scroll_bar(scroll_bar&); // copy constructor @@ -1927,7 +1926,7 @@ namespace dlib { auto_mutex M(wm); bool t = true; - scoped_ptr item(new menu_item_type(new_item)); + std::unique_ptr item(new menu_item_type(new_item)); items.push_back(item); item_enabled.push_back(t); @@ -2137,7 +2136,7 @@ namespace dlib rectangle win_rect; unsigned long left_width; unsigned long middle_width; - array > items; + array > items; array item_enabled; array left_rects; array middle_rects; @@ -2358,7 +2357,7 @@ namespace dlib scroll_bar vsb; scroll_bar hsb; - scoped_ptr style; + std::unique_ptr style; // restricted functions zoomable_region(zoomable_region&); // copy constructor @@ -2578,7 +2577,7 @@ namespace dlib bool mouse_drag_enabled_; bool user_is_dragging_mouse; point drag_origin; - scoped_ptr style; + std::unique_ptr style; }; diff --git a/dlib/gui_widgets/widgets.cpp b/dlib/gui_widgets/widgets.cpp index 5c13b84f6..cf8a39aa7 100644 --- a/dlib/gui_widgets/widgets.cpp +++ b/dlib/gui_widgets/widgets.cpp @@ -3002,7 +3002,7 @@ namespace dlib const std::string old_path = path; const long old_cur_dir = cur_dir; - scoped_ptr new_btn(new toggle_button(*this)); + std::unique_ptr new_btn(new toggle_button(*this)); new_btn->set_name(folder_name); new_btn->set_click_handler(*this,&box_win::on_path_button_click); @@ -3011,7 +3011,7 @@ namespace dlib { while (sob.size() > (unsigned long)(cur_dir+1)) { - scoped_ptr junk; + std::unique_ptr junk; sob.remove(cur_dir+1,junk); } } diff --git a/dlib/gui_widgets/widgets.h b/dlib/gui_widgets/widgets.h index 9affe3120..45b37f712 100644 --- a/dlib/gui_widgets/widgets.h +++ b/dlib/gui_widgets/widgets.h @@ -24,7 +24,6 @@ #include "../sequence.h" #include "../dir_nav.h" #include "../queue.h" -#include "../smart_pointers/scoped_ptr.h" #include "style.h" #include "../string.h" #include "../misc_api.h" @@ -293,7 +292,7 @@ namespace dlib any_function event_handler; any_function event_handler_self; - scoped_ptr style; + std::unique_ptr style; protected: @@ -656,7 +655,7 @@ namespace dlib any_function enter_key_handler; any_function focus_lost_handler; - scoped_ptr style; + std::unique_ptr style; timer t; @@ -1052,7 +1051,7 @@ namespace dlib any_function enter_key_handler; any_function focus_lost_handler; - scoped_ptr style; + std::unique_ptr style; timer t; @@ -1829,7 +1828,7 @@ namespace dlib any_function single_click_event_handler; unsigned long last_selected; - scoped_ptr style; + std::unique_ptr style; // restricted functions list_box(list_box&); // copy constructor @@ -1928,7 +1927,7 @@ namespace dlib int cur_dir; any_function event_handler; - sequence >::kernel_2a_c sob; + sequence >::kernel_2a_c sob; }; } diff --git a/dlib/image_loader/png_loader.h b/dlib/image_loader/png_loader.h index 04dc4ab4c..437e28adf 100644 --- a/dlib/image_loader/png_loader.h +++ b/dlib/image_loader/png_loader.h @@ -3,8 +3,9 @@ #ifndef DLIB_PNG_IMPORT #define DLIB_PNG_IMPORT +#include + #include "png_loader_abstract.h" -#include "../smart_pointers/scoped_ptr.h" #include "image_loader.h" #include "../pixel.h" #include "../dir_nav.h" @@ -193,7 +194,7 @@ namespace dlib unsigned height_, width_; unsigned bit_depth_; int color_type_; - scoped_ptr ld_; + std::unique_ptr ld_; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/iosockstream/iosockstream.h b/dlib/iosockstream/iosockstream.h index e71afc69d..e49d2e37f 100644 --- a/dlib/iosockstream/iosockstream.h +++ b/dlib/iosockstream/iosockstream.h @@ -154,10 +154,10 @@ namespace dlib thecon->shutdown(); } - scoped_ptr con_timeout; + std::unique_ptr con_timeout; rmutex class_mutex; std::shared_ptr con; - scoped_ptr buf; + std::unique_ptr buf; }; diff --git a/dlib/logger/logger_kernel_1.cpp b/dlib/logger/logger_kernel_1.cpp index e867a1075..093cd29a8 100644 --- a/dlib/logger/logger_kernel_1.cpp +++ b/dlib/logger/logger_kernel_1.cpp @@ -202,7 +202,7 @@ namespace dlib } else { - scoped_ptr temp (new T); + std::unique_ptr temp (new T); temp->val = c.val; assign_tables(*temp, last, val); c.table.add(first,temp); diff --git a/dlib/logger/logger_kernel_1.h b/dlib/logger/logger_kernel_1.h index cfe0b5569..528bd6f67 100644 --- a/dlib/logger/logger_kernel_1.h +++ b/dlib/logger/logger_kernel_1.h @@ -3,20 +3,21 @@ #ifndef DLIB_LOGGER_KERNEl_1_ #define DLIB_LOGGER_KERNEl_1_ +#include +#include +#include +#include +#include + #include "../threads.h" #include "../misc_api.h" #include "../set.h" #include "logger_kernel_abstract.h" -#include -#include #include "../algs.h" #include "../assert.h" #include "../uintn.h" #include "../map.h" -#include "../smart_pointers/scoped_ptr.h" #include "../member_function_pointer.h" -#include -#include namespace dlib { @@ -445,7 +446,7 @@ namespace dlib level_container (); log_level val; - map >::kernel_1b_c table; + map >::kernel_1b_c table; } level_table; const log_level level ( @@ -473,7 +474,7 @@ namespace dlib struct auto_flush_container { bool val; - map >::kernel_1b_c table; + map >::kernel_1b_c table; } auto_flush_table; bool auto_flush ( @@ -501,7 +502,7 @@ namespace dlib struct output_streambuf_container { std::streambuf* val; - map >::kernel_1b_c table; + map >::kernel_1b_c table; } streambuf_table; std::streambuf* output_streambuf ( @@ -542,7 +543,7 @@ namespace dlib struct output_hook_container { hook_mfp val; - map >::kernel_1b_c table; + map >::kernel_1b_c table; } hook_table; hook_mfp output_hook ( @@ -570,7 +571,7 @@ namespace dlib struct logger_header_container { print_header_type val; - map >::kernel_1b_c table; + map >::kernel_1b_c table; } header_table; print_header_type logger_header ( diff --git a/dlib/optimization/optimization_bobyqa.h b/dlib/optimization/optimization_bobyqa.h index 3542fbdd9..6fbc40c06 100644 --- a/dlib/optimization/optimization_bobyqa.h +++ b/dlib/optimization/optimization_bobyqa.h @@ -18,8 +18,9 @@ #include #include +#include + #include "../matrix.h" -#include "../smart_pointers/scoped_ptr.h" #include "optimization_bobyqa_abstract.h" #include "optimization.h" @@ -59,7 +60,7 @@ namespace dlib { const unsigned long n = x.size(); const unsigned long w_size = (npt+5)*(npt+n)+3*n*(n+5)/2; - scoped_ptr w(new doublereal[w_size]); + std::unique_ptr w(new doublereal[w_size]); // make these temporary matrices becuse U might be some // kind of matrix_exp that doesn't support taking the address diff --git a/dlib/server/server_kernel.h b/dlib/server/server_kernel.h index 68e102b15..4232ff343 100644 --- a/dlib/server/server_kernel.h +++ b/dlib/server/server_kernel.h @@ -5,13 +5,14 @@ #include "server_kernel_abstract.h" +#include +#include + #include "../threads.h" #include "../sockets.h" -#include #include "../algs.h" #include "../set.h" #include "../logger.h" -#include "../smart_pointers/scoped_ptr.h" namespace dlib @@ -209,8 +210,8 @@ namespace dlib int max_connections; mutex max_connections_mutex; signaler thread_count_zero; - scoped_ptr async_start_thread; - scoped_ptr sock; + std::unique_ptr async_start_thread; + std::unique_ptr sock; unsigned long graceful_close_timeout; diff --git a/dlib/smart_pointers.h b/dlib/smart_pointers.h index 5f4686c1f..4560e55e1 100644 --- a/dlib/smart_pointers.h +++ b/dlib/smart_pointers.h @@ -13,9 +13,11 @@ #pragma GCC warning "smart_pointers.h is included which will fail to compile under C++17" #endif -#include "smart_pointers/scoped_ptr.h" +#include + #include "smart_pointers/shared_ptr.h" #include "smart_pointers/weak_ptr.h" +#include "smart_pointers/scoped_ptr.h" #endif // DLIB_SMART_POINTERs_H_ diff --git a/dlib/smart_pointers/scoped_ptr.h b/dlib/smart_pointers/scoped_ptr.h index af5964057..dd890f330 100644 --- a/dlib/smart_pointers/scoped_ptr.h +++ b/dlib/smart_pointers/scoped_ptr.h @@ -1,217 +1,16 @@ -// Copyright (C) 2007 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#ifndef DLIB_SCOPED_PTr_ -#define DLIB_SCOPED_PTr_ +#ifndef DLIB_SCOPED_PTr_H_ +#define DLIB_SCOPED_PTr_H_ -#include -#include "../noncopyable.h" -#include "../algs.h" -#include "scoped_ptr_abstract.h" +#include -namespace dlib -{ - -// ---------------------------------------------------------------------------------------- - - template - struct default_deleter - { - void operator() (T* item) const - { - delete item; - } - }; - - template - struct default_deleter - { - void operator() (T* item) const - { - delete [] item; - } - }; - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename deleter = default_deleter - > - class scoped_ptr : noncopyable - { - /*! - CONVENTION - - get() == ptr - !*/ - - public: - typedef T element_type; - typedef deleter deleter_type; - - explicit scoped_ptr ( - T* p = 0 - ) : ptr(p) { } - - ~scoped_ptr() - { - if (ptr) - { - deleter del; - del(ptr); - } - } - - void reset ( - T* p = 0 - ) - { - if (ptr) - { - deleter del; - del(ptr); - } - - ptr = p; - } - - T& operator*() const - { - DLIB_ASSERT(get() != 0, - "\tscoped_ptr::operator*()" - << "\n\tget() can't be null if you are going to dereference it" - << "\n\tthis: " << this - ); - - return *ptr; - } - - T* operator->() const - { - DLIB_ASSERT(get() != 0, - "\tscoped_ptr::operator*()" - << "\n\tget() can't be null" - << "\n\tthis: " << this - ); - - return ptr; - } - - T* get() const - { - return ptr; - } - - operator bool() const - { - return (ptr != 0); - } - - void swap( - scoped_ptr& b - ) - { - std::swap(ptr,b.ptr); - } - - private: - - T* ptr; - }; - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename deleter - > - class scoped_ptr : noncopyable - { - /*! - CONVENTION - - get() == ptr - !*/ - - public: - typedef T element_type; - - explicit scoped_ptr ( - T* p = 0 - ) : ptr(p) { } - - ~scoped_ptr() - { - if (ptr) - { - deleter del; - del(ptr); - } - } - - void reset ( - T* p = 0 - ) - { - if (ptr) - { - deleter del; - del(ptr); - } - ptr = p; - } - - T& operator[] ( - unsigned long idx - ) const - { - DLIB_ASSERT(get() != 0, - "\tscoped_ptr::operator[]()" - << "\n\tget() can't be null if you are going to dereference it" - << "\n\tthis: " << this - ); - - return ptr[idx]; - } - - T* get() const - { - return ptr; - } - - operator bool() const - { - return (ptr != 0); - } - - void swap( - scoped_ptr& b - ) - { - std::swap(ptr,b.ptr); - } - - private: - - T* ptr; - }; - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename deleter - > - void swap( - scoped_ptr& a, - scoped_ptr& b - ) - { - a.swap(b); - } - -// ---------------------------------------------------------------------------------------- +namespace dlib { + // Template alias for compatibility with clients using old dlib::scoped_ptr + // Old scoped_ptr implementation is removed completely + // This alias may fail in some reference deduction cases + + template > + using scoped_ptr = std::unique_ptr; } -#endif // DLIB_SCOPED_PTr_ - - +#endif diff --git a/dlib/smart_pointers/scoped_ptr_abstract.h b/dlib/smart_pointers/scoped_ptr_abstract.h deleted file mode 100644 index 1bc5db64a..000000000 --- a/dlib/smart_pointers/scoped_ptr_abstract.h +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (C) 2007 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#undef DLIB_SCOPED_PTr_ABSTRACT_ -#ifdef DLIB_SCOPED_PTr_ABSTRACT_ - -#include "../noncopyable.h" - -namespace dlib -{ - -// ---------------------------------------------------------------------------------------- - - template - struct default_deleter - { - void operator() ( - T* item - ) const; - /*! - ensures - - if (T is an array type (e.g. int[])) then - - performs "delete [] item;" - - else - - performs "delete item;" - !*/ - }; - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename deleter = default_deleter - > - class scoped_ptr : noncopyable - { - /*! - REQUIREMENTS ON deleter - Must be a function object that performs deallocation of a pointer - of type T. For example, see the default_deleter type defined above. - It must also not throw when constructed or when performing a delete. - - INITIAL VALUE - defined by constructor - - WHAT THIS OBJECT REPRESENTS - This is a smart pointer class inspired by the implementation of the scoped_ptr - class found in the Boost C++ library. So this is a simple smart pointer - class which guarantees that the pointer contained within it will always be - deleted. - - The class does not permit copying and so does not do any kind of - reference counting. Thus it is very simply and quite fast. - - Note that this class allows you to use pointers to arrays as well as - pointers to single items. To let it know that it is supposed to point - to an array you have to declare it using the bracket syntax. Consider - the following examples: - - // This is how you make a scoped pointer to a single thing - scoped_ptr single_item(new int); - - // This is how you can use a scoped pointer to contain array pointers. - // Note the use of []. This ensures that the proper version of delete - // is called. - scoped_ptr array_of_ints(new int[50]); - !*/ - - public: - typedef T element_type; - typedef deleter deleter_type; - - explicit scoped_ptr ( - T* p = 0 - ); - /*! - ensures - - #get() == p - !*/ - - ~scoped_ptr( - ); - /*! - ensures - - if (get() != 0) then - - calls deleter()(get()) - (i.e. uses the deleter type to delete the pointer that is - contained in this scoped pointer) - !*/ - - void reset ( - T* p = 0 - ); - /*! - ensures - - if (get() != 0) then - - calls deleter()(get()) - (i.e. uses the deleter type to delete the pointer that is - contained in this scoped pointer) - - #get() == p - (i.e. makes this object contain a pointer to p instead of whatever it - used to contain) - !*/ - - T& operator*( - ) const; - /*! - requires - - get() != 0 - - T is NOT an array type (e.g. not int[]) - ensures - - returns a reference to *get() - !*/ - - T* operator->( - ) const; - /*! - requires - - get() != 0 - - T is NOT an array type (e.g. not int[]) - ensures - - returns the pointer contained in this object - !*/ - - T& operator[]( - unsigned long idx - ) const; - /*! - requires - - get() != 0 - - T is an array type (e.g. int[]) - ensures - - returns get()[idx] - !*/ - - T* get( - ) const; - /*! - ensures - - returns the pointer contained in this object - !*/ - - operator bool( - ) const; - /*! - ensures - - returns get() != 0 - !*/ - - void swap( - scoped_ptr& b - ); - /*! - ensures - - swaps *this and item - !*/ - }; - - template < - typename T - > - void swap( - scoped_ptr& a, - scoped_ptr& b - ) { a.swap(b); } - /*! - provides a global swap function - !*/ -} - -#endif // DLIB_SCOPED_PTr_ABSTRACT_ - - diff --git a/dlib/sockets/sockets_extensions.cpp b/dlib/sockets/sockets_extensions.cpp index 1d794398c..be08c1998 100644 --- a/dlib/sockets/sockets_extensions.cpp +++ b/dlib/sockets/sockets_extensions.cpp @@ -294,14 +294,14 @@ namespace dlib unsigned long timeout ) { - scoped_ptr ptr(con); + std::unique_ptr ptr(con); close_gracefully(ptr,timeout); } // ---------------------------------------------------------------------------------------- void close_gracefully ( - scoped_ptr& con, + std::unique_ptr& con, unsigned long timeout ) { diff --git a/dlib/sockets/sockets_extensions.h b/dlib/sockets/sockets_extensions.h index a733676b5..9faa34e01 100644 --- a/dlib/sockets/sockets_extensions.h +++ b/dlib/sockets/sockets_extensions.h @@ -3,11 +3,14 @@ #ifndef DLIB_SOCKETS_EXTENSIONs_ #define DLIB_SOCKETS_EXTENSIONs_ -#include -#include "../sockets.h" -#include "sockets_extensions_abstract.h" -#include "../smart_pointers/scoped_ptr.h" #include +#include +#include + +#include "../sockets.h" +#include "../smart_pointers/scoped_ptr.h" +#include "sockets_extensions_abstract.h" + namespace dlib { @@ -132,7 +135,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- void close_gracefully ( - scoped_ptr& con, + std::unique_ptr& con, unsigned long timeout = 500 ); diff --git a/dlib/sockets/sockets_extensions_abstract.h b/dlib/sockets/sockets_extensions_abstract.h index f40ac705a..194c22ab2 100644 --- a/dlib/sockets/sockets_extensions_abstract.h +++ b/dlib/sockets/sockets_extensions_abstract.h @@ -3,9 +3,10 @@ #undef DLIB_SOCKETS_EXTENSIONs_ABSTRACT_ #ifdef DLIB_SOCKETS_EXTENSIONs_ABSTRACT_ +#include #include + #include "sockets_kernel_abstract.h" -#include "../smart_pointers.h" #include "../error.h" namespace dlib @@ -265,7 +266,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- void close_gracefully ( - scoped_ptr& con, + std::unique_ptr& con, unsigned long timeout = 500 ); /*! diff --git a/dlib/sockets/sockets_kernel_1.cpp b/dlib/sockets/sockets_kernel_1.cpp index a4b1887d1..55e39569f 100644 --- a/dlib/sockets/sockets_kernel_1.cpp +++ b/dlib/sockets/sockets_kernel_1.cpp @@ -498,7 +498,7 @@ namespace dlib int listener:: accept ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned long timeout ) { @@ -646,7 +646,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- int create_listener ( - scoped_ptr& new_listener, + std::unique_ptr& new_listener, unsigned short port, const std::string& ip ) @@ -764,7 +764,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- int create_connection ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned short foreign_port, const std::string& foreign_ip, unsigned short local_port, diff --git a/dlib/sockets/sockets_kernel_1.h b/dlib/sockets/sockets_kernel_1.h index 5eb4c2aad..5fb73ecd6 100644 --- a/dlib/sockets/sockets_kernel_1.h +++ b/dlib/sockets/sockets_kernel_1.h @@ -9,8 +9,10 @@ #include "sockets_kernel_abstract.h" -#include "../algs.h" +#include #include + +#include "../algs.h" #include "../threads.h" #include "../uintn.h" @@ -268,7 +270,7 @@ namespace dlib ); int accept ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned long timeout = 0 ); @@ -323,13 +325,13 @@ namespace dlib ); int create_listener ( - scoped_ptr& new_listener, + std::unique_ptr& new_listener, unsigned short port, const std::string& ip = "" ); int create_connection ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned short foreign_port, const std::string& foreign_ip, unsigned short local_port = 0, diff --git a/dlib/sockets/sockets_kernel_2.cpp b/dlib/sockets/sockets_kernel_2.cpp index 862ec49df..ac7408ff3 100644 --- a/dlib/sockets/sockets_kernel_2.cpp +++ b/dlib/sockets/sockets_kernel_2.cpp @@ -527,7 +527,7 @@ namespace dlib int listener:: accept ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned long timeout ) { @@ -788,7 +788,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- int create_listener ( - scoped_ptr& new_listener, + std::unique_ptr& new_listener, unsigned short port, const std::string& ip ) @@ -907,7 +907,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- int create_connection ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned short foreign_port, const std::string& foreign_ip, unsigned short local_port, diff --git a/dlib/sockets/sockets_kernel_2.h b/dlib/sockets/sockets_kernel_2.h index 10cf90af9..f3bc94ec0 100644 --- a/dlib/sockets/sockets_kernel_2.h +++ b/dlib/sockets/sockets_kernel_2.h @@ -13,10 +13,14 @@ #define _BSD_SOCKLEN_T_ +#include +#include +#include + #include #include #include -#include + #ifndef HPUX #include #endif @@ -26,13 +30,12 @@ #include #include #include -#include #include #include "../threads.h" #include "../algs.h" -#include "../smart_pointers/scoped_ptr.h" + @@ -312,7 +315,7 @@ namespace dlib ); int accept ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned long timeout = 0 ); @@ -368,13 +371,13 @@ namespace dlib ); int create_listener ( - scoped_ptr& new_listener, + std::unique_ptr& new_listener, unsigned short port, const std::string& ip = "" ); int create_connection ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned short foreign_port, const std::string& foreign_ip, unsigned short local_port = 0, diff --git a/dlib/sockets/sockets_kernel_abstract.h b/dlib/sockets/sockets_kernel_abstract.h index 85bf216fd..d4571acad 100644 --- a/dlib/sockets/sockets_kernel_abstract.h +++ b/dlib/sockets/sockets_kernel_abstract.h @@ -117,13 +117,13 @@ namespace dlib !*/ int create_listener ( - scoped_ptr& new_listener, + std::unique_ptr& new_listener, unsigned short port, const std::string& ip = "" ); /*! This function is just an overload of the above function but it gives you a - scoped_ptr smart pointer instead of a C pointer. + std::unique_ptr smart pointer instead of a C pointer. !*/ int create_connection ( @@ -154,7 +154,7 @@ namespace dlib !*/ int create_connection ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned short foreign_port, const std::string& foreign_ip, unsigned short local_port = 0, @@ -162,7 +162,7 @@ namespace dlib ); /*! This function is just an overload of the above function but it gives you a - scoped_ptr smart pointer instead of a C pointer. + std::unique_ptr smart pointer instead of a C pointer. !*/ // ---------------------------------------------------------------------------------------- @@ -459,12 +459,12 @@ namespace dlib !*/ int accept ( - scoped_ptr& new_connection, + std::unique_ptr& new_connection, unsigned long timeout = 0 ); /*! This function is just an overload of the above function but it gives you a - scoped_ptr smart pointer instead of a C pointer. + std::unique_ptr smart pointer instead of a C pointer. !*/ unsigned short get_listening_port ( diff --git a/dlib/sockstreambuf/sockstreambuf.h b/dlib/sockstreambuf/sockstreambuf.h index b02301865..f5b450e78 100644 --- a/dlib/sockstreambuf/sockstreambuf.h +++ b/dlib/sockstreambuf/sockstreambuf.h @@ -47,7 +47,7 @@ namespace dlib } sockstreambuf ( - const scoped_ptr& con_ + const std::unique_ptr& con_ ) : con(*con_), out_buffer(0), diff --git a/dlib/sockstreambuf/sockstreambuf_abstract.h b/dlib/sockstreambuf/sockstreambuf_abstract.h index 25251ff26..12be84193 100644 --- a/dlib/sockstreambuf/sockstreambuf_abstract.h +++ b/dlib/sockstreambuf/sockstreambuf_abstract.h @@ -4,7 +4,9 @@ #ifdef DLIB_SOCKSTREAMBUF_ABSTRACT_ #include +#include #include + #include "../sockets/sockets_kernel_abstract.h" namespace dlib @@ -60,7 +62,7 @@ namespace dlib !*/ sockstreambuf ( - const scoped_ptr& con + const std::unique_ptr& con ); /*! requires diff --git a/dlib/sockstreambuf/sockstreambuf_unbuffered.h b/dlib/sockstreambuf/sockstreambuf_unbuffered.h index f9aae4c15..8aa5992db 100644 --- a/dlib/sockstreambuf/sockstreambuf_unbuffered.h +++ b/dlib/sockstreambuf/sockstreambuf_unbuffered.h @@ -57,7 +57,7 @@ namespace dlib {} sockstreambuf_unbuffered ( - const scoped_ptr& con_ + const std::unique_ptr& con_ ) : con(*con_), peek(EOF), diff --git a/dlib/svm/kkmeans.h b/dlib/svm/kkmeans.h index 89fc3b7af..4c72106d8 100644 --- a/dlib/svm/kkmeans.h +++ b/dlib/svm/kkmeans.h @@ -4,6 +4,8 @@ #define DLIB_KKMEANs_ #include +#include + #include "../matrix/matrix_abstract.h" #include "../algs.h" #include "../serialize.h" @@ -12,8 +14,6 @@ #include "kcentroid.h" #include "kkmeans_abstract.h" #include "../noncopyable.h" -#include "../smart_pointers/scoped_ptr.h" -#include namespace dlib { @@ -176,7 +176,7 @@ namespace dlib item.centers.resize(num); for (unsigned long i = 0; i < item.centers.size(); ++i) { - scoped_ptr > temp(new kcentroid(kernel_type())); + std::unique_ptr > temp(new kcentroid(kernel_type())); deserialize(*temp, in); item.centers[i].swap(temp); } @@ -270,7 +270,7 @@ namespace dlib } - array > > centers; + array > > centers; kcentroid kc; scalar_type min_change; diff --git a/dlib/svm/structural_svm_distributed.h b/dlib/svm/structural_svm_distributed.h index b4a058d82..a9542c70f 100644 --- a/dlib/svm/structural_svm_distributed.h +++ b/dlib/svm/structural_svm_distributed.h @@ -332,7 +332,7 @@ namespace dlib }; - scoped_ptr the_problem; + std::unique_ptr the_problem; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/test/sockets.cpp b/dlib/test/sockets.cpp index ab0361444..920fa9402 100644 --- a/dlib/test/sockets.cpp +++ b/dlib/test/sockets.cpp @@ -2,10 +2,12 @@ // License: Boost Software License See LICENSE.txt for the full license. -#include -#include #include #include +#include +#include +#include + #include #include #include @@ -118,7 +120,7 @@ namespace { } int status; - scoped_ptr con; + std::unique_ptr con; string hostname; string ip; status = get_local_hostname(hostname); diff --git a/dlib/test/sockets2.cpp b/dlib/test/sockets2.cpp index c6fbbf508..3521e751d 100644 --- a/dlib/test/sockets2.cpp +++ b/dlib/test/sockets2.cpp @@ -1,11 +1,13 @@ // Copyright (C) 2008 Davis E. King (davis@dlib.net) // License: Boost Software License See LICENSE.txt for the full license. +#include +#include + #include "tester.h" #include #include #include -#include // This is called an unnamed-namespace and it has the effect of making everything // inside this file "private" so that everything you declare will have static linkage. @@ -39,7 +41,7 @@ namespace { try { - scoped_ptr con(connect("127.0.0.1", port_num)); + std::unique_ptr con(connect("127.0.0.1", port_num)); // Send a copy of the data down the connection so we can test our the read() function // that uses timeouts in the main thread. @@ -63,7 +65,7 @@ namespace { try { - scoped_ptr con(connect("127.0.0.1", port_num)); + std::unique_ptr con(connect("127.0.0.1", port_num)); // just do nothing until the connection closes char ch; @@ -120,17 +122,17 @@ namespace dlog << LINFO << "data block size: " << data_to_send.size(); - scoped_ptr list; + std::unique_ptr list; DLIB_TEST(create_listener(list, port_num, "127.0.0.1") == 0); - DLIB_TEST(list); + DLIB_TEST(bool(list)); // kick off the sending threads start(); - dlib::array > cons; + dlib::array > cons; std::vector bytes_received(6,0); - scoped_ptr con_temp; + std::unique_ptr con_temp; // accept the 6 connections we should get for (int i = 0; i < 6; ++i) diff --git a/dlib/test/sockstreambuf.cpp b/dlib/test/sockstreambuf.cpp index 21282d852..519feb2b5 100644 --- a/dlib/test/sockstreambuf.cpp +++ b/dlib/test/sockstreambuf.cpp @@ -2,15 +2,15 @@ // License: Boost Software License See LICENSE.txt for the full license. +#include #include #include -#include +#include + #include #include #include #include -#include -#include #include "tester.h" @@ -143,7 +143,7 @@ namespace } // make sure con gets deleted - scoped_ptr del_con(con); + std::unique_ptr del_con(con); ssb buf(con); istream in(&buf); diff --git a/dlib/test/tester.h b/dlib/test/tester.h index b228ffdf0..e16647cf5 100644 --- a/dlib/test/tester.h +++ b/dlib/test/tester.h @@ -17,7 +17,7 @@ #endif -#define DLIB_TEST(_exp) check_test(_exp, __LINE__, __FILE__, #_exp) +#define DLIB_TEST(_exp) check_test(bool(_exp), __LINE__, __FILE__, #_exp) #define DLIB_TEST_MSG(_exp,_message) \ do{increment_test_count(); if ( !(_exp) ) \ diff --git a/dlib/threads/thread_function_extension.h b/dlib/threads/thread_function_extension.h index cfad5dbe4..7ecdd6520 100644 --- a/dlib/threads/thread_function_extension.h +++ b/dlib/threads/thread_function_extension.h @@ -1,13 +1,14 @@ // Copyright (C) 2007 Davis E. King (davis@dlib.net) // License: Boost Software License See LICENSE.txt for the full license. #ifndef DLIB_THREAD_FUNCTIOn_ -#define DLIB_THREAD_FUNCTIOn_ +#define DLIB_THREAD_FUNCTIOn_ + +#include #include "thread_function_extension_abstract.h" #include "threads_kernel.h" #include "auto_mutex_extension.h" #include "threaded_object_extension.h" -#include "../smart_pointers/scoped_ptr.h" namespace dlib { @@ -197,7 +198,7 @@ namespace dlib f->go(); } - scoped_ptr f; + std::unique_ptr f; // restricted functions thread_function(thread_function&); // copy constructor diff --git a/examples/bayes_net_gui_ex.cpp b/examples/bayes_net_gui_ex.cpp index bc981b69b..81101912c 100644 --- a/examples/bayes_net_gui_ex.cpp +++ b/examples/bayes_net_gui_ex.cpp @@ -21,13 +21,14 @@ examples and want to see a more in-depth example then by all means, continue reading. :) */ -#include +#include #include #include + +#include #include #include #include -#include #include #include #include @@ -123,7 +124,7 @@ private: widget_group cpt_group; widget_group ppt_group; - scoped_ptr solution; + std::unique_ptr solution; join_tree_type join_tree; // The std_vector_c is an object identical to the std::vector except that it checks // all its preconditions and throws a dlib::fatal_error if they are violated. diff --git a/examples/sockstreambuf_ex.cpp b/examples/sockstreambuf_ex.cpp index c7a921e80..93200baa5 100644 --- a/examples/sockstreambuf_ex.cpp +++ b/examples/sockstreambuf_ex.cpp @@ -15,9 +15,11 @@ http://www.jmarshall.com/easy/http/ */ +#include +#include + #include #include -#include using namespace std; using namespace dlib; @@ -31,7 +33,7 @@ int main() // are using a smart pointer here to contain the connection pointer // returned from connect. Doing this ensures that the connection // is deleted even if someone throws an exception somewhere in your code. - scoped_ptr con(connect("www.google.com",80)); + std::unique_ptr con(connect("www.google.com",80)); {