Last active
January 4, 2019 18:52
-
-
Save neontorrent/216fd1bea9c8bb5a593214ad8d87ddae to your computer and use it in GitHub Desktop.
Boilerplates for C++
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
//Template Type Check | |
template<typename T, typename F, | |
typename = std::enable_if_t<std::is_invocable<F, T>::value> > | |
void foo() | |
{} | |
template<typename T, typename F, | |
typename = typename std::enable_if<std::is_invocable<F, T>::value>::type > | |
void foo() | |
{} | |
template<typename T, typename F, | |
typename std::enable_if<std::is_invocable<F, T>::value>::type* = nullptr > | |
void foo() | |
{} | |
template<typename T, typename F> | |
auto foo() -> std::enable_if_t<std::is_invocable<F, T>::value>::type | |
{} | |
template<typename T, typename F> | |
void foo() | |
{ | |
static_assert(std::is_invocable<F, T>::value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ad-hoc polymorphism with templated type can be achieved using:
std::enable_if_t<std::is_xxxx::value>
std::void_t<decltype(expression)>
concept