/** ** \file misc/ref.hxx ** \brief Implementation of misc::ref. **/ #pragma once #include #include namespace misc { /*-----------------. | Ctors and dtor. | `-----------------*/ template template ref::ref(const ref& other) : super_type(other) {} template ref::ref(const ref& other) : super_type(other) {} template ref::ref(T* p) : super_type(p) {} /*---------------------. | Equality operators. | `---------------------*/ template bool ref::operator==(const T* other) const { return this->get() == other; } template bool ref::operator!=(const T* other) const { return !(*this == other); } /*--------. | Casts. | `--------*/ template template ref ref::unsafe_cast() const { ref res; (std::dynamic_pointer_cast(*this)).swap(res); return res; } template template ref ref::cast() const { if (!this->get() || !this->is_a()) throw std::bad_cast(); return unsafe_cast(); } template template bool ref::is_a() const { return dynamic_cast(this->get()); } } // namespace misc