Alf P. Steinbach said:
For example, for the task of reading from an input stream one can define
Code:
namespace cppx {
using std::istream;
using std::istream_iterator;
using std::ostream;
using std::ostream_iterator;
using std::string;
template< class Value >
class Istream_reader
// :public Non_copyable
{
private:
istream* p_stream_;
public:
typedef istream_iterator< Value > It;
auto begin() const -> It { return It( *p_stream_ ); }
auto end() const -> It { return It(); }
Istream_reader( istream& stream ): p_stream_( &stream ) {}
};
} // namespace cppx
I really don't understand your point. You wrote something like 8 no-op
lines in that example that do absolutely nothing, plus a bunch of
unneeded syntax... for what purpose, exactly? To deliberately make it
look more complicated than it really needs to be? Why?
My point was: The range-based for cannot be used in all situations,
in which case you have to use a regular for. What exactly is your point?
I think it comes down to Rube Goldberg's rule: why use anything simple
and straightforward when a complex and convoluted method can accomplish
the same task? Impress the unwashed masses with the complexity and earn
respect and admiration of many...
To quote Martin Shobe in this same subthread:
"He just showed you how to use a range-based for in a situation you said
it couldn't be used in. That would be his point."
I'm surprised at you, Victor.
You know that comments such as yours, which mainly go to imagined
motives of a person, and in a derogatory fashion, would NEVER be
accepted in clc++m. Furthermore what little you provide of technical
assessment is incorrect. The code above is utterly trivial, ad simple as
possible, on the other end of the scale from "complex".
And as shown in the the context removed, the above code not only allows
a range based for to do the input iterator job, which is contrary to
Juha's assertion, proving him wrong, but
it also simplifies and clarifies that code.
Cheers,
- Alf (pretty disappointed, both about Juha's reaction to being proved
wrong, and about your follow-up false statements and imagined motives).