diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 6f2a6d95c..59e836443 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -38,6 +38,7 @@ set(base_SOURCES filelogger.cpp filelogger.hpp filelogger-ti.hpp function.cpp function.hpp function-ti.hpp function-script.cpp functionwrapper.hpp initialize.cpp initialize.hpp + intrusive-ptr.hpp io-engine.cpp io-engine.hpp journaldlogger.cpp journaldlogger.hpp journaldlogger-ti.hpp json.cpp json.hpp json-script.cpp diff --git a/lib/base/intrusive-ptr.hpp b/lib/base/intrusive-ptr.hpp new file mode 100644 index 000000000..eb0f67e66 --- /dev/null +++ b/lib/base/intrusive-ptr.hpp @@ -0,0 +1,22 @@ +/* Icinga 2 | (c) 2025 Icinga GmbH | GPLv2+ */ + +#pragma once + +#include "base/i2-base.hpp" +#include +#include +#include + +// std::hash is only implemented starting from Boost 1.74. Implement it ourselves for older version to allow using +// boost::intrusive_ptr inside std::unordered_set<> or as the key of std::unordered_map<>. +// https://github.com/boostorg/smart_ptr/commit/5a18ffdc5609a0e64b63e47cb81c4f0847e0c087 +#if BOOST_VERSION < 107400 +template +struct std::hash> +{ + std::size_t operator()(const boost::intrusive_ptr& ptr) const noexcept + { + return std::hash{}(ptr.get()); + } +}; +#endif /* BOOST_VERSION < 107400 */ diff --git a/lib/base/object.hpp b/lib/base/object.hpp index aae28ae88..008426b8d 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -5,6 +5,7 @@ #include "base/i2-base.hpp" #include "base/debug.hpp" +#include "base/intrusive-ptr.hpp" #include #include #include diff --git a/lib/base/shared.hpp b/lib/base/shared.hpp index 63b35cb2f..2acec012e 100644 --- a/lib/base/shared.hpp +++ b/lib/base/shared.hpp @@ -4,6 +4,7 @@ #define SHARED_H #include "base/atomic.hpp" +#include "base/intrusive-ptr.hpp" #include #include #include