| 247 | auto pointer_sentinel(std::shared_ptr<T> &ptr) const |
| 248 | { |
| 249 | struct Sentinel { |
| 250 | Sentinel(std::shared_ptr<T> &t_ptr, Data &data) |
| 251 | : m_ptr(t_ptr), m_data(data) |
| 252 | { |
| 253 | } |
| 254 | |
| 255 | ~Sentinel() |
| 256 | { |
| 257 | // save new pointer data |
| 258 | const auto ptr_ = m_ptr.get().get(); |
| 259 | m_data.get().m_data_ptr = ptr_; |
| 260 | m_data.get().m_const_data_ptr = ptr_; |
| 261 | } |
| 262 | |
| 263 | Sentinel& operator=(Sentinel&&s) = default; |
| 264 | Sentinel(Sentinel &&s) = default; |
| 265 | |
| 266 | operator std::shared_ptr<T>&() const |
| 267 | { |
| 268 | return m_ptr.get(); |
| 269 | } |
| 270 | |
| 271 | Sentinel &operator=(const Sentinel &) = delete; |
| 272 | Sentinel(Sentinel&) = delete; |
| 273 | |
| 274 | std::reference_wrapper<std::shared_ptr<T>> m_ptr; |
| 275 | std::reference_wrapper<Data> m_data; |
| 276 | }; |
| 277 | |
| 278 | return Sentinel(ptr, *(m_data.get())); |
| 279 | } |