From 9153155076ada5728b9d6f68bc3e066ff67a7497 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 11 Sep 2020 13:35:51 +1000 Subject: [PATCH] singleton: add "maybe" pointer accessor --- singleton.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/singleton.hpp b/singleton.hpp index 67d57835..304897d5 100644 --- a/singleton.hpp +++ b/singleton.hpp @@ -71,15 +71,25 @@ namespace cruft { } - /// returns a reference to sole instantiated value + /// Returns a reference to the instantiated value. /// - /// `instantiate` must have already been called before `get` is called. + /// `instantiate` must have already been called before `get` is called + /// otherwise the results are undefined. static SelfT& get (void) { CHECK (instance); return *instance; } + + + /// returns a pointer to the instantiated value if it exists, else we + /// return nullptr. + static SelfT* + maybe (void) + { + return instance; + } }; };