Warning, file /include/boost/locale/hold_ptr.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_LOCALE_HOLD_PTR_H
0008 #define BOOST_LOCALE_HOLD_PTR_H
0009
0010 #include <boost/locale/config.hpp>
0011 #include <boost/core/exchange.hpp>
0012
0013 namespace boost { namespace locale {
0014
0015
0016 template<typename T>
0017 class hold_ptr {
0018 public:
0019
0020 hold_ptr() : ptr_(nullptr) {}
0021
0022
0023 explicit hold_ptr(T* v) : ptr_(v) {}
0024
0025
0026 ~hold_ptr() { delete ptr_; }
0027
0028
0029 hold_ptr(const hold_ptr&) = delete;
0030 hold_ptr& operator=(const hold_ptr&) = delete;
0031
0032 hold_ptr(hold_ptr&& other) noexcept : ptr_(exchange(other.ptr_, nullptr)) {}
0033 hold_ptr& operator=(hold_ptr&& other) noexcept
0034 {
0035 swap(other);
0036 return *this;
0037 }
0038
0039
0040 T const* get() const { return ptr_; }
0041
0042 T* get() { return ptr_; }
0043
0044
0045 explicit operator bool() const { return ptr_ != nullptr; }
0046
0047
0048 T const& operator*() const { return *ptr_; }
0049
0050 T& operator*() { return *ptr_; }
0051
0052
0053 T const* operator->() const { return ptr_; }
0054
0055 T* operator->() { return ptr_; }
0056
0057
0058 T* release() { return exchange(ptr_, nullptr); }
0059
0060
0061 void reset(T* p = nullptr)
0062 {
0063 if(ptr_)
0064 delete ptr_;
0065 ptr_ = p;
0066 }
0067
0068
0069 void swap(hold_ptr& other) noexcept { ptr_ = exchange(other.ptr_, ptr_); }
0070
0071 private:
0072 T* ptr_;
0073 };
0074
0075 }}
0076
0077 #endif