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
10 changes: 6 additions & 4 deletions include/boolinq/boolinq.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,16 +781,18 @@ namespace boolinq {
// Linq Creators
////////////////////////////////////////////////////////////////

template<typename T>
Linq<std::pair<T, T>, typename std::iterator_traits<T>::value_type> from(const T & begin, const T & end)
template<typename T, typename _TValue = typename std::iterator_traits<T>::value_type>
Linq<std::pair<T, T>, _TValue> from(const T & begin, const T & end)
{
return Linq<std::pair<T, T>, typename std::iterator_traits<T>::value_type>(
return Linq<std::pair<T, T>, _TValue>(
std::make_pair(begin, end),
[](std::pair<T, T> &pair) {
if (pair.first == pair.second) {
throw LinqEndException();
}
return *(pair.first++);
const _TValue &ret = *pair.first;
++pair.first;
return ret;
}
);
}
Expand Down
19 changes: 19 additions & 0 deletions test/LinqTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@

#include <gtest/gtest.h>

#include "CommonTests.h"

#include "boolinq.h"

using namespace boolinq;

TEST(Linq, Unique)
{
std::vector<std::unique_ptr<int> > vec = {
std::unique_ptr<int>(new int (1)),
std::unique_ptr<int>(new int (2)),
std::unique_ptr<int>(new int (3))
};

auto rng = from(vec)
.select([](const std::unique_ptr<int> &uniquePtr) { return *uniquePtr.get(); })
.toStdVector();

int ans[] = {1,2,3};

CheckRangeEqArray(rng, ans);
}

// Where Tests

TEST(Linq, WhereOdd)
Expand Down