Function signatures

Started by CatalinNic, 03 September 2019, 11:46:50

CatalinNic

I've tried in past to make a gui from scratch before using this library and i wondered: how the library stores function signature?

Kvaz1r

There is std::function<> in modern C++. Of course there are also could be some templates tricks for works with variadic arguments but in base it's std::function.

texus

#2
Kvaz1r is correct, all you need is a simple std::function<void()> to store the callback function.

Without adding extra code around it, you can only store free functions that have no arguments, but even in complex cases std::function<void()> is what you store it in eventually (unless you e.g. always have the widget as argument in which case you put that type between the brackets). If you strip away all the complex signal handling code in TGUI then you find a simple map that stores all the callback functions and their unique id.
Code (cpp) Select
std::map<unsigned int, std::function<void()>> m_handlers;