File indexing completed on 2025-01-18 09:53:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
0017 #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
0018
0019
0020
0021
0022
0023
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
0033
0034 #pragma warning(disable: 4351)
0035
0036
0037 #pragma warning(disable: 4512)
0038 #endif
0039
0040 #ifndef BOOST_UTILITY_DOCS
0041
0042 #ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
0043
0044
0045
0046 #define BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
0047 #endif
0048
0049
0050
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
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 }
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
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 }
0242
0243 #ifdef BOOST_MSVC
0244 #pragma warning(pop)
0245 #endif
0246
0247 #endif