You're a Parenthesis

By Zhihao Yuan

Callable Objects in Java, C#, Rust, and C++

It is trivial to make a class callable in C++. Just define operator(). But what if you cannot?

Adding operator() requires three things to check simultaneously: you’re working on an object of a class type, you own the class type, and the action of "call" has an unambiguous meaning in the class. You may think a closure or a bind_front object will solve all problems. But, depending on which pieces are missing, such a solution can range from adequate to a code smell.

The talk will begin with an old tale: Java — a language with no operator() and was transitioning to adding lambda. Then, we will look into how Java, C♯, and Rust avoid all the restrictions of operator() by not adding operator() to the language. Finally, we’ll introduce a small library change in C++ that achieves all the benefits we’ve seen and even more.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.