2016-03-12 06:47:15 +08:00
resolve
=======
utility to pick overloaded C++ function calls
---------------------------------------------
.. code-block :: cpp
:caption: function: resolve C++ overload
template <typename... Args, typename F>
auto resolve( F f );
`` resolve `` is a function that is meant to help users pick a single function out of a group of overloaded functions in C++. You can use it to pick overloads by specifying the signature as the first template argument. Given a collection of overloaded functions:
.. code-block :: cpp
:linenos:
int overloaded(int x);
int overloaded(int x, int y);
int overloaded(int x, int y, int z);
You can disambiguate them using `` resolve `` :
.. code-block :: cpp
:linenos:
2016-03-30 12:31:18 +08:00
auto one_argument_func = resolve<int(int)>( overloaded );
auto two_argument_func = resolve<int(int, int)>( overloaded );
auto three_argument_func = resolve<int(int, int, int)>( overloaded );
2016-03-12 06:47:15 +08:00
2016-03-30 12:31:18 +08:00
This resolution becomes useful when setting functions on a :doc: `table<table>` or :doc: `state_view<state>` :
2016-03-12 06:47:15 +08:00
.. code-block :: cpp
:linenos:
sol::state lua;
2016-03-30 12:31:18 +08:00
lua.set_function("a", resolve<int(int)>( overloaded ) );
lua.set_function("b", resolve<int(int, int)>( overloaded ));
lua.set_function("c", resolve<int(int, int, int)>( overloaded ));