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


From: Vadim Zeitlin
Subject: Re: [lmi] Replacing boost with std C++11
Date: Mon, 23 Jan 2017 02:49:52 +0100

On Sat, 21 Jan 2017 10:36:52 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-01-20 23:47, Greg Chicares wrote:
GC> > On 2017-01-20 23:10, Vadim Zeitlin wrote:
GC> > [...s/boost::bind/std::bind/...]
GC> >> if you do run into any
GC> >> problems with doing the straightforward replacement, it would, IMHO, be
GC> >> worth replacing boost::bind with something else entirely rather than
GC> >> leaving it be.
GC> > 
GC> > I'll try replacing boost::bind() with std::bind().
GC> > 
GC> > If that fails, I'll abort the task.
GC> 
GC> It was mostly straightforward:
GC>  - s/boost::bind/std::bind/g
GC>  - s/boost:ref/std::ref/
GC>  - prepend "std::placeholder::" to _1, _2, ...
GC> In one unit-test file, boost::bind() specified the return type, but
GC> with C++11 we can must replace "<void>" with this atrocity:
GC>   std::bind((void 
(product_database::*)(std::vector<double>&,e_database_key) 
const)&product_database::Query,&db,v,DB_MaturityAge)

 I think explicitly specifying the template argument is _very_ slightly
better, i.e. I'd write this as

        std::bind<void (product_database::*)(std::vector<double>&, 
e_database_key) const>(&product_database::Query,           &db, v, 
DB_MaturityAge))

but it does indeed show why I prefer writing this as

        [&db, &v](){ db.Query(v, DB_MaturityAge); }

very well, thank you for the example.


GC> BTW, why the verbosely-named "placeholders"?

 No idea, really, but I'd hazard a guess that it was just inherited from
boost. And while people do, of course, always use the using directive to
avoid typing their full names, it's still sometimes useful to have them in
a separate namespace, or at least was, before standardization, as it
allowed to use "_1" to refer to a placeholder in one library (e.g.
Boost.Bind) in some places and to a placeholder from another library (e.g.
Boost.Lambda) elsewhere.

 Regards,
VZ


reply via email to

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