File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ class shared_func<R(Args...)> {
123123 template <typename FO>
124124 struct wrapper : public wrapper_base {
125125 FO func_object;
126- wrapper (FO&& f) : func_object(std::forward<FO> (f)) {
126+ wrapper (FO f) : func_object(std::move (f)) {
127127 this ->func = +[](void * obj, Args&&... args) -> R {
128128 return static_cast <wrapper*>(obj)->func_object (std::forward<Args>(args)...);
129129 };
@@ -144,7 +144,7 @@ class shared_func<R(Args...)> {
144144 if (!f) {
145145 return {};
146146 }
147- return std::make_shared<wrapper<FP>>(f);
147+ return std::make_shared<wrapper<FP* >>(f);
148148 }
149149};
150150
Original file line number Diff line number Diff line change @@ -55,3 +55,14 @@ TEST_CASE("lambda") {
5555 CHECK (func.use_count () == 2 );
5656 }
5757}
58+
59+ int sum (int a, int b) { return a + b; }
60+
61+ TEST_CASE (" free func" ) {
62+ itlib::shared_func<int (int , int )> func = sum;
63+ CHECK (func (1 , 2 ) == 3 );
64+ func = [](int a, int b) { return a * b; };
65+ CHECK (func (3 , 4 ) == 12 );
66+ func = sum;
67+ CHECK (func (3 , 4 ) == 7 );
68+ }
You can’t perform that action at this time.
0 commit comments