From ff5bff1aa58945afdcebc408e983a2e428511e08 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 13 Feb 2026 15:15:08 -0500 Subject: [PATCH] xo-gc stack: streamline object pointer forwarding --- include/xo/facet/FacetRegistry.hpp | 39 ++++++++++++++++++++++++------ include/xo/facet/obj.hpp | 6 +++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/xo/facet/FacetRegistry.hpp b/include/xo/facet/FacetRegistry.hpp index d4b1518..9b7e7ad 100644 --- a/include/xo/facet/FacetRegistry.hpp +++ b/include/xo/facet/FacetRegistry.hpp @@ -159,7 +159,7 @@ namespace xo { * } **/ template - obj try_variant(obj from) { + obj try_variant(obj from) noexcept { return try_variant(from._typeseq(), from.data()); } @@ -173,7 +173,7 @@ namespace xo { * = FacetRegistry::variant(foo._typeseq(), foo.opaque_data()); **/ template - obj try_variant(typeseq repr_id, void * data) { + obj try_variant(typeseq repr_id, void * data) noexcept { const AFacet * iface = this->lookup(repr_id); if (iface) @@ -246,12 +246,37 @@ namespace xo { obj obj::to_facet() { - if constexpr (std::is_same_v) { - // return type has type-erased data - return FacetRegistry::instance().variant(*this); + if (this->data()) { + if constexpr (std::is_same_v) { + // return type has type-erased data + return FacetRegistry::instance().variant(*this); + } else { + // return type has known data + return obj(this->data()); + } } else { - // return type has known data - return obj(this->data()); + return obj(); + } + } + + // Deferred definitioon of obj::to_facet(), + // since implementation requires FacetRegistry + // + template + template + obj + obj::try_to_facet() noexcept + { + if (this->data()) { + if constexpr (std::is_same_v) { + // return type has type-erased data + return FacetRegistry::instance().try_variant(*this); + } else { + // return type has known data + return obj(this->data()); + } + } else { + return obj(); } } diff --git a/include/xo/facet/obj.hpp b/include/xo/facet/obj.hpp index 3619ae3..ada5c83 100644 --- a/include/xo/facet/obj.hpp +++ b/include/xo/facet/obj.hpp @@ -137,6 +137,12 @@ namespace xo { template obj to_facet(); + /** like to_facet(), + * but on failure return empty obj instead of throwing exception + **/ + template + obj try_to_facet() noexcept; + /** enabled when RRouter provides _preincrement. * Note we don't need this trick for comparison operators, * since return type is fixed.