44# include < pybind11/pybind11.h>
55# include < string>
66# include < type_traits>
7+ # include < utility>
78
89# include " data_types.hpp"
910
@@ -13,45 +14,53 @@ namespace utils {
1314
1415
1516// Generic function binder for all types in a TypeList
16- template <typename ... T>
17- void bindForSpecifiedTypeList (py::module_ &m, const std::string &baseName, TypeList<T...>, auto functionTemplate) {
18- (m.def ((baseName + " _" + std::string (getTypeName<T>())).c_str (), functionTemplate.template operator ()<T>()), ...);
17+ template <typename FunctionTemplate, typename ... T>
18+ void bindForSpecifiedTypeList (
19+ py::module_ &m,
20+ const std::string &baseName,
21+ TypeList<T...>,
22+ FunctionTemplate&& functionTemplate) {
23+ (m.def (
24+ (baseName + " _" + std::string (getTypeName<T>())).c_str (),
25+ std::forward<FunctionTemplate>(functionTemplate).template operator ()<T>(TypeTag<T>{})
26+ ),
27+ ...);
1928}
2029
2130// Helpers to bind functions for predefined TypeList (see data_types.hpp)
2231template <typename FunctionTemplate>
23- void bindForFloatingTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
24- bindForSpecifiedTypeList (m, baseName, FloatingTypes{}, functionTemplate );
32+ void bindForFloatingTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
33+ bindForSpecifiedTypeList (m, baseName, FloatingTypes{}, std::forward<FunctionTemplate>(ft) );
2534}
2635
2736template <typename FunctionTemplate>
28- void bindForPositiveIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
29- bindForSpecifiedTypeList (m, baseName, PositiveIntegralTypes{}, functionTemplate );
37+ void bindForPositiveIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
38+ bindForSpecifiedTypeList (m, baseName, PositiveIntegralTypes{}, std::forward<FunctionTemplate>(ft) );
3039}
3140
3241template <typename FunctionTemplate>
33- void bindForSignedIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
34- bindForSpecifiedTypeList (m, baseName, SignedIntegralTypes{}, functionTemplate );
42+ void bindForSignedIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
43+ bindForSpecifiedTypeList (m, baseName, SignedIntegralTypes{}, std::forward<FunctionTemplate>(ft) );
3544}
3645
3746template <typename FunctionTemplate>
38- void bindForIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
39- bindForSpecifiedTypeList (m, baseName, IntegralTypes{}, functionTemplate );
47+ void bindForIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
48+ bindForSpecifiedTypeList (m, baseName, IntegralTypes{}, std::forward<FunctionTemplate>(ft) );
4049}
4150
4251template <typename FunctionTemplate>
43- void bindForFloatingAndIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
44- bindForSpecifiedTypeList (m, baseName, FloatingAndIntegralTypes{}, functionTemplate );
52+ void bindForFloatingAndIntegralTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
53+ bindForSpecifiedTypeList (m, baseName, FloatingAndIntegralTypes{}, std::forward<FunctionTemplate>(ft) );
4554}
4655
4756template <typename FunctionTemplate>
48- void bindForScalarTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
49- bindForSpecifiedTypeList (m, baseName, ScalarTypes{}, functionTemplate );
57+ void bindForScalarTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
58+ bindForSpecifiedTypeList (m, baseName, ScalarTypes{}, std::forward<FunctionTemplate>(ft) );
5059}
5160
5261template <typename FunctionTemplate>
53- void bindForStringAndScalarTypes (py::module_ &m, const std::string &baseName, FunctionTemplate functionTemplate ) {
54- bindForSpecifiedTypeList (m, baseName, StringAndScalarTypes{}, functionTemplate );
62+ void bindForStringAndScalarTypes (py::module_ &m, const std::string &baseName, FunctionTemplate&& ft ) {
63+ bindForSpecifiedTypeList (m, baseName, StringAndScalarTypes{}, std::forward<FunctionTemplate>(ft) );
5564}
5665
5766}
0 commit comments