| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //
- // const_ptr.hpp
- // pointers
- //
- // Created by Sam Jaffe on 1/5/17.
- //
- #pragma once
- #include <memory>
- #include "pointer_fwd.hpp"
- #include "ptr_compare.hpp"
- template <typename P>
- class const_ptr : private detail::get_ptr<P> {
- public:
- using element_type = typename std::pointer_traits<P>::element_type;
- using pointer = element_type const *;
- using reference = element_type const &;
- const_ptr() noexcept : _ptr(nullptr) {}
- const_ptr(P const & p) noexcept(detail::is_nt_cc<P>::value) : _ptr(p) {}
- const_ptr(P && p) noexcept(detail::is_nt_mc<P>::value) : _ptr(std::move(p)) {}
-
- template <typename Y>
- explicit operator const_ptr<Y>() const noexcept(detail::is_nt_c<P, Y>::value) {
- return _ptr;
- }
-
- operator bool() const noexcept {
- return static_cast<bool>(_ptr);
- }
- reference operator*() const noexcept(noexcept(*_ptr)) { return *_ptr; }
- pointer get() const noexcept(noexcept(detail::get_ptr<P>::get(_ptr))) { return detail::get_ptr<P>::get(_ptr); }
- pointer operator->() const noexcept(noexcept(get())) { return get(); }
- private:
- P _ptr;
- };
- POINTER_TEMPLATE_COMPARE( const_ptr )
|