// 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 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 T* AnyPtr(const std::any& any) noexcept { T* const* ptr = std::any_cast(&any); return ptr ? *ptr : nullptr; } } // namespace util #endif // BITCOIN_UTIL_ANY_H