| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //
- // const_propogating_ptr.hpp
- // pointers
- //
- // Created by Sam Jaffe on 12/3/16.
- //
- #pragma once
- #include <memory>
- #include "pointer_fwd.hpp"
- #include "ptr_compare.hpp"
- template <typename P>
- class const_propogating_ptr {
- public:
- using element_type = typename std::pointer_traits<P>::element_type;
- using pointer = element_type *;
- using reference = element_type &;
- using const_pointer = element_type const *;
- using const_reference = element_type const &;
- const_propogating_ptr() : _ptr(nullptr) {}
- const_propogating_ptr(P const & p) : _ptr(p) {}
- const_propogating_ptr(P && p) : _ptr(std::move(p)) {}
-
- const_propogating_ptr(const_propogating_ptr & other) : _ptr(other._ptr) {}
- const_propogating_ptr(const_propogating_ptr &&) = default;
- const_propogating_ptr(const_propogating_ptr const &) = delete;
- const_propogating_ptr& operator=(const_propogating_ptr & other) { _ptr = other._ptr; return *this; }
- const_propogating_ptr& operator=(const_propogating_ptr &&) = default;
- const_propogating_ptr& operator=(const_propogating_ptr const &) = delete;
-
- template <typename Y>
- explicit operator const_propogating_ptr<Y>() & {
- return _ptr;
- }
-
- template <typename Y>
- explicit operator const_ptr<Y>() const {
- return _ptr;
- }
-
- template <typename Y>
- explicit operator const_propogating_ptr<Y>() const & = delete;
-
- operator bool() const {
- return bool(_ptr);
- }
-
- reference operator*() { return *_ptr; }
- pointer get() { return std::addressof(operator*()); }
- pointer operator->() { return get(); }
-
- const_reference operator*() const { return *_ptr; }
- const_pointer get() const { return std::addressof(operator*()); }
- const_pointer operator->() const { return get(); }
-
- private:
- P _ptr;
- };
- POINTER_TEMPLATE_COMPARE( const_propogating_ptr )
|