sol2
sol2 copied to clipboard
Simplify `sol::wrap`
Now sol::wrap
is implemented as follows:
https://github.com/ThePhD/sol2/blob/a7da2a8e889498b0c5a4ed6d9e3463af02bb6102/include/sol/function_types_templated.hpp#L132-L139
This is not so user-friendly API, because one should use sol::wrap<decltype(<expr>), <expr>>
(or write macro to avoid copy-pasting).
I suggest replacing it with:
template <auto F>
struct wrap {
using type = decltype(F);
...
};
- sol2 requires C++17, so there should be no concern about using
auto
in non-type template parameters - this is a breaking change, however upcoming v4.0.0 release is the right time to do it
- if you don't want to break anything, you can simply add
template <auto F> struct foobar
with different name, butsol::wrap
is a really good name for such a wrapper
P.S. you can also refactor sol::function_detail
with auto F
feature without breaking sol2 API:
https://github.com/ThePhD/sol2/blob/a7da2a8e889498b0c5a4ed6d9e3463af02bb6102/include/sol/function_types_templated.hpp#L30-L115