Re: newbie question about data I/O
On Sep 21, 6:59 am, Jerry Coffin <jerryvcof...@yahoo.com> wrote:
In article <87773dca-e68e-427c-962e-3d0aedc2fbf6
@l35g2000vba.googlegroups.com>, all...@tele.ntnu.no says...
On 19 Sep, 08:12, "Ross A. Finlayson" <ross.finlay...@gmail.com>
wrote:
while(!!input_file)
while(!!input_file)
while ( !!(in >> temp) vec.push_back(temp);
while(!!in)
Any reason for the consitent use of two exclamation marks?
I'm not sure why _he's_ doing it, but it's an old C trick for
converting from int to bool -- i.e. zero stays zero, but any non-zero
value becomes a one.
--
Later,
Jerry.
There is already an overload of istream to convert it to bool.
#include <iosfwd>
std::istream in;
if(in) 0; // calls the globally defined complement operator
// that checks the istream state, rather istream typeconverts
// which is implemented as !
if(!!in) 0; // could it be overriden to another that returns that
converts to bool ?
class boolean_evaluable
{
operator ()(bool& b){b = true;}
}
boolean_evaluable& operator !(istream& in){}
if(!!in) 0; // different?
One would think that the iostream operator would be resolved first to
be the maybe class-defined type, the complement operator is overloaded
as a member function of iostream. If the function was otherwise
resolved to be the overload for the istream that returns a
boolean_evaluable, then the identical source code statements could
have different effects from template inclusion. Then, if "in" was
some in-place input stream with the layout in an object, the user
could activate code with the extra double-negative pairs that are no-
ops.
Sure, the syntax above might actually not be ISO C++ but it seems that
it might be, wondering if it should "(void)0" instead of "0" and
whether it's ISO C++ if the compiler can erase the loop.
It seems an idea about trying to autogenerate the composite inserters
and extractors via the careful observance of the semantics of the I/O
streams, and re-implementing them, with compile-time support of the
generation of the class framework, so to say, there isn't much of a
class framework as really just some templates that collapse leaving
behind type converters that the language interpreter compiles per
unit, where there's quite a large template class framework where the
idea is to templatize functions around the parent types of the
template typename types, to automatically generate the inserters and
extractors from C variables and structs, with the notion of not having
standard includes on the file, defining templates around the built-in
types, including the standard includes, then for some reason canceling
the templates yet not those that were generated afterwards from the
legacy classes, with the temporary templates.
Regards,
Ross F.