Commit fb3397d4 authored by Anton Bukov's avatar Anton Bukov

Refactor some export methods

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