Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49263 - trunk/boost/serialization
From: ramey_at_[hidden]
Date: 2008-10-11 01:33:00


Author: ramey
Date: 2008-10-11 01:32:59 EDT (Sat, 11 Oct 2008)
New Revision: 49263
URL: http://svn.boost.org/trac/boost/changeset/49263

Log:
Fix to make is_destoryed function as advertised
Text files modified:
   trunk/boost/serialization/singleton.hpp | 32 +++++++++++++++++++++-----------
   1 files changed, 21 insertions(+), 11 deletions(-)

Modified: trunk/boost/serialization/singleton.hpp
==============================================================================
--- trunk/boost/serialization/singleton.hpp (original)
+++ trunk/boost/serialization/singleton.hpp 2008-10-11 01:32:59 EDT (Sat, 11 Oct 2008)
@@ -93,21 +93,37 @@
     }
 };
 
+namespace detail {
+
+template<class T>
+class singleton_wrapper : public T
+{
+public:
+ static bool m_is_destroyed;
+ ~singleton_wrapper(){
+ m_is_destroyed = true;
+ }
+};
+
+template<class T>
+bool detail::singleton_wrapper<T>::m_is_destroyed = false;
+
+} // detail
+
 template <class T>
 class singleton : public singleton_module
 {
 private:
- static bool m_is_destroyed;
     BOOST_DLLEXPORT static T & instance;
     // include this to provoke instantiation at pre-execution time
     static void use(T const &) {}
     BOOST_DLLEXPORT static T & get_instance() {
- static T t;
+ static detail::singleton_wrapper<T> t;
         // refer to instance, causing it to be instantiated (and
         // initialized at startup on working compilers)
- assert(! m_is_destroyed);
+ assert(! detail::singleton_wrapper<T>::m_is_destroyed);
         use(instance);
- return t;
+ return static_cast<T &>(t);
     }
 public:
     BOOST_DLLEXPORT static T & get_mutable_instance(){
@@ -118,19 +134,13 @@
         return get_instance();
     }
     BOOST_DLLEXPORT static bool is_destroyed(){
- return m_is_destroyed;
- }
- ~singleton(){
- m_is_destroyed = true;
+ return detail::singleton_wrapper<T>::m_is_destroyed;
     }
 };
 
 template<class T>
 BOOST_DLLEXPORT T & singleton<T>::instance = singleton<T>::get_instance();
 
-template<class T>
-bool singleton<T>::m_is_destroyed = false;
-
 } // namespace serialization
 } // namespace boost
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk