From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/ref.hxx | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tiger-compiler/lib/misc/ref.hxx (limited to 'tiger-compiler/lib/misc/ref.hxx') diff --git a/tiger-compiler/lib/misc/ref.hxx b/tiger-compiler/lib/misc/ref.hxx new file mode 100644 index 0000000..ae740fd --- /dev/null +++ b/tiger-compiler/lib/misc/ref.hxx @@ -0,0 +1,71 @@ +/** + ** \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 -- cgit v1.2.3