Fun With Type Erasure

Fun With Type Erasure

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

11:00 - 12:30 Thursday 7th April 2022 BST



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.:

	"request": "baz",
	"count": 1,
	"id": "two",
	"payload": \{ "three": 3 }

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.

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.