2023-12-09 14:55:01 +01:00
|
|
|
// Copyright (c) 2021-present The Bitcoin Core developers
|
2021-02-16 22:36:26 -05:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_UTIL_OVERLOADED_H
|
|
|
|
#define BITCOIN_UTIL_OVERLOADED_H
|
|
|
|
|
|
|
|
namespace util {
|
|
|
|
//! Overloaded helper for std::visit. This helper and std::visit in general are
|
|
|
|
//! useful to write code that switches on a variant type. Unlike if/else-if and
|
|
|
|
//! switch/case statements, std::visit will trigger compile errors if there are
|
|
|
|
//! unhandled cases.
|
|
|
|
//!
|
|
|
|
//! Implementation comes from and example usage can be found at
|
|
|
|
//! https://en.cppreference.com/w/cpp/utility/variant/visit#Example
|
|
|
|
template<class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
|
|
|
|
|
2023-12-09 14:55:01 +01:00
|
|
|
//! Explicit deduction guide (not needed after clang-17)
|
2021-02-16 22:36:26 -05:00
|
|
|
template<class... Ts> Overloaded(Ts...) -> Overloaded<Ts...>;
|
|
|
|
} // namespace util
|
|
|
|
|
|
|
|
#endif // BITCOIN_UTIL_OVERLOADED_H
|