std::bind1st, std::bind2nd, and std::mem_fun were deprecated in C++11 and removed in C++17.
GCC is the only compiler that allows using these functions regardless of the standard. Clang (both LLVM, and Apple Clang) and MSVC will error out on standard >=C++17. This is currently mainly an issue for LLVM Clang as starting LLVM 16, Clang defaults to C++17 and no standard used to be set in qmake.
This PR addresses this issue by using C++11 lambdas. This typically offers better performances compared to the alternative std::bind and std::mem_fn, and better extensibility if more methods need to be called in the same loop.
Benchmark for reference
Here are some speed results for calling the same member function 1'000'000'000 times:
```
Took 3.79699s to run 1000000000 steps with lambda
Took 4.25883s to run 1000000000 steps with mem_fn // Only for object pointers, no equivalent to mem_fun_ref
Took 13.6731s to run 1000000000 steps with bind
Took 16.3081s to run 1000000000 steps with mem_fn+bind
```
Also see https://github.com/pokemon-speedrunning/gambatte-core/issues/18
std::bind1st
,std::bind2nd
, andstd::mem_fun
were deprecated in C++11 and removed in C++17.GCC is the only compiler that allows using these functions regardless of the standard. Clang (both LLVM, and Apple Clang) and MSVC will error out on standard >=C++17. This is currently mainly an issue for LLVM Clang as starting LLVM 16, Clang defaults to C++17 and no standard used to be set in qmake.
This PR addresses this issue by using C++11 lambdas. This typically offers better performances compared to the alternative
std::bind
andstd::mem_fn
, and better extensibility if more methods need to be called in the same loop.Benchmark for reference
Here are some speed results for calling the same member function 1'000'000'000 times: ``` Took 3.79699s to run 1000000000 steps with lambda Took 4.25883s to run 1000000000 steps with mem_fn // Only for object pointers, no equivalent to mem_fun_ref Took 13.6731s to run 1000000000 steps with bind Took 16.3081s to run 1000000000 steps with mem_fn+bind ```