| 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 : private detail::get_ptr<P> {
- 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() noexcept : _ptr(nullptr) {}
- const_propogating_ptr(P const & p) noexcept(detail::is_nt_cc<P>::value) : _ptr(p) {}
- const_propogating_ptr(P && p) noexcept(detail::is_nt_mc<P>::value) : _ptr(std::move(p)) {}
-
- const_propogating_ptr(const_propogating_ptr &) noexcept(detail::is_nt_cc<P>::value) = default;
- const_propogating_ptr(const_propogating_ptr &&) noexcept(detail::is_nt_mc<P>::value) = default;
- const_propogating_ptr(const_propogating_ptr const &) = delete;
- const_propogating_ptr& operator=(const_propogating_ptr &) noexcept(detail::is_nt_ca<P>::value) = default;
- const_propogating_ptr& operator=(const_propogating_ptr &&) noexcept(detail::is_nt_ma<P>::value) = default;
- const_propogating_ptr& operator=(const_propogating_ptr const &) = delete;
-
- template <typename Y>
- explicit operator const_propogating_ptr<Y>() & noexcept(detail::is_nt_c<P, Y>::value) {
- return _ptr;
- }
-
- template <typename Y>
- explicit operator const_ptr<Y>() const noexcept(detail::is_nt_c<P, Y>::value) {
- return _ptr;
- }
-
- template <typename Y>
- explicit operator const_propogating_ptr<Y>() const & = delete;
-
- operator bool() const noexcept {
- return static_cast<bool>(_ptr);
- }
-
- reference operator*() noexcept(noexcept(*_ptr)) { return *_ptr; }
- pointer get() noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
- pointer operator->() noexcept(noexcept(get())) { return get(); }
-
- const_reference operator*() const noexcept(noexcept(*_ptr)) { return *_ptr; }
- const_pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
- const_pointer operator->() const noexcept(noexcept(get())) { return get(); }
-
- private:
- P _ptr;
- };
- POINTER_TEMPLATE_COMPARE( const_propogating_ptr )
|