From b4e3e99cc8efb18c9de236a42e195b6b509917ba Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 18 Aug 2015 15:29:38 +0200 Subject: [PATCH] base: add Weak_object::weak_ptr const Issue #1649 --- repos/base/include/base/weak_ptr.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/repos/base/include/base/weak_ptr.h b/repos/base/include/base/weak_ptr.h index 79d60c2d2..0290cf48e 100644 --- a/repos/base/include/base/weak_ptr.h +++ b/repos/base/include/base/weak_ptr.h @@ -290,6 +290,22 @@ struct Genode::Weak_object : Genode::Weak_object_base * Obtain a weak pointer referring to the weak object */ Weak_ptr weak_ptr() { return _weak_ptr(); } + + /** + * Const version of 'weak_ptr' + * + * This function is useful in cases where the returned weak pointer is + * merely used for comparison operations. + */ + Weak_ptr const weak_ptr_const() const + { + /* + * We strip off the constness of 'this' to reuse the internal non-const + * code of the weak object. The executed operations are known to not + * alter the state of the weak object. + */ + return const_cast(this)->_weak_ptr(); + } };