Commit 0b0add10 authored by Anton Bukov's avatar Anton Bukov

Unified all export methods

parent fb3397d4
...@@ -591,14 +591,14 @@ namespace boolinq ...@@ -591,14 +591,14 @@ namespace boolinq
private: private:
template<typename C> template<typename C, typename TFunc>
C pushBackToContainer() const { C exportToContainer(TFunc func) const {
C container; C container;
try try
{ {
auto en = _enumerator; auto en = _enumerator;
for (;;) for (;;)
container.push_back(en.nextObject()); func(container, en.nextObject());
} }
catch(EnumeratorEndException &) {} catch(EnumeratorEndException &) {}
return container; return container;
...@@ -608,30 +608,30 @@ namespace boolinq ...@@ -608,30 +608,30 @@ namespace boolinq
std::vector<T> toVector() const std::vector<T> toVector() const
{ {
return pushBackToContainer<std::vector<T> >(); return exportToContainer<std::vector<T> >([](std::vector<T> &container, const T &value){
container.push_back(value);
});
} }
std::list<T> toList() const std::list<T> toList() const
{ {
return pushBackToContainer<std::list<T> >(); return exportToContainer<std::list<T> >([](std::list<T> &container, const T &value){
container.push_back(value);
});
} }
std::deque<T> toDeque() const std::deque<T> toDeque() const
{ {
return pushBackToContainer<std::deque<T> >(); return exportToContainer<std::deque<T> >([](std::deque<T> &container, const T &value){
container.push_back(value);
});
} }
std::set<T> toSet() const std::set<T> toSet() const
{ {
std::set<T> res; return exportToContainer<std::set<T> >([](std::set<T> &container, const T &value){
try container.insert(value);
{ });
auto en = _enumerator;
for (;;)
res.insert(en.nextObject());
}
catch(EnumeratorEndException &) {}
return res;
} }
// Custom methods // Custom methods
......
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