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$
#include <memory>
#include <boost/config.hpp>
namespace fsm { namespace aux {
@@ -25,13 +26,32 @@ struct base_event
public:
virtual ~base_event() {};
#if defined(BOOST_NO_CXX11_SMART_PTR)
std::auto_ptr<base_event> clone() const
#else
std::unique_ptr<base_event> clone() const
#endif
{
return do_clone();
}
private:
#if defined(BOOST_NO_CXX11_SMART_PTR)
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;
private:
#if defined(BOOST_NO_CXX11_SMART_PTR)
virtual std::auto_ptr<base_event> do_clone() const
{
return std::auto_ptr<base_event>(
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)
#else
void post_event(std::unique_ptr<base_event_t const> evt)
#endif
{
m_events_queue.push(base_event_ptr_t(evt.release()));
}