File indexing completed on 2025-01-18 09:50:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_STATIC_MOVE_PTR_HPP_INCLUDED
0018 #define BOOST_STATIC_MOVE_PTR_HPP_INCLUDED
0019
0020 #include <boost/config.hpp> // Member template friends, put size_t in std.
0021 #include <cstddef> // size_t
0022 #include <boost/compressed_pair.hpp>
0023 #include <boost/ptr_container/detail/default_deleter.hpp>
0024 #include <boost/ptr_container/detail/is_convertible.hpp>
0025 #include <boost/ptr_container/detail/move.hpp>
0026 #include <boost/static_assert.hpp>
0027 #include <boost/type_traits/add_reference.hpp>
0028 #include <boost/type_traits/is_array.hpp>
0029
0030 #if defined(BOOST_MSVC)
0031 #pragma warning(push)
0032 #pragma warning(disable:4521)
0033 #endif
0034
0035 namespace boost { namespace ptr_container_detail {
0036
0037
0038 template< typename T,
0039 typename Deleter =
0040 move_ptrs::default_deleter<T> >
0041 class static_move_ptr
0042 {
0043 public:
0044
0045 typedef typename remove_bounds<T>::type element_type;
0046 typedef Deleter deleter_type;
0047
0048 private:
0049
0050 struct safe_bool_helper { int x; };
0051 typedef int safe_bool_helper::* safe_bool;
0052 typedef boost::compressed_pair<element_type*, Deleter> impl_type;
0053
0054 public:
0055 typedef typename impl_type::second_reference deleter_reference;
0056 typedef typename impl_type::second_const_reference deleter_const_reference;
0057
0058
0059
0060 static_move_ptr() : impl_(0) { }
0061
0062 static_move_ptr(const static_move_ptr& p)
0063 : impl_(p.get(), p.get_deleter())
0064 {
0065 const_cast<static_move_ptr&>(p).release();
0066 }
0067
0068 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0069 static_move_ptr( const move_ptrs::move_source<static_move_ptr<T,Deleter> >& src )
0070 #else
0071 static_move_ptr( const move_ptrs::move_source<static_move_ptr>& src )
0072 #endif
0073 : impl_(src.ptr().get(), src.ptr().get_deleter())
0074 {
0075 src.ptr().release();
0076 }
0077
0078 template<typename TT>
0079 static_move_ptr(TT* tt, Deleter del)
0080 : impl_(tt, del)
0081 { }
0082
0083
0084
0085 ~static_move_ptr() { if (ptr()) get_deleter()(ptr()); }
0086
0087
0088
0089 static_move_ptr& operator=(static_move_ptr rhs)
0090 {
0091 rhs.swap(*this);
0092 return *this;
0093 }
0094
0095
0096
0097 element_type* get() const { return ptr(); }
0098
0099 element_type& operator*()
0100 {
0101 return *ptr();
0102 }
0103
0104 const element_type& operator*() const
0105 {
0106 return *ptr();
0107 }
0108
0109 element_type* operator->()
0110 {
0111 return ptr();
0112 }
0113
0114 const element_type* operator->() const
0115 {
0116 return ptr();
0117 }
0118
0119
0120 element_type* release()
0121 {
0122 element_type* result = ptr();
0123 ptr() = 0;
0124 return result;
0125 }
0126
0127 void reset()
0128 {
0129 if (ptr()) get_deleter()(ptr());
0130 ptr() = 0;
0131 }
0132
0133 template<typename TT>
0134 void reset(TT* tt, Deleter dd)
0135 {
0136 static_move_ptr(tt, dd).swap(*this);
0137 }
0138
0139 operator safe_bool() const { return ptr() ? &safe_bool_helper::x : 0; }
0140
0141 void swap(static_move_ptr& p) { impl_.swap(p.impl_); }
0142
0143 deleter_reference get_deleter() { return impl_.second(); }
0144
0145 deleter_const_reference get_deleter() const { return impl_.second(); }
0146 private:
0147 template<typename TT, typename DD>
0148 void check(const static_move_ptr<TT, DD>&)
0149 {
0150 typedef move_ptrs::is_smart_ptr_convertible<TT, T> convertible;
0151 BOOST_STATIC_ASSERT(convertible::value);
0152 }
0153
0154 #if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) || defined(BOOST_NO_SFINAE)
0155
0156 #else
0157
0158 template<typename Ptr> struct cant_move_from_const;
0159
0160 template<typename TT, typename DD>
0161 struct cant_move_from_const< const static_move_ptr<TT, DD> > {
0162 typedef typename static_move_ptr<TT, DD>::error type;
0163 };
0164
0165 template<typename Ptr>
0166 static_move_ptr(Ptr&, typename cant_move_from_const<Ptr>::type = 0);
0167
0168
0169 public:
0170 static_move_ptr(static_move_ptr&);
0171
0172
0173 private:
0174 template<typename TT, typename DD>
0175 static_move_ptr( static_move_ptr<TT, DD>&,
0176 typename
0177 move_ptrs::enable_if_convertible<
0178 TT, T, static_move_ptr&
0179 >::type::type* = 0 );
0180
0181 #endif
0182
0183
0184
0185
0186
0187 public:
0188
0189 typename impl_type::first_reference
0190 ptr() { return impl_.first(); }
0191
0192 typename impl_type::first_const_reference
0193 ptr() const { return impl_.first(); }
0194
0195 impl_type impl_;
0196 };
0197
0198 }
0199 }
0200
0201 #if defined(BOOST_MSVC)
0202 #pragma warning(pop)
0203 #endif
0204
0205 #endif