Replace std::bind1st/bind2nd with C++11 lambdas; target C++17#71
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/flr/FLasher/sessions/a4a30070-fc6f-4c8c-b140-b3fec11bf6db Co-authored-by: iagomosqueira <[email protected]>
Agent-Logs-Url: https://github.com/flr/FLasher/sessions/a4a30070-fc6f-4c8c-b140-b3fec11bf6db Co-authored-by: iagomosqueira <[email protected]>
Copilot
AI
changed the title
[WIP] Update code to remove deprecated std::bind1st and std::bind2nd
Replace std::bind1st/bind2nd with C++11 lambdas; target C++17
May 5, 2026
iagomosqueira
approved these changes
May 5, 2026
iagomosqueira
left a comment
Member
There was a problem hiding this comment.
Tested on R 4.5. and R 4.60 in Linux.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
std::bind1standstd::bind2ndwere deprecated in C++11 and removed in C++17, causing compilation failures under C++17 toolchains. All usages are confined to scalar arithmetic operators insrc/FLQuant_base.cpp.Changes
src/FLQuant_base.cpp— Replace all 14bind1st/bind2ndcalls inoperator+=,-=,*=,/=and the corresponding free operators with equivalent lambdas, preserving exact operand order:src/Makevars,src/Makevars.win— BumpCXX_STDfromCXX11toCXX17.Original prompt
Create a pull request for repository
flr/FLasherto make the package compile cleanly under C++17 by removing deprecated/removedstd::bind1standstd::bind2ndusage in the package's C++ sources.Context:
src/and includes headers underinst/include/.src/FLQuant_base.cppusesstd::bind1standstd::bind2ndinsidestd::transformcalls for scalar arithmetic operators (e.g.,operator+=,operator-=,operator*=,operator/=and related free operators).Required changes:
std::bind1standstd::bind2ndinsrc/FLQuant_base.cppwith equivalent C++11+ lambdas. Ensure semantics remain identical, including for overloads templated onT2(scalar rhs) and for free operators likeT - FLQuant_base<T>that currently usebind1st(std::minus<T>(), lhs).bind2nd(op, rhs): replace with[rhs](const T& x){ return x OP rhs; }(or appropriate operation).bind1st(op, lhs): replace with[lhs](const T& x){ return lhs OP x; }.TandT2(do not inadvertently narrow types). If needed, useautoin lambda parameter anddecltype/std::common_type_tto preserve types.src/Makevarsandsrc/Makevars.win(if present) to specifyCXX_STD = CXX17.Acceptance criteria:
bind1storbind2ndremain insrc/.Files likely involved:
src/FLQuant_base.cppsrc/Makevarsand/orsrc/Makevars.win(discover and update as appropriate)Notes:
masteras default branch (badges showbranch/master). Use the repository default branch as PR base.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: how can I make the C++ code in flr/FLasher follow C++17 and C++20 deprecation of std::bind?
Assistant: To make the C++ code in
flr/FLasher“follow C++17/C++20” with respect tostd::binddeprecation guidance, replacestd::bind(...)usage with lambdas (or direct function objects) and, where applicable, switch tostd::invoke/std::applypatterns. Practically, you’ll (1) find allstd::bindcall sites, (2) convert each to an equivalent lambda capturing whatbindcaptured, and (3) ensure your build uses-std=c++17or-std=c++20so you catch remaining legacy constructs.Because I can’t see your repository contents from what you’ve provided, below is the concrete “how” (with conversion templates) and what I’d do in that codebase. If you paste a couple of representative
std::bindlines fromflr/FLasher, I can rewrite them precisely.1) Why change
std::bind(and what “deprecated” means here)std::bindis not removed, but it is widely discouraged and triggers warnings under various “deprecation / modernization” checks (e.g., clang-tidymodernize-avoid-bind). Many projects treat it as effectively deprecated._1,_2, …).2) Find all uses
Typical search patterns:
std::bindusing namespace std::placeholders_1,_2,_3(placeholders)3) Mechanical replacements (most common cases)
A) Binding a free function
Before
After
If you know the parameter type, prefer explicit:
B) Binding a member function with an object pointer
Before
auto cb = std::bind(&Worker::step, workerPtr, _1);After
C) Binding a member function with a reference to an object
Before
auto cb = std::bind(&Worker::step, std::ref(worker), _1);After
D) Reordering / duplicating args (common “bind trick”)
Before
After
E) Binding to adapt to a callback signature (event systems, threads, etc.)
Before
After