Commit 3087b44d authored by Anton Bukov's avatar Anton Bukov

Merge pull request #19 from k06a/feature/some-refactorings

Refactor some export methods
parents 8e85b80f 0b0add10
...@@ -589,56 +589,49 @@ namespace boolinq ...@@ -589,56 +589,49 @@ namespace boolinq
// Export methods // Export methods
std::vector<T> toVector() const private:
{
std::vector<T> vec; template<typename C, typename TFunc>
C exportToContainer(TFunc func) const {
C container;
try try
{ {
auto en = _enumerator; auto en = _enumerator;
for (;;) for (;;)
vec.push_back(en.nextObject()); func(container, en.nextObject());
} }
catch(EnumeratorEndException &) {} catch(EnumeratorEndException &) {}
return vec; return container;
} }
std::set<T> toSet() const public:
{
std::set<T> res; std::vector<T> toVector() const
try
{ {
auto en = _enumerator; return exportToContainer<std::vector<T> >([](std::vector<T> &container, const T &value){
for (;;) container.push_back(value);
res.insert(en.nextObject()); });
}
catch(EnumeratorEndException &) {}
return res;
} }
std::list<T> toList() const std::list<T> toList() const
{ {
std::list<T> res; return exportToContainer<std::list<T> >([](std::list<T> &container, const T &value){
try container.push_back(value);
{ });
auto en = _enumerator;
for (;;)
res.push_back(en.nextObject());
}
catch(EnumeratorEndException &) {}
return res;
} }
std::deque<T> toDeque() const std::deque<T> toDeque() const
{ {
std::deque<T> res; return exportToContainer<std::deque<T> >([](std::deque<T> &container, const T &value){
try container.push_back(value);
{ });
auto en = _enumerator;
for (;;)
res.push_back(en.nextObject());
} }
catch(EnumeratorEndException &) {}
return res; std::set<T> toSet() const
{
return exportToContainer<std::set<T> >([](std::set<T> &container, const T &value){
container.insert(value);
});
} }
// 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