Created
February 7, 2025 03:34
-
-
Save IceSandwich/a0b6608248478d2c7029d3995ea87cfc to your computer and use it in GitHub Desktop.
overloaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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