ClientServerProject/switch_expression.h

21 lines
395 B
C++

#pragma once
#include <functional>
template<typename T>
void on(T what, std::tuple<T, std::function<void()>> match)
{
auto [a,b] = match;
if (what == a)
b;
}
template<typename T>
void on(T what, std::tuple<T, std::function<void()>> match, std::tuple<T, std::function<void()>> others)
{
auto [a,b] = match;
if (what == a)
b;
else
on(what, others);
}