Why is stdin.byLine.writeln so slow?
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 13 15:34:50 PDT 2014
On Friday, 13 June 2014 at 22:25:25 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
In C/C++,
> you'd have
> to manually write nested loops to print out the data, which may
> involve
> manually calling accessor methods, manually counting them,
> perhaps
> storing intermediate output fragments in temporary buffers,
> encapsulating all this jazz in a throwaway function so that you
> can use
> it at multiple strategic points (in D you just copy-n-paste the
> single
> line above), etc.. Pure lose.
>
> T
In C++, I usually use copy/transform:
*std::copy(begin(), end(), std::ostream_iterator<T>(std::cout,
"\n")) = "\n";
or
*std::tranform(begin(), end(),
std::ostream_iterator<T>(std::cout, "\n"), [](???){???}) = "\n";
It's a bit verbose, and looks like ass to the non-initiated, but
once you are used to it, it's quite convenient. It's just
something that grows on you. You can stack on a "foreach" if you
need more "depth".
foreach(begin(), end(), [](R& r){
*std::copy(r.begin(), r.end(),
std::ostream_iterator<T>(std::cout, "\n")) = "\n";
});
Though arguably, that's just a loop in disguise :)
More information about the Digitalmars-d-learn
mailing list