21
21
namespace py = pybind11;
22
22
using namespace cpp_features ::containers;
23
23
using cpp_features::concepts::CopyableType;
24
+ using cpp_features::concepts::TransformFunction;
24
25
25
26
namespace {
26
27
@@ -32,6 +33,12 @@ auto GetItem(const Container<T> &self, typename Container<T>::size_type index) -
32
33
throw py::index_error (" Index out of bounds" );
33
34
}
34
35
36
+ template <typename Input, typename Output>
37
+ auto GetTransformWrapper (const Container<Input> &self,
38
+ const std::function<Output(Input)> &transform) {
39
+ return self.template GetTransformedView <Output>(transform);
40
+ }
41
+
35
42
template <CopyableType T>
36
43
auto GetIter (const Container<T> &self) {
37
44
return py::make_iterator (self.begin (), self.end ());
@@ -69,7 +76,9 @@ void BindContainers(py::module &m) {
69
76
.def (" at" , &GetItem<int >)
70
77
.def (" view" , &IntContainer::GetView)
71
78
.def (" filter" , &IntContainer::GetFilteredView<std::function<bool (int )>>)
72
- .def (" transform" , &IntContainer::GetTransformedView<std::function<int (int )>>)
79
+ .def (" transform" , &GetTransformWrapper<int , int >)
80
+ .def (" transform" , &GetTransformWrapper<int , double >)
81
+ .def (" transform" , &GetTransformWrapper<int , std::string>)
73
82
.def (" __len__" , &IntContainer::GetSize)
74
83
.def (" __bool__" , [](const IntContainer &self) { return !self.IsEmpty (); })
75
84
.def (" __getitem__" , &GetItem<int >)
@@ -90,7 +99,9 @@ void BindContainers(py::module &m) {
90
99
.def (" at" , &GetItem<double >)
91
100
.def (" view" , &FloatContainer::GetView)
92
101
.def (" filter" , &FloatContainer::GetFilteredView<std::function<bool (double )>>)
93
- .def (" transform" , &FloatContainer::GetTransformedView<std::function<double (double )>>)
102
+ .def (" transform" , &GetTransformWrapper<double , int >)
103
+ .def (" transform" , &GetTransformWrapper<double , double >)
104
+ .def (" transform" , &GetTransformWrapper<double , std::string>)
94
105
.def (" __len__" , &FloatContainer::GetSize)
95
106
.def (" __bool__" , [](const FloatContainer &self) { return !self.IsEmpty (); })
96
107
.def (" __getitem__" , &GetItem<double >)
@@ -111,8 +122,9 @@ void BindContainers(py::module &m) {
111
122
.def (" at" , &GetItem<std::string>)
112
123
.def (" view" , &StringContainer::GetView)
113
124
.def (" filter" , &StringContainer::GetFilteredView<std::function<bool (const std::string &)>>)
114
- .def (" transform" ,
115
- &StringContainer::GetTransformedView<std::function<std::string (const std::string &)>>)
125
+ .def (" transform" , &GetTransformWrapper<std::string, int >)
126
+ .def (" transform" , &GetTransformWrapper<std::string, double >)
127
+ .def (" transform" , &GetTransformWrapper<std::string, std::string>)
116
128
.def (" __len__" , &StringContainer::GetSize)
117
129
.def (" __bool__" , [](const StringContainer &self) { return !self.IsEmpty (); })
118
130
.def (" __getitem__" , &GetItem<std::string>)
0 commit comments