Open malamanteau opened 7 years ago
@vectorantics I'm pretty sure from()
and distinct()
are both just cpplinq
constructs, so, yes, AFAIK, you need to vector-ize it.
You can do something like:
GeneralResult generalResult;
cpplinq::from(calculators_)
>> cpplinq::orderby([](const IResultCalculator &x) {return x.Priority; })
>> cpplinq::for_each([&](IResultCalculator &x)
{
x.CalculateResult(data, generalResult);
});
This function in the for_each will work on references to the original objects instead of copies. But then a question from my side: Is there a way to conditionally break out of this loop like the break keyword for normal loops? This solution is not very elegant:
GeneralResult generalResult;
bool brk = false;
cpplinq::from(calculators_)
>> cpplinq::orderby([](const IResultCalculator &x) {return x.Priority; })
>> cpplinq::for_each([&](IResultCalculator &x)
{
if (brk)
{
return;
}
x.CalculateResult(data, generalResult);
if (something)
{
brk = true;
}
});
The preferred way would be
for (auto&& x : ... >> experimental::container())
I was wondering, how can I iterate over query results without putting them into a vector first?
So for example, if I do this:
I would rather iterate over each item in-place, without making a copy, is there a way to do this?