Last active
May 28, 2017 17:34
-
-
Save leoetlino/2272a70232dc14176403bd291f33a4fb to your computer and use it in GitHub Desktop.
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
// @copyright Louis Dionne 2013-2017 | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
template <typename F, typename ...G> | |
struct overload_t | |
: overload_t<F>::type | |
, overload_t<G...>::type | |
{ | |
using type = overload_t; | |
using overload_t<F>::type::operator(); | |
using overload_t<G...>::type::operator(); | |
template <typename F_, typename ...G_> | |
constexpr explicit overload_t(F_&& f, G_&& ...g) | |
: overload_t<F>::type(static_cast<F_&&>(f)) | |
, overload_t<G...>::type(static_cast<G_&&>(g)...) | |
{ } | |
}; | |
template <typename F> | |
struct overload_t<F> { using type = F; }; | |
template <typename R, typename ...Args> | |
struct overload_t<R(*)(Args...)> { | |
using type = overload_t; | |
R (*fptr_)(Args...); | |
explicit constexpr overload_t(R (*fp)(Args...)) | |
: fptr_(fp) | |
{ } | |
constexpr R operator()(Args ...args) const | |
{ return fptr_(static_cast<Args&&>(args)...); } | |
}; | |
struct make_overload_t { | |
template <typename ...F, | |
typename Overload = typename overload_t< | |
typename std::decay<F>::type... | |
>::type | |
> | |
constexpr Overload operator()(F&& ...f) const { | |
return Overload(static_cast<F&&>(f)...); | |
} | |
}; | |
constexpr make_overload_t overload{}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment