diff options
author | TheCharlatan <seb.kung@gmail.com> | 2023-05-17 17:47:25 +0200 |
---|---|---|
committer | TheCharlatan <seb.kung@gmail.com> | 2023-05-20 12:03:33 +0200 |
commit | 7eee356c0a7fefd70c8de21689efa335f52a69ba (patch) | |
tree | 424f75e0ee33d4a7de12976123f59ee14eb5a729 /src/util | |
parent | 44de325d95447498036479c3112ba741caf45bf6 (diff) |
refactor: Split util::AnyPtr into its own file
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/any.h | 26 | ||||
-rw-r--r-- | src/util/system.h | 17 |
2 files changed, 26 insertions, 17 deletions
diff --git a/src/util/any.h b/src/util/any.h new file mode 100644 index 0000000000..4562c5bd8a --- /dev/null +++ b/src/util/any.h @@ -0,0 +1,26 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_ANY_H +#define BITCOIN_UTIL_ANY_H + +#include <any> + +namespace util { + +/** + * Helper function to access the contained object of a std::any instance. + * Returns a pointer to the object if passed instance has a value and the type + * matches, nullptr otherwise. + */ +template<typename T> +T* AnyPtr(const std::any& any) noexcept +{ + T* const* ptr = std::any_cast<T*>(&any); + return ptr ? *ptr : nullptr; +} + +} // namespace util + +#endif // BITCOIN_UTIL_ANY_H diff --git a/src/util/system.h b/src/util/system.h index 463713d565..719cd28f97 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -13,7 +13,6 @@ #include <compat/assumptions.h> #include <compat/compat.h> -#include <any> #include <set> #include <stdint.h> #include <string> @@ -36,20 +35,4 @@ void runCommand(const std::string& strCommand); */ int GetNumCores(); -namespace util { - -/** - * Helper function to access the contained object of a std::any instance. - * Returns a pointer to the object if passed instance has a value and the type - * matches, nullptr otherwise. - */ -template<typename T> -T* AnyPtr(const std::any& any) noexcept -{ - T* const* ptr = std::any_cast<T*>(&any); - return ptr ? *ptr : nullptr; -} - -} // namespace util - #endif // BITCOIN_UTIL_SYSTEM_H |