Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions CppLinq/cpplinq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,28 +544,31 @@ namespace cpplinq
container_type&& container
)
: container (std::move (container))
, current (container.begin ())
, upcoming (container.begin ())
, end (container.end ())
{
upcoming = current = this->container.begin();
end = this->container.end();
}

CPPLINQ_INLINEMETHOD from_copy_range (
container_type const & container
)
: container (container)
, current (container.begin ())
, upcoming (container.begin ())
, end (container.end ())
{
upcoming = current = this->container.begin();
end = this->container.end();
}

CPPLINQ_INLINEMETHOD from_copy_range (from_copy_range const & v)
: container (v.container)
, current (v.current)
, upcoming (v.upcoming)
, end (v.end)
{
iterator_type s_b = v.container.begin();
auto d_c = std::distance(s_b, v.current);
auto d_u = std::distance(v.current, v.upcoming); // upcoming is never before current.
current = container.begin();
std::advance(current, d_c);
upcoming = current;
std::advance(upcoming, d_u);
end = container.end(); // end must re-create from new container.
}

CPPLINQ_INLINEMETHOD from_copy_range (from_copy_range && v) CPPLINQ_NOEXCEPT
Expand Down Expand Up @@ -2113,10 +2116,13 @@ namespace cpplinq
return true;
}

if (range.next ())
while(range.next ())
{
inner_range = predicate (range.front ());
return inner_range && inner_range->next ();
if(inner_range && inner_range->next ())
{
return true;
}
}

inner_range.clear ();
Expand Down
35 changes: 35 additions & 0 deletions Test/CppLinqTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// ----------------------------------------------------------------------------------------------
#include <limits.h>
#include <stdio.h>
#include <cmath>
// ----------------------------------------------------------------------------------------------
#include "../CppLinq/cpplinq.hpp"
// ----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1775,7 +1776,41 @@ namespace
}
}
}
{
std::vector<int> seed;
seed.push_back(1);
seed.push_back(2);
std::vector<int> select_many_result =
from (seed)
>> select_many ([&seed](int n){
if(n == 1)
return from(std::vector<int>());
else
return from(seed);
})
>> to_vector ()
;

TEST_ASSERT (2U, select_many_result.size ());
}
{
std::vector<int> seed;
seed.push_back(1);
std::vector<int> select_many_result =
from (seed)
>> select_many ([](int n){
std::vector<int> seq;
seq.push_back(n);
seq.push_back(n);
return from_copy(std::move(seq));
})
>> to_vector ()
;

TEST_ASSERT (2U, select_many_result.size ());
TEST_ASSERT (1, select_many_result[0]);
TEST_ASSERT (1, select_many_result[1]);
}
}

void test_orderby ()
Expand Down