Skip to content

Instantly share code, notes, and snippets.

@IceSandwich
Created February 7, 2025 03:34
Show Gist options
  • Save IceSandwich/a0b6608248478d2c7029d3995ea87cfc to your computer and use it in GitHub Desktop.
Save IceSandwich/a0b6608248478d2c7029d3995ea87cfc to your computer and use it in GitHub Desktop.
overloaded
#include <gtest/gtest.h>
#include "overloaded.hpp"
TEST(Overload, function) {
overloaded s{
[](int) { std::cout << "int" << std::endl; },
[](double) { std::cout << "double" << std::endl; },
[](std::string) { std::cout << "string" << std::endl; }
};
s(1);
s(1.);
s("1");
}
#pragma once
template <typename ...Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <typename ...Ts> overloaded(Ts...) -> overloaded<Ts...>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment