[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();
}
- Re: [lmi] C++ modernization [Was: Replacing boost with std C++11], (continued)
- [lmi] static_assert and :argdo [Was: Replacing boost with std C++11], Greg Chicares, 2017/01/10
- Re: [lmi] static_assert and :argdo [Was: Replacing boost with std C++11], Vadim Zeitlin, 2017/01/10
- Re: [lmi] static_assert and :argdo [Was: Replacing boost with std C++11], Greg Chicares, 2017/01/11
- Re: [lmi] static_assert and :argdo [Was: Replacing boost with std C++11], Vadim Zeitlin, 2017/01/11
- Re: [lmi] static_assert and :argdo [Was: Replacing boost with std C++11], Greg Chicares, 2017/01/11
- Re: [lmi] Replacing boost with std C++11 [Was: Fix value_cast defect shown by the unit test], Greg Chicares, 2017/01/11
- Re: [lmi] Replacing boost with std C++11 [Was: Fix value_cast defect shown by the unit test],
Greg Chicares <=
- Re: [lmi] Replacing boost with std C++11 [Was: Fix value_cast defect shown by the unit test], Vadim Zeitlin, 2017/01/11
- Re: [lmi] Replacing boost with std C++11, Greg Chicares, 2017/01/20
- Re: [lmi] Replacing boost with std C++11, Vadim Zeitlin, 2017/01/20
- Re: [lmi] Replacing boost with std C++11, Greg Chicares, 2017/01/20
- Re: [lmi] Replacing boost with std C++11, Vadim Zeitlin, 2017/01/20
- Re: [lmi] Replacing boost with std C++11, Greg Chicares, 2017/01/20
- Re: [lmi] Using auto-vectorization (was: Replacing boost with std C++11), Vadim Zeitlin, 2017/01/20
- Re: [lmi] Using auto-vectorization, Greg Chicares, 2017/01/21
- Re: [lmi] Using auto-vectorization, Vadim Zeitlin, 2017/01/23
- Re: [lmi] Using auto-vectorization, Greg Chicares, 2017/01/23