In c++ 11, how to invoke an arbitrary callable object?

Rather than implementing INVOKE yourself, use one of the library features that uses it. In particular, std::reference_wrapper works. Thus you can have the effect of std::invoke(f, args…) with std::ref(f)(args…): template<typename F, typename… Args> auto invoke(F f, Args&&… args) -> decltype(std::ref(f)(std::forward<Args>(args)…)) { return std::ref(f)(std::forward<Args>(args)…); } I didn’t forward f because std::reference_wrapper requires that the object passed … Read more

How can I wrap a method so that I can kill its execution if it exceeds a specified timeout?

You should take a look at these classes : FutureTask, Callable, Executors Here is an example : public class TimeoutExample { public static Object myMethod() { // does your thing and taking a long time to execute return someResult; } public static void main(final String[] args) { Callable<Object> callable = new Callable<Object>() { public Object … Read more

What is a “callable”?

A callable is anything that can be called. The built-in callable (PyCallable_Check in objects.c) checks if the argument is either: an instance of a class with a __call__ method or is of a type that has a non null tp_call (c struct) member which indicates callability otherwise (such as in functions, methods etc.) The method … Read more