123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
- #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
- #include <boost/config.hpp>
- #include <boost/core/invoke_swap.hpp>
- #include <cstring>
- #include <cstddef>
- #ifdef BOOST_MSVC
- #pragma warning(push)
- #pragma warning(disable: 4351)
- #pragma warning(disable: 4512)
- #endif
- #ifndef BOOST_UTILITY_DOCS
- #ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
-
-
-
- #define BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
- #endif
- #ifndef BOOST_DETAIL_VALUE_INIT_WORKAROUND
- #ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
- #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 1
- #else
- #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0
- #endif
- #endif
- #endif
- namespace boost {
- namespace detail {
- struct zero_init
- {
- zero_init()
- {
- }
- zero_init( void * p, std::size_t n )
- {
- std::memset( p, 0, n );
- }
- };
- }
- template<class T>
- class initialized
- #if BOOST_DETAIL_VALUE_INIT_WORKAROUND
- : detail::zero_init
- #endif
- {
- private:
- T data_;
- public :
- BOOST_GPU_ENABLED
- initialized():
- #if BOOST_DETAIL_VALUE_INIT_WORKAROUND
- zero_init( &const_cast< char& >( reinterpret_cast<char const volatile&>( data_ ) ), sizeof( data_ ) ),
- #endif
- data_()
- {
- }
- BOOST_GPU_ENABLED
- explicit initialized(T const & arg): data_( arg )
- {
- }
- BOOST_GPU_ENABLED
- T const & data() const
- {
- return data_;
- }
- BOOST_GPU_ENABLED
- T& data()
- {
- return data_;
- }
- BOOST_GPU_ENABLED
- void swap(initialized & arg)
- {
- ::boost::core::invoke_swap( this->data(), arg.data() );
- }
- BOOST_GPU_ENABLED
- operator T const &() const
- {
- return data_;
- }
- BOOST_GPU_ENABLED
- operator T&()
- {
- return data_;
- }
- } ;
- template<class T>
- BOOST_GPU_ENABLED
- T const& get ( initialized<T> const& x )
- {
- return x.data() ;
- }
- template<class T>
- BOOST_GPU_ENABLED
- T& get ( initialized<T>& x )
- {
- return x.data() ;
- }
- template<class T>
- BOOST_GPU_ENABLED
- void swap ( initialized<T> & lhs, initialized<T> & rhs )
- {
- lhs.swap(rhs) ;
- }
- template<class T>
- class value_initialized
- {
- private :
-
- initialized<T> m_data;
- public :
- BOOST_GPU_ENABLED
- value_initialized()
- :
- m_data()
- { }
- BOOST_GPU_ENABLED
- T const & data() const
- {
- return m_data.data();
- }
- BOOST_GPU_ENABLED
- T& data()
- {
- return m_data.data();
- }
- BOOST_GPU_ENABLED
- void swap(value_initialized & arg)
- {
- m_data.swap(arg.m_data);
- }
- BOOST_GPU_ENABLED
- operator T const &() const
- {
- return m_data;
- }
- BOOST_GPU_ENABLED
- operator T&()
- {
- return m_data;
- }
- } ;
- template<class T>
- BOOST_GPU_ENABLED
- T const& get ( value_initialized<T> const& x )
- {
- return x.data() ;
- }
- template<class T>
- BOOST_GPU_ENABLED
- T& get ( value_initialized<T>& x )
- {
- return x.data() ;
- }
- template<class T>
- BOOST_GPU_ENABLED
- void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs )
- {
- lhs.swap(rhs) ;
- }
- class initialized_value_t
- {
- public :
- template <class T> BOOST_GPU_ENABLED operator T() const
- {
- return initialized<T>().data();
- }
- };
- initialized_value_t const initialized_value = {} ;
- }
- #ifdef BOOST_MSVC
- #pragma warning(pop)
- #endif
- #endif
|