Loading…
CppCon 2019 has ended
Friday, September 20 • 14:45 - 15:45
`unique_pseudofunction`: N overloads for the price of 1

Log in to save this to your schedule and see who's attending!

This talk will present a class template that behaves almost like `unique_function`, but lacks one of its key restrictions: having just one overload of `operator()`.

`std::function` is an excellent tool for interface design. It encapsulates almost any object that is invocable the right way. `unique_function` is an even better tool. It can encapsulate some types that `std::function` can't - the ones that are move-only. Unfortunately, it is still invocable in just one way. You get one list of argument types and that's what you must pass.

What if the object you want to pass is invocable in more than one way? What if its `operator()` is a template that you will instantiate with N different types? What if it is a variadic template to which you will pass 0-N arguments? What if you use tag dispatch to do N different things?

If you want these things, as well as the type erasure offered by `std::function` and the move-only support offered by `unique_function`, then `unique_pseudofunction` is the class for you.

Follow the path I took towards realizing that `unique_pseudofunction` is the solution to most of my problems. We'll break this down into the following steps:
Building a simple non-generic `unique_function`
Making it generic
Adding a small buffer optimization
Extending it to support more than one overload of `operator()`

We will also look in close detail at several problems solved along the way, and several others that are still unsolved.

This talk involves small amounts of C++17 and large amounts of template metaprogramming, function references, and type erasure.

Speakers
FG

Filipp Gelman

Software Developer, Bloomberg LP
At Bloomberg LP since 2016, Filipp enjoys exploring the obscure, arcane, and esoteric corners of the C++ language. He is known among his coworkers for heavy use of templates, emphasis on compile time computation, and abusing language features for nefarious purposes.


Friday September 20, 2019 14:45 - 15:45
Crest 3

Attendees (42)




Twitter Feed