From 9c13afc570edf6873a44315d5fe7fa3143276c56 Mon Sep 17 00:00:00 2001 From: Fredrik Kjolstad Date: Wed, 29 May 2019 10:52:56 -0400 Subject: [PATCH] Improves all and zip functions --- include/taco/util/collections.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/include/taco/util/collections.h b/include/taco/util/collections.h index 06ba53d34..97982d231 100644 --- a/include/taco/util/collections.h +++ b/include/taco/util/collections.h @@ -139,9 +139,9 @@ std::pair,std::vector> split(const std::vector& vector, return {first, second}; } -template -bool all(const std::vector& vector, T test) { - for (auto& element : vector) { +template +bool all(const C& collection, T test) { + for (const auto& element : collection) { if (!test(element)) { return false; } @@ -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 &p) { + return os << "(" << p.first << ", " << p.second << ")"; + } class ZipConstIterator { public: typedef typename C1::const_iterator const_iterator1; @@ -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 operator*() { + return std::pair(*c1it, *c2it); } private: