summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-25 17:50:04 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-28 02:10:47 +0100
commitb656ad280092832ce47df3b7752be0a8052fcd20 (patch)
tree9f5eff2d9853bb26b0d2e4d48255c7033a0fc1fd /lib
parentTidy and de-dupe enumDetails (diff)
downloadilt-b656ad280092832ce47df3b7752be0a8052fcd20.tar.bz2
ilt-b656ad280092832ce47df3b7752be0a8052fcd20.tar.xz
ilt-b656ad280092832ce47df3b7752be0a8052fcd20.zip
Add AnyPtr for accepting pointers of any kind into a function
Diffstat (limited to 'lib')
-rw-r--r--lib/stdTypeDefs.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/stdTypeDefs.hpp b/lib/stdTypeDefs.hpp
index 8d17c33..317cdb3 100644
--- a/lib/stdTypeDefs.hpp
+++ b/lib/stdTypeDefs.hpp
@@ -3,7 +3,34 @@
#include <memory>
#include <vector>
+template<typename T> struct AnyPtr {
+ // cppcheck-suppress noExplicitConstructor
+ AnyPtr(T * p) : ptr {p} { }
+ // cppcheck-suppress noExplicitConstructor
+ template<typename S> AnyPtr(const S & p) : ptr {p.get()} { }
+ auto
+ get() const
+ {
+ return ptr;
+ }
+ auto
+ operator->() const
+ {
+ return ptr;
+ }
+ auto &
+ operator*() const
+ {
+ return *ptr;
+ }
+
+private:
+ T * ptr;
+};
+
template<typename T> struct StdTypeDefs {
+ using AnyPtr = ::AnyPtr<T>;
+ using AnyCPtr = ::AnyPtr<const T>;
using Ptr = std::shared_ptr<T>;
using CPtr = std::shared_ptr<const T>;
using WPtr = std::weak_ptr<const T>;