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
// Export methods
std::vector<T> toVector() const
{
std::vector<T> vec;
private:
template<typename C, typename TFunc>
C exportToContainer(TFunc func) const {
C container;
try
{
auto en = _enumerator;
for (;;)
vec.push_back(en.nextObject());
func(container, en.nextObject());
}
catch(EnumeratorEndException &) {}
return vec;
return container;
}
std::set<T> toSet() const
public:
std::vector<T> toVector() const
{
std::set<T> res;
try
{
auto en = _enumerator;
for (;;)
res.insert(en.nextObject());
}
catch(EnumeratorEndException &) {}
return res;
return exportToContainer<std::vector<T> >([](std::vector<T> &container, const T &value){
container.push_back(value);
});
}
std::list<T> toList() const
{
std::list<T> res;
try
{
auto en = _enumerator;
for (;;)
res.push_back(en.nextObject());
}
catch(EnumeratorEndException &) {}
return res;
return exportToContainer<std::list<T> >([](std::list<T> &container, const T &value){
container.push_back(value);
});
}
std::deque<T> toDeque() const
{
std::deque<T> res;
try
{
auto en = _enumerator;
for (;;)
res.push_back(en.nextObject());
}
catch(EnumeratorEndException &) {}
return res;
return exportToContainer<std::deque<T> >([](std::deque<T> &container, const T &value){
container.push_back(value);
});
}
std::set<T> toSet() const
{
return exportToContainer<std::set<T> >([](std::set<T> &container, const T &value){
container.insert(value);
});
}
// 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