Please rotate your tablet to be horizontal.

You can dismiss this notice but please note that this experience has not been designed for mobile devices and so will be less than optimal

Back To Schedule

Fun With Type Erasure

+ Dispatching Data from Abstract Structure to Function Parameters in C++

11:00 - 12:30 Thursday 7th April 2022 BST
Intermediate
Advanced
Add to Google Calendar

Sometimes we want some kind of magic that would call appropriate handler for a request, and put appropriate request fields into function parameters, e.g.:
```json
{
"request": "baz",
"count": 1,
"id": "two",
"payload": { "three": 3 }
}
```

```c#
public class Program
{
public static void foo()
{ }
public static void bar([Name("count")] int i)
{ }
public static void baz([Name("count")] int i,
[Name("id")] string s,
[Name("payload")] JsonElement p)
{ }
}
```
(That is, in this C# example, for request "baz" we want the function `baz` to be called, and values of fields "count", "id" and "payload" to be passed to corresponding function parameters.)

We want this magic even more when the number of handlers with many parameters grows significantly.
In this talk we will concentrate on type erasure in C++ in order to make convenient and user friendly way of organizing request handlers.

We will examine several approaches, their profit, how can we make it better, and what else can we do with it. There will be a lot of code. (And template magic, you just can't do anything without it.)

Pavel Novikov

Got an engineering degree in missilery from BMSTU.

Loves C++ and knows how to cook it.

Likes metaprogramming, multithreading and asynchronous programming, coroutine adoption enthusiast.