lmi
[Top][All Lists]
Advanced

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

Re: [lmi] Parallel blues


From: Vadim Zeitlin
Subject: Re: [lmi] Parallel blues
Date: Wed, 28 Jun 2017 01:44:13 +0200

On Tue, 27 Jun 2017 21:26:39 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-06-22 13:42, Vadim Zeitlin wrote:
GC> > On Thu, 22 Jun 2017 13:32:53 +0000 Greg Chicares <address@hidden> wrote:
GC> > 
GC> > GC> On 2017-06-21 12:50, Vadim Zeitlin wrote:
GC> > GC> > On Wed, 21 Jun 2017 12:26:36 +0000 Greg Chicares <address@hidden> 
wrote:
GC> > GC> [...]
GC> > GC> > GC> Then I realized that I could implement
GC> > GC> > GC>   bool is_null_stream(std::ostream&);
GC> > GC> > GC> and use that to conditionalize stream output in 'zero.hpp', and 
its
GC> > GC> > GC> effect on calendar_date_test's speed is the same as using 
#ifdef.
GC> 
GC> Setting 'badbit' automatically for null streams means that no such
GC> function is necessary: it suffices to test the stream state (see below).
GC> 
GC> >  Compare with:
GC> > 
GC> >   if(iteration_stream)
GC> >       {
GC> >       iteration_stream
GC> >           << "iteration " << number_of_iterations++
GC> >           << " iterand "  << value_cast<std::string>(a)
GC> >           << " value "    << value_cast<std::string>(fa)
GC> >           << std::endl
GC> >           ;
GC> >       }
GC> 
GC> That's what I've done, except with a slightly different test:
GC> 
GC> - if(iteration_stream)
GC> + if(iteration_stream.good())
GC> 
GC> IOW, the optional<> nature is already embedded in the stream state.

 Hmm, I never thought of bad bit in this way, but I guess it could be seen
like that even if it's an unusual kind of optionality because it can change
both implicitly (if a real error occurs while the stream is used) and
explicitly (by just resetting the stream state). So I'd still argue that
using a separate bit to indicate the stream presence or absence would be
cleaner than reusing this one, as the former is purely compile-time while
the latter is a run-time construct. E.g. consider what happens if there is
an error while writing to the stream the first time it's used in
decimal_root() function: the subsequent checks will just silently fail and
you'd end up with a partial debug log for some unclear reason. Granted,
this seems unlikely to happen in practice and should be simple enough to
find if it does, but things like this still make me uncomfortable.

 Also, more prosaically, in practice, it seems to be pretty rare to check
for the stream being good() before using it, so it still seems like it
would be too easy to forget to do it.

 But I'm not going to continue arguing about this as I think I already gave
all the arguments I could.

 Regards,
VZ


reply via email to

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