From 2aa6ea8a0b4f7e36d9b89ec84524e2bb3fecf5b6 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Tue, 2 Jul 2019 14:57:28 +0300 Subject: [PATCH] Add test for unique_ptr --- include/boolinq/boolinq.h | 10 ++++++---- test/LinqTest.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/boolinq/boolinq.h b/include/boolinq/boolinq.h index 882fd39..96c863b 100644 --- a/include/boolinq/boolinq.h +++ b/include/boolinq/boolinq.h @@ -781,16 +781,18 @@ namespace boolinq { // Linq Creators //////////////////////////////////////////////////////////////// - template - Linq, typename std::iterator_traits::value_type> from(const T & begin, const T & end) + template::value_type> + Linq, _TValue> from(const T & begin, const T & end) { - return Linq, typename std::iterator_traits::value_type>( + return Linq, _TValue>( std::make_pair(begin, end), [](std::pair &pair) { if (pair.first == pair.second) { throw LinqEndException(); } - return *(pair.first++); + const _TValue &ret = *pair.first; + ++pair.first; + return ret; } ); } diff --git a/test/LinqTest.cpp b/test/LinqTest.cpp index 7285cdb..aaf4b0b 100644 --- a/test/LinqTest.cpp +++ b/test/LinqTest.cpp @@ -5,10 +5,29 @@ #include +#include "CommonTests.h" + #include "boolinq.h" using namespace boolinq; +TEST(Linq, Unique) +{ + std::vector > vec = { + std::unique_ptr(new int (1)), + std::unique_ptr(new int (2)), + std::unique_ptr(new int (3)) + }; + + auto rng = from(vec) + .select([](const std::unique_ptr &uniquePtr) { return *uniquePtr.get(); }) + .toStdVector(); + + int ans[] = {1,2,3}; + + CheckRangeEqArray(rng, ans); +} + // Where Tests TEST(Linq, WhereOdd)