]> git.lyx.org Git - features.git/blobdiff - boost/boost/utility/value_init.hpp
boost: add eol property
[features.git] / boost / boost / utility / value_init.hpp
index 40b2614eca959159997157f62d6f89da931d41f5..177fe743450c2135ba873a239bf2e14b0b9592bb 100644 (file)
-// (C) Copyright 2002-2008, Fernando Luis Cacciola Carballal.\r
-//\r
-// Distributed under the Boost Software License, Version 1.0. (See\r
-// accompanying file LICENSE_1_0.txt or copy at\r
-// http://www.boost.org/LICENSE_1_0.txt)\r
-//\r
-// 21 Ago 2002 (Created) Fernando Cacciola\r
-// 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker\r
-// 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola\r
-// 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola\r
-// 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola\r
-//\r
-#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP\r
-#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP\r
-\r
-// Note: The implementation of boost::value_initialized had to deal with the\r
-// fact that various compilers haven't fully implemented value-initialization.\r
-// The constructor of boost::value_initialized<T> works around these compiler\r
-// issues, by clearing the bytes of T, before constructing the T object it\r
-// contains. More details on these issues are at libs/utility/value_init.htm\r
-\r
-#include <boost/aligned_storage.hpp>\r
-#include <boost/detail/workaround.hpp>\r
-#include <boost/static_assert.hpp>\r
-#include <boost/type_traits/cv_traits.hpp>\r
-#include <boost/type_traits/alignment_of.hpp>\r
-#include <boost/swap.hpp>\r
-#include <cstring>\r
-#include <new>\r
-\r
-namespace boost {\r
-\r
-template<class T>\r
-class value_initialized\r
-{\r
-  private :\r
-    struct wrapper\r
-    {\r
-#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))\r
-      typename\r
-#endif \r
-      remove_const<T>::type data;\r
-    };\r
-\r
-    mutable\r
-#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))\r
-      typename\r
-#endif \r
-      aligned_storage<sizeof(wrapper), alignment_of<wrapper>::value>::type x;\r
-\r
-    wrapper * wrapper_address() const\r
-    {\r
-      return static_cast<wrapper *>( static_cast<void*>(&x));\r
-    }\r
-\r
-  public :\r
-\r
-    value_initialized()\r
-    {\r
-      std::memset(&x, 0, sizeof(x));\r
-#ifdef BOOST_MSVC\r
-#pragma warning(push)\r
-#if _MSC_VER >= 1310\r
-// When using MSVC 7.1 or higher, the following placement new expression may trigger warning C4345:\r
-// "behavior change: an object of POD type constructed with an initializer of the form ()\r
-// will be default-initialized".  It is safe to ignore this warning when using value_initialized.\r
-#pragma warning(disable: 4345)\r
-#endif\r
-#endif\r
-      new (wrapper_address()) wrapper();\r
-#ifdef BOOST_MSVC\r
-#pragma warning(pop)\r
-#endif\r
-    }\r
-\r
-    value_initialized(value_initialized const & arg)\r
-    {\r
-      new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address())));\r
-    }\r
-\r
-    value_initialized & operator=(value_initialized const & arg)\r
-    {\r
-      // Assignment is only allowed when T is non-const.\r
-      BOOST_STATIC_ASSERT( ! is_const<T>::value );\r
-      *wrapper_address() = static_cast<wrapper const &>(*(arg.wrapper_address()));\r
-      return *this;\r
-    }\r
-\r
-    ~value_initialized()\r
-    {\r
-      wrapper_address()->wrapper::~wrapper();\r
-    }\r
-\r
-    T const & data() const\r
-    {\r
-      return wrapper_address()->data;\r
-    }\r
-\r
-    T& data()\r
-    {\r
-      return wrapper_address()->data;\r
-    }\r
-\r
-    void swap(value_initialized & arg)\r
-    {\r
-      ::boost::swap( this->data(), arg.data() );\r
-    }\r
-\r
-    operator T const &() const { return this->data(); }\r
-\r
-    operator T&() { return this->data(); }\r
-\r
-} ;\r
-\r
-\r
-\r
-\r
-\r
-template<class T>\r
-T const& get ( value_initialized<T> const& x )\r
-{\r
-  return x.data() ;\r
-}\r
-template<class T>\r
-T& get ( value_initialized<T>& x )\r
-{\r
-  return x.data() ;\r
-}\r
-\r
-template<class T>\r
-void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs )\r
-{\r
-  lhs.swap(rhs) ;\r
-}\r
-\r
-\r
-class initialized_value_t\r
-{\r
-  public :\r
-    \r
-    template <class T> operator T() const\r
-    {\r
-      return get( value_initialized<T>() );\r
-    }\r
-};\r
-\r
-initialized_value_t const initialized_value = {} ;\r
-\r
-\r
-} // namespace boost\r
-\r
-\r
-#endif\r
+// (C) Copyright 2002-2008, Fernando Luis Cacciola Carballal.
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// 21 Ago 2002 (Created) Fernando Cacciola
+// 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker
+// 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola
+// 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola
+// 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola
+//
+#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
+#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
+
+// Note: The implementation of boost::value_initialized had to deal with the
+// fact that various compilers haven't fully implemented value-initialization.
+// The constructor of boost::value_initialized<T> works around these compiler
+// issues, by clearing the bytes of T, before constructing the T object it
+// contains. More details on these issues are at libs/utility/value_init.htm
+
+#include <boost/aligned_storage.hpp>
+#include <boost/detail/workaround.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/cv_traits.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+#include <boost/swap.hpp>
+#include <cstring>
+#include <new>
+
+namespace boost {
+
+template<class T>
+class value_initialized
+{
+  private :
+    struct wrapper
+    {
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
+      typename
+#endif 
+      remove_const<T>::type data;
+    };
+
+    mutable
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
+      typename
+#endif 
+      aligned_storage<sizeof(wrapper), alignment_of<wrapper>::value>::type x;
+
+    wrapper * wrapper_address() const
+    {
+      return static_cast<wrapper *>( static_cast<void*>(&x));
+    }
+
+  public :
+
+    value_initialized()
+    {
+      std::memset(&x, 0, sizeof(x));
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#if _MSC_VER >= 1310
+// When using MSVC 7.1 or higher, the following placement new expression may trigger warning C4345:
+// "behavior change: an object of POD type constructed with an initializer of the form ()
+// will be default-initialized".  It is safe to ignore this warning when using value_initialized.
+#pragma warning(disable: 4345)
+#endif
+#endif
+      new (wrapper_address()) wrapper();
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+    }
+
+    value_initialized(value_initialized const & arg)
+    {
+      new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address())));
+    }
+
+    value_initialized & operator=(value_initialized const & arg)
+    {
+      // Assignment is only allowed when T is non-const.
+      BOOST_STATIC_ASSERT( ! is_const<T>::value );
+      *wrapper_address() = static_cast<wrapper const &>(*(arg.wrapper_address()));
+      return *this;
+    }
+
+    ~value_initialized()
+    {
+      wrapper_address()->wrapper::~wrapper();
+    }
+
+    T const & data() const
+    {
+      return wrapper_address()->data;
+    }
+
+    T& data()
+    {
+      return wrapper_address()->data;
+    }
+
+    void swap(value_initialized & arg)
+    {
+      ::boost::swap( this->data(), arg.data() );
+    }
+
+    operator T const &() const { return this->data(); }
+
+    operator T&() { return this->data(); }
+
+} ;
+
+
+
+
+
+template<class T>
+T const& get ( value_initialized<T> const& x )
+{
+  return x.data() ;
+}
+template<class T>
+T& get ( value_initialized<T>& x )
+{
+  return x.data() ;
+}
+
+template<class T>
+void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs )
+{
+  lhs.swap(rhs) ;
+}
+
+
+class initialized_value_t
+{
+  public :
+    
+    template <class T> operator T() const
+    {
+      return get( value_initialized<T>() );
+    }
+};
+
+initialized_value_t const initialized_value = {} ;
+
+
+} // namespace boost
+
+
+#endif