Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:31

0001 // (C) Copyright 2002-2008, Fernando Luis Cacciola Carballal.
0002 // Copyright 2020 Peter Dimov
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See
0005 // accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // 21 Ago 2002 (Created) Fernando Cacciola
0009 // 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker
0010 // 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola
0011 // 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola
0012 // 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola
0013 // 03 Apr 2010 (Added initialized<T>, suggested by Jeffrey Hellrung, fixing #3472) Niels Dekker
0014 // 30 May 2010 (Made memset call conditional, fixing #3869) Niels Dekker
0015 //
0016 #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
0017 #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
0018 
0019 // Note: The implementation of boost::value_initialized had to deal with the
0020 // fact that various compilers haven't fully implemented value-initialization.
0021 // The constructor of boost::value_initialized<T> works around these compiler
0022 // issues, by clearing the bytes of T, before constructing the T object it
0023 // contains. More details on these issues are at libs/utility/value_init.htm
0024 
0025 #include <boost/config.hpp> // For BOOST_NO_COMPLETE_VALUE_INITIALIZATION.
0026 #include <boost/core/invoke_swap.hpp>
0027 #include <cstring>
0028 #include <cstddef>
0029 
0030 #ifdef BOOST_MSVC
0031 #pragma warning(push)
0032 // It is safe to ignore the following warning from MSVC 7.1 or higher:
0033 // "warning C4351: new behavior: elements of array will be default initialized"
0034 #pragma warning(disable: 4351)
0035 // It is safe to ignore the following MSVC warning, which may pop up when T is
0036 // a const type: "warning C4512: assignment operator could not be generated".
0037 #pragma warning(disable: 4512)
0038 #endif
0039 
0040 #ifndef BOOST_UTILITY_DOCS
0041 
0042 #ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
0043   // Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
0044   // suggests that a workaround should be applied, because of compiler issues
0045   // regarding value-initialization.
0046   #define BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
0047 #endif
0048 
0049 // Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND
0050 // switches the value-initialization workaround either on or off.
0051 #ifndef BOOST_DETAIL_VALUE_INIT_WORKAROUND
0052   #ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
0053   #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 1
0054   #else
0055   #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0
0056   #endif
0057 #endif
0058 
0059 #endif // BOOST_UTILITY_DOCS
0060 
0061 namespace boost {
0062 
0063 namespace detail {
0064 
0065   struct zero_init
0066   {
0067     zero_init()
0068     {
0069     }
0070 
0071     zero_init( void * p, std::size_t n )
0072     {
0073       std::memset( p, 0, n );
0074     }
0075   };
0076 
0077 } // namespace detail
0078 
0079 template<class T>
0080 class initialized
0081 #if BOOST_DETAIL_VALUE_INIT_WORKAROUND
0082   : detail::zero_init
0083 #endif
0084 {
0085   private:
0086 
0087     T data_;
0088 
0089   public :
0090 
0091     BOOST_GPU_ENABLED
0092     initialized():
0093 #if BOOST_DETAIL_VALUE_INIT_WORKAROUND
0094       zero_init( &const_cast< char& >( reinterpret_cast<char const volatile&>( data_ ) ), sizeof( data_ ) ),
0095 #endif
0096       data_()
0097     {
0098     }
0099 
0100     BOOST_GPU_ENABLED
0101     explicit initialized(T const & arg): data_( arg )
0102     {
0103     }
0104 
0105     BOOST_GPU_ENABLED
0106     T const & data() const
0107     {
0108       return data_;
0109     }
0110 
0111     BOOST_GPU_ENABLED
0112     T& data()
0113     {
0114       return data_;
0115     }
0116 
0117     BOOST_GPU_ENABLED
0118     void swap(initialized & arg)
0119     {
0120       ::boost::core::invoke_swap( this->data(), arg.data() );
0121     }
0122 
0123     BOOST_GPU_ENABLED
0124     operator T const &() const
0125     {
0126       return data_;
0127     }
0128 
0129     BOOST_GPU_ENABLED
0130     operator T&()
0131     {
0132       return data_;
0133     }
0134 
0135 } ;
0136 
0137 template<class T>
0138 BOOST_GPU_ENABLED
0139 T const& get ( initialized<T> const& x )
0140 {
0141   return x.data() ;
0142 }
0143 
0144 template<class T>
0145 BOOST_GPU_ENABLED
0146 T& get ( initialized<T>& x )
0147 {
0148   return x.data() ;
0149 }
0150 
0151 template<class T>
0152 BOOST_GPU_ENABLED
0153 void swap ( initialized<T> & lhs, initialized<T> & rhs )
0154 {
0155   lhs.swap(rhs) ;
0156 }
0157 
0158 template<class T>
0159 class value_initialized
0160 {
0161   private :
0162 
0163     // initialized<T> does value-initialization by default.
0164     initialized<T> m_data;
0165 
0166   public :
0167 
0168     BOOST_GPU_ENABLED
0169     value_initialized()
0170     :
0171     m_data()
0172     { }
0173 
0174     BOOST_GPU_ENABLED
0175     T const & data() const
0176     {
0177       return m_data.data();
0178     }
0179 
0180     BOOST_GPU_ENABLED
0181     T& data()
0182     {
0183       return m_data.data();
0184     }
0185 
0186     BOOST_GPU_ENABLED
0187     void swap(value_initialized & arg)
0188     {
0189       m_data.swap(arg.m_data);
0190     }
0191 
0192     BOOST_GPU_ENABLED
0193     operator T const &() const
0194     {
0195       return m_data;
0196     }
0197 
0198     BOOST_GPU_ENABLED
0199     operator T&()
0200     {
0201       return m_data;
0202     }
0203 } ;
0204 
0205 
0206 template<class T>
0207 BOOST_GPU_ENABLED
0208 T const& get ( value_initialized<T> const& x )
0209 {
0210   return x.data() ;
0211 }
0212 
0213 template<class T>
0214 BOOST_GPU_ENABLED
0215 T& get ( value_initialized<T>& x )
0216 {
0217   return x.data() ;
0218 }
0219 
0220 template<class T>
0221 BOOST_GPU_ENABLED
0222 void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs )
0223 {
0224   lhs.swap(rhs) ;
0225 }
0226 
0227 
0228 class initialized_value_t
0229 {
0230   public :
0231 
0232     template <class T> BOOST_GPU_ENABLED operator T() const
0233     {
0234       return initialized<T>().data();
0235     }
0236 };
0237 
0238 initialized_value_t const initialized_value = {} ;
0239 
0240 
0241 } // namespace boost
0242 
0243 #ifdef BOOST_MSVC
0244 #pragma warning(pop)
0245 #endif
0246 
0247 #endif