Last active
June 24, 2017 17:32
-
-
Save bbannier/d44c0d436ac08af2b99981f2a5bdc52c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <type_traits> | |
using std::is_callable_v; | |
template <typename Fn, typename A> constexpr auto bind(Fn fn, A &&a) noexcept { | |
return [fn, a](auto &&... args) { return fn(a, args...); }; | |
} | |
int main() { | |
constexpr auto b0 = bind([]() {}, 4); | |
constexpr auto b2 = bind([](int, int) {}, 4); | |
// OK. | |
static_assert(is_callable_v<decltype(b2)(int)>); | |
// FAILING to compile. | |
static_assert(!is_callable_v<decltype(b0)()>); | |
static_assert(!is_callable_v<decltype(b2)()>); | |
static_assert(!is_callable_v<decltype(b2)(int, int)>); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment