lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Replacing boost with std C++11 [Was: Fix value_cast defect sho


From: Greg Chicares
Subject: Re: [lmi] Replacing boost with std C++11 [Was: Fix value_cast defect shown by the unit test]
Date: Wed, 11 Jan 2017 15:33:06 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.5.1

On 2017-01-09 16:18, Greg Chicares wrote:
[...]
> I took a look at other lmi uses of boost

<boost/functional.hpp> is used in only one place, so it should be trivial
to replace if one has sufficient knowledge; but I don't.

AFAICT, this transformation is an equivalence:

- boost::bind1st(std::mem_fun(&Class::MemberFn), this)
+ std::bind(&Class::MemberFn, this, std::placeholders::_1)

and if that's right, then I can see a pattern (using a monospace font):

- boost::bind1st(std::mem_fun(&Class::MemberFn), this                       )
+   std::bind   (             &Class::MemberFn , this, std::placeholders::_1)

Thus:
 - delete 'std::mem_fun(' and its matching ')'
 - s/boost/std/
 - replace the early '1st' with a late ', std::placeholders::_1'
so, in visual appearance, we essentially just replace '1st' with a
magic incantation in a different place, and poof! it become C++11.
I imagine the same transformation works for non-boost std::bind1st.

I have two questions. First, does the patch below do this correctly?
(It has the virtue of actually compiling, but I don't have a unit
test to validate that it actually does the right thing.)

Second, I think you'll say we should use lambdas instead, and I'm
not opposed, but I've been struggling with the syntax for an hour
to no avail, so let me just ask how you'd do it.

Anyway, here's a "std::bind" patch:

diff --git a/msw_workarounds.cpp b/msw_workarounds.cpp
index a1a6831..b36f156 100644
--- a/msw_workarounds.cpp
+++ b/msw_workarounds.cpp
@@ -30,8 +30,6 @@
 #include "fenv_lmi.hpp"
 #include "handle_exceptions.hpp"
 
-#include <boost/functional.hpp>
-
 #include <windows.h>
 
 #include <algorithm>
@@ -48,7 +46,7 @@ MswDllPreloader::~MswDllPreloader()
     std::for_each
         (SuccessfullyPreloadedDlls_.begin()
         ,SuccessfullyPreloadedDlls_.end()
-        ,boost::bind1st(std::mem_fun(&MswDllPreloader::UnloadOneDll), this)
+        ,std::bind(&MswDllPreloader::UnloadOneDll, this, std::placeholders::_1)
         );
 }
 
@@ -75,7 +73,7 @@ void MswDllPreloader::PreloadDesignatedDlls()
     std::for_each
         (std::istream_iterator<std::string>(iss)
         ,std::istream_iterator<std::string>()
-        ,boost::bind1st(std::mem_fun(&MswDllPreloader::PreloadOneDll), this)
+        ,std::bind(&MswDllPreloader::PreloadOneDll, this, 
std::placeholders::_1)
         );
     fenv_initialize();
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]