Skip to content

Commit

Permalink
Improves all and zip functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikbk committed May 29, 2019
1 parent ddd3424 commit 9c13afc
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions include/taco/util/collections.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ std::pair<std::vector<V>,std::vector<V>> split(const std::vector<V>& vector,
return {first, second};
}

template <typename V, typename T>
bool all(const std::vector<V>& vector, T test) {
for (auto& element : vector) {
template <typename C, typename T>
bool all(const C& collection, T test) {
for (const auto& element : collection) {
if (!test(element)) {
return false;
}
Expand Down Expand Up @@ -257,15 +257,10 @@ class ZipConstIterable {
public:
typedef typename C1::value_type value_type1;
typedef typename C2::value_type value_type2;
struct pair {
const value_type1 &first;
const value_type2 &second;
pair(const value_type1 &first, const value_type2 &second)
: first(first), second(second){}
friend std::ostream& operator<<(std::ostream &os, const pair &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
};
friend std::ostream& operator<<(std::ostream &os,
const std::pair<value_type1,value_type2> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
class ZipConstIterator {
public:
typedef typename C1::const_iterator const_iterator1;
Expand All @@ -292,8 +287,8 @@ class ZipConstIterable {
const ZipConstIterator &r) {
return l.c1it != r.c1it || l.c2it != r.c2it;
}
pair operator*() {
return pair(*c1it, *c2it);
std::pair<value_type1, value_type2> operator*() {
return std::pair<value_type1, value_type2>(*c1it, *c2it);
}

private:
Expand Down

0 comments on commit 9c13afc

Please sign in to comment.