1 // Copyright (c) 2021-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 5 #ifndef BITCOIN_UTIL_OVERLOADED_H
6 #define BITCOIN_UTIL_OVERLOADED_H
7 8 namespace util {
9 //! Overloaded helper for std::visit. This helper and std::visit in general are
10 //! useful to write code that switches on a variant type. Unlike if/else-if and
11 //! switch/case statements, std::visit will trigger compile errors if there are
12 //! unhandled cases.
13 //!
14 //! Implementation comes from and example usage can be found at
15 //! https://en.cppreference.com/w/cpp/utility/variant/visit#Example
16 template<class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
17 } // namespace util
18 19 #endif // BITCOIN_UTIL_OVERLOADED_H
20