nextpnr_base_types: Add overload lambda visitor helper

This commit is contained in:
Rowan Goemans 2024-09-26 18:24:59 +02:00
parent be826df3ce
commit 0729f0166c

View File

@ -29,11 +29,27 @@
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include <string> #include <string>
#include <variant>
#include "hashlib.h" #include "hashlib.h"
#include "idstring.h" #include "idstring.h"
#include "nextpnr_namespaces.h" #include "nextpnr_namespaces.h"
/* Helper struct to overload lambdas for variabt visiting
so you can do:
std::variant<int, std::string> var = 42;
std::visit(overloaded{
[](int arg) { std::cout << "Integer: " << arg << '\n'; },
[](const std::string& arg) { std::cout << "String: " << arg << '\n'; }
}, var);
*/
template <class... Ts> struct overloaded : Ts...
{
using Ts::operator()...;
};
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
struct GraphicElement struct GraphicElement