Updated examples to use unique_ptr when available rather than auto_ptr, which is being deprecated.

This commit is contained in:
Edward Diener
2017-08-26 15:06:30 -04:00
parent 523bc5a782
commit ef60815c66
3 changed files with 45 additions and 0 deletions

View File

@@ -15,6 +15,7 @@
// $Revision$ // $Revision$
#include <memory> #include <memory>
#include <boost/config.hpp>
namespace fsm { namespace aux { namespace fsm { namespace aux {
@@ -25,13 +26,32 @@ struct base_event
public: public:
virtual ~base_event() {}; virtual ~base_event() {};
#if defined(BOOST_NO_CXX11_SMART_PTR)
std::auto_ptr<base_event> clone() const std::auto_ptr<base_event> clone() const
#else
std::unique_ptr<base_event> clone() const
#endif
{ {
return do_clone(); return do_clone();
} }
private: private:
#if defined(BOOST_NO_CXX11_SMART_PTR)
virtual std::auto_ptr<base_event> do_clone() const = 0; virtual std::auto_ptr<base_event> do_clone() const = 0;
#else
virtual std::unique_ptr<base_event> do_clone() const = 0;
#endif
}; };
}} }}

View File

@@ -26,12 +26,27 @@ struct event
typedef base_event base_t; typedef base_event base_t;
private: private:
#if defined(BOOST_NO_CXX11_SMART_PTR)
virtual std::auto_ptr<base_event> do_clone() const virtual std::auto_ptr<base_event> do_clone() const
{ {
return std::auto_ptr<base_event>( return std::auto_ptr<base_event>(
new Derived(static_cast<Derived const&>(*this)) new Derived(static_cast<Derived const&>(*this))
); );
} }
#else
virtual std::unique_ptr<base_event> do_clone() const
{
return std::unique_ptr<base_event>(
new Derived(static_cast<Derived const&>(*this))
);
}
#endif
}; };
}} }}

View File

@@ -83,7 +83,17 @@ class state_machine
{ {
} }
#if defined(BOOST_NO_CXX11_SMART_PTR)
void post_event(std::auto_ptr<base_event_t const> evt) void post_event(std::auto_ptr<base_event_t const> evt)
#else
void post_event(std::unique_ptr<base_event_t const> evt)
#endif
{ {
m_events_queue.push(base_event_ptr_t(evt.release())); m_events_queue.push(base_event_ptr_t(evt.release()));
} }