3 ms·
But in a language with mutating side effects, and iterators, I'm not sure what this buys you over: for (auto& num = file.line_iterator(); num != file.end()
by ori_b 12y ago
But in a language with mutating side effects, and iterators, I'm not sure what this buys you over:
for (auto& num = file.line_iterator(); num != file.end(); num++) {
if (atoi(num) == 42)
return true;
return false;
Note that 'line_iterator()' isn't something that (as far as I know) is defined in the C++ standard library, but there's nothing preventing it.
- hrjet 12y ago> But in a language with mutating side effects, and iterators, I'm not sure what this buys you... Side-effect free, functional style of programming.
- deleted 12y ago[deleted]
- wyager 12y agoCompare the code you wrote with what I wrote. Lazy evaluation gets you all that, with no extra code, all the time. Imagine writing that iterator stuff for every single applicable thing in the entire program. There are also other places where lazy evaluation is useful and you can't use iterators, like a function that will only use a portion of its arguments depending on some condition.