-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace deprecated binder2nd and binder1st #1287
Replace deprecated binder2nd and binder1st #1287
Conversation
binder2nd generates error in c++17 Replace by lambdas when possible and with std::function when the type is required. decltype(lambda) does not work, so we bind the lambda to a std::function. Other option is to use std::bind and std::placeholders, but it is harder to read the code IMO. FIX DGtal-team#1221
Thanks ! In fact, we can make a There is still one |
using ValuePredicate = std::function<bool(Image::Value)>; | ||
ValuePredicate equalTo1 = [](Image::Value&& v) | ||
{ | ||
return std::forward<Image::Value>(v) == 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also simply pass v
by const-ref and test v == 1
. In fact, using &&
here forbids lvalue parameters, like in the code
const auto fn = [] ( int&& v ) { return v == 1; };
int a = 3;
bool dummy = fn(a);
Here, since the std::function
signature specifies a pass-by-value parameter, it doesn't fail.
Therefore, I also suggest to use a std::function<bool(Image::Value const&)>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, makes sense, still rusty with std::forward usage. I will change it in 12 hours
Good points, I will polish it tomorrow morning, thanks! |
(tagged as 0.9.4) |
Use std::bind instead of lambdas in examples.
I have changed the signature of std::function as @rolanddenis suggested. Replaced binder1st with std::function, and its instantiation, using std::bind1st, with a std::bind and std::placeholder. |
Thanks ! |
thanks @phcerdan & @rolanddenis Merging.. |
binder2nd generates error in c++17
Replace by lambdas when possible and with std::function when the type is
required.
decltype(lambda) does not work, so we bind the lambda to a std::function.
Other option also used is std::bind and std::placeholders.
FIX #1221
Checklist
cmake
mode (otherwise, Travis C.I. will fail).