Function signatures

  • 2 Replies
  • 35 Views
Function signatures
« on: 03 September 2019, 11:46:50 »
I've tried in past to make a gui from scratch before using this library and i wondered: how the library stores function signature?

Re: Function signatures
« Reply #1 on: 03 September 2019, 12:53:50 »
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

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Function signatures
« Reply #2 on: 03 September 2019, 19:08:12 »
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.
std::map<unsigned int, std::function<void()>> m_handlers;
« Last Edit: 03 September 2019, 19:09:57 by texus »