Commit fb578714 authored by Anton Bukov's avatar Anton Bukov

Merge pull request #15 from babelvit/linq-creators

Linq creators
parents d121f345 8f8baff2
...@@ -4,4 +4,6 @@ ipch ...@@ -4,4 +4,6 @@ ipch
*.opensdf *.opensdf
*.sdf *.sdf
*.user *.user
*.suo *.suo
\ No newline at end of file [Bb]uild*
nbproject
# Common variables. # Common variables.
SET (CMAKE_BUILD_TYPE "Release") SET (CMAKE_BUILD_TYPE "Release")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wundef -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wundef -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
......
...@@ -15,7 +15,7 @@ std::vector<int> vecCppIter (benchmarkVectorSize, 0); ...@@ -15,7 +15,7 @@ std::vector<int> vecCppIter (benchmarkVectorSize, 0);
int main (int argc, const char ** argv) int main (int argc, char ** argv)
{ {
// Preparing input benchmark data (the same data sets for all tests). // Preparing input benchmark data (the same data sets for all tests).
srand(0xDEADBEEF); srand(0xDEADBEEF);
......
Subproject commit 0a1593b06f4c79edcd4cd150dc37c8a0446e2e4a Subproject commit 354b14d1a0770da28f1725fa8409af3264de3a79
...@@ -757,48 +757,43 @@ namespace boolinq ...@@ -757,48 +757,43 @@ namespace boolinq
return from<T>(array, array + N); return from<T>(array, array + N);
} }
// std::list, vector, dequeue template<template<class> class TV, typename TT>
auto from(const TV<TT> & container)
-> decltype(from<TT>(std::begin(container), std::end(container)))
{
return from<TT>(std::begin(container), std::end(container));
}
// std::list, std::vector, std::dequeue
template<template<class,class> class TV, typename TT, typename TU> template<template<class,class> class TV, typename TT, typename TU>
auto from(const TV<TT,TU> & container) -> LinqObj<Enumerator<TT,IteratorContainerPair<decltype(container.cbegin()),const TV<TT,TU> > > > auto from(const TV<TT,TU> & container)
-> decltype(from<TT>(std::begin(container), std::end(container)))
{ {
typedef IteratorContainerPair<decltype(container.cbegin()),const TV<TT,TU> > DataType; return from<TT>(std::begin(container), std::end(container));
return Enumerator<TT,DataType>([](DataType & pair){
return (pair.first == pair.second.cend()) ? throw EnumeratorEndException() : *(pair.first++);
}, DataType(container, [](const TV<TT,TU> & cont){return cont.cbegin();}));
} }
// std::set // std::set
template<template<class,class,class> class TV, typename TT, typename TS, typename TU> template<template<class,class,class> class TV, typename TT, typename TS, typename TU>
auto from(const TV<TT,TS,TU> & container) -> LinqObj<Enumerator<TT,IteratorContainerPair<decltype(container.cbegin()),const TV<TT,TS,TU> > > > auto from(const TV<TT,TS,TU> & container)
-> decltype(from<TT>(std::begin(container), std::end(container)))
{ {
typedef IteratorContainerPair<decltype(container.cbegin()),const TV<TT,TS,TU> > DataType; return from<TT>(std::begin(container), std::end(container));
return Enumerator<TT,DataType>([](DataType & pair){
return (pair.first == pair.second.cend()) ? throw EnumeratorEndException() : *(pair.first++);
}, DataType(container, [](const TV<TT,TS,TU> & cont){return cont.cbegin();}));
} }
// std::map // std::map
template<template<class,class,class,class> class TV, typename TK, typename TT, typename TS, typename TU> template<template<class,class,class,class> class TV, typename TK, typename TT, typename TS, typename TU>
auto from(const TV<TK,TT,TS,TU> & container) -> LinqObj<Enumerator<std::pair<TK,TT>,IteratorContainerPair<decltype(container.cbegin()),const TV<TK,TT,TS,TU> > > > auto from(const TV<TK,TT,TS,TU> & container)
-> decltype(from<std::pair<TK, TT> >(std::begin(container), std::end(container)))
{ {
typedef IteratorContainerPair<decltype(container.cbegin()),const TV<TK,TT,TS,TU> > DataType; return from<std::pair<TK,TT> >(std::begin(container), std::end(container));
return Enumerator<std::pair<TK,TT>,DataType>([](DataType & pair){
return (pair.first == pair.second.cend()) ? throw EnumeratorEndException() : *(pair.first++);
}, DataType(container, [](const TV<TK,TT,TS,TU> & cont){return cont.cbegin();}));
} }
// std::array // std::array
template<template<class,unsigned> class TV, typename TT, unsigned TL> template<template<class,size_t> class TV, typename TT, size_t TL>
auto from(const TV<TT,TL> & container) -> LinqObj<Enumerator<TT,IteratorContainerPair<decltype(container.cbegin()),const TV<TT,TL> > > > auto from(const TV<TT,TL> & container)
-> decltype(from<TT>(std::begin(container), std::end(container)))
{ {
typedef IteratorContainerPair<decltype(container.cbegin()),const TV<TT,TL> > DataType; return from<TT>(std::begin(container), std::end(container));
return Enumerator<TT,DataType>([](DataType & pair){
return (pair.first == pair.second.cend()) ? throw EnumeratorEndException() : *(pair.first++);
}, DataType(container, [](const TV<TT,TL> & cont){return cont.cbegin();}));
} }
template<typename T> template<typename T>
......
# Common variables. # Common variables.
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wundef -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wundef -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo") SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <string> #include <string>
#include <set>
#include <map>
#include <array>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "CommonTests.h" #include "CommonTests.h"
...@@ -60,6 +63,39 @@ TEST(IterRange, VectorInt) ...@@ -60,6 +63,39 @@ TEST(IterRange, VectorInt)
CheckRangeEqArray(from<int>(vec.cbegin(), vec.cend()), ans); CheckRangeEqArray(from<int>(vec.cbegin(), vec.cend()), ans);
} }
TEST(IterRange, SetInt)
{
std::set<int> set = {1,2,3,4,5};
int ans[] = {1,2,3,4,5};
CheckRangeEqSet(from(set), ans);
CheckRangeEqSet(from<int>(set.begin(), set.end()), ans);
CheckRangeEqSet(from<int>(set.cbegin(), set.cend()), ans);
}
TEST(IterRange, MapInt)
{
std::map<int, int> map = {{5,1},{4,2},{3,3},{2,4},{1,5}};
std::pair<int, int> ans[] = {{5,1},{4,2},{3,3},{2,4},{1,5}};
CheckRangeEqArray(from(map)
.orderBy([](std::pair<int,int> p){ return p.second; }), ans);
CheckRangeEqArray(from<std::pair<int,int> >(map.begin(), map.end())
.orderBy([](std::pair<int,int> p){ return p.second; }), ans);
CheckRangeEqArray(from<std::pair<int,int> >(map.cbegin(), map.cend())
.orderBy([](std::pair<int,int> p){ return p.second; }), ans);
}
TEST(IterRange, StdArrayInt)
{
std::array<int, 5> arr = {1,2,3,4,5};
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(arr), ans);
CheckRangeEqArray(from<int>(arr.begin(), arr.end()), ans);
CheckRangeEqArray(from<int>(arr.cbegin(), arr.cend()), ans);
}
TEST(IterRange, ArrayInt) TEST(IterRange, ArrayInt)
{ {
int arr[] = {1,2,3,4,5}; int arr[] = {1,2,3,4,5};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment