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: Greg Chicares
Subject: Re: [lmi] Replacing boost with std C++11
Date: Fri, 20 Jan 2017 22:57:38 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 2017-01-20 19:25, Vadim Zeitlin wrote:
> On Fri, 20 Jan 2017 18:07:49 +0000 Greg Chicares <address@hidden> wrote:
[...]
> GC> I haven't given any thought to <boost/bind.hpp>
> GC> yet, but this article:
> GC>   
> http://stackoverflow.com/questions/10555566/difference-between-c11-stdbind-and-boostbind
> GC> seems hopeful.
> 
>  I'd strongly prefer to get rid of bind() completely rather than just
> replacing boost::bind with std::bind.

Yes, that should be our goal. Still, if I can do a simple change
like s/boost::bind/std::bind/g and it works, then that achieves
the minor goal of reducing dependency on boost at little cost.
I've already gone far down the path of replacing boost, and I
don't want to stop prematurely.

> I did use bind() enthusiastically
> before, but it was just because we didn't have any better alternatives in
> C++98. Now that we have lambdas, they're IMO invariably easier to both
> write and read/modify. Please, let's just use them instead of dealing with
> bind() and its placeholders and other warts.

And let's include std::transform() etc., too. For example:

// TODO ?? Replace these long lines with PETE expressions.
    // ET !! miscellaneous_charges += AmortLoad_ + ExtraSepAcctCharge_;
    std::transform(miscellaneous_charges.begin(), miscellaneous_charges.end(), 
AmortLoad_         .begin(), miscellaneous_charges.begin(), 
std::plus<double>());
    std::transform(miscellaneous_charges.begin(), miscellaneous_charges.end(), 
ExtraSepAcctCharge_.begin(), miscellaneous_charges.begin(), 
std::plus<double>());

Replacing the names with simpler ones, we have double-precision
vectors X, A, and B, and we wish to do this:
    X += A + B; // If we had the expressiveness of, say, FORTRAN.
which can be expressed tersely and elegantly in C++98 thus:
    std::transform(X.begin(), X.end(), A.begin(), X.begin(), 
std::plus<double>());
    std::transform(X.begin(), X.end(), B.begin(), X.begin(), 
std::plus<double>());
The question is whether to use PETE for that. That seemed like the
obvious thing to do years ago; I just never found the time. PETE
may very well be terser and faster than anything C++11 provides,
in vector-arithmetic cases like this.

But other instances of bind() must be replaced some other way.
PETE lets us write many simple APL expressions pretty well, but
bind() doesn't really let us write decent Haskell.




reply via email to

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