Commit fb3397d4 authored by Anton Bukov's avatar Anton Bukov

Refactor some export methods

parent 8e85b80f
...@@ -589,53 +589,46 @@ namespace boolinq ...@@ -589,53 +589,46 @@ namespace boolinq
// Export methods // Export methods
std::vector<T> toVector() const private:
{
std::vector<T> vec; template<typename C>
C pushBackToContainer() const {
C container;
try try
{ {
auto en = _enumerator; auto en = _enumerator;
for (;;) for (;;)
vec.push_back(en.nextObject()); container.push_back(en.nextObject());
} }
catch(EnumeratorEndException &) {} catch(EnumeratorEndException &) {}
return vec; return container;
} }
std::set<T> toSet() const public:
std::vector<T> toVector() const
{ {
std::set<T> res; return pushBackToContainer<std::vector<T> >();
try
{
auto en = _enumerator;
for (;;)
res.insert(en.nextObject());
}
catch(EnumeratorEndException &) {}
return res;
} }
std::list<T> toList() const std::list<T> toList() const
{ {
std::list<T> res; return pushBackToContainer<std::list<T> >();
try
{
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 pushBackToContainer<std::deque<T> >();
}
std::set<T> toSet() const
{
std::set<T> res;
try try
{ {
auto en = _enumerator; auto en = _enumerator;
for (;;) for (;;)
res.push_back(en.nextObject()); res.insert(en.nextObject());
} }
catch(EnumeratorEndException &) {} catch(EnumeratorEndException &) {}
return res; return res;
......
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