Skip to content

Instantly share code, notes, and snippets.

@bbannier
Last active June 24, 2017 17:32
Show Gist options
  • Save bbannier/d44c0d436ac08af2b99981f2a5bdc52c to your computer and use it in GitHub Desktop.
Save bbannier/d44c0d436ac08af2b99981f2a5bdc52c to your computer and use it in GitHub Desktop.
#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