Skip to content

Instantly share code, notes, and snippets.

@vittorioromeo
Created October 17, 2016 08:49
Show Gist options
  • Save vittorioromeo/282d5288bbe8af31bf5623930386983d to your computer and use it in GitHub Desktop.
Save vittorioromeo/282d5288bbe8af31bf5623930386983d to your computer and use it in GitHub Desktop.
#include <type_traits>
#include <experimental/type_traits>
template <typename T, typename TVoid = void>
struct is_overloaded : std::true_type { };
template <typename T>
struct is_overloaded<T, std::void_t<decltype(&std::decay_t<T>::operator())>>: std::false_type { };
struct s0
{
template <typename T0>
void operator()(T0){ }
};
struct s1
{
void operator()(int){ }
void operator()(float){ }
};
struct s2
{
void operator()(int){ }
};
int main()
{
auto l0 = [](auto){};
auto l1 = [](int){};
auto l2 = [](int) -> float {};
static_assert(is_overloaded<decltype(l0)>{}, "");
static_assert(!is_overloaded<decltype(l1)>{}, "");
static_assert(!is_overloaded<decltype(l2)>{}, "");
static_assert(is_overloaded<s0>{}, "");
static_assert(is_overloaded<s1>{}, "");
static_assert(!is_overloaded<s2>{}, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment