Remove more #include directives from util/util.h. This time, it was also necessary to remove using declarations, which meant adding "std::" to everything. I left std::string alone for now, but added a couple of TODOs for it. Change-Id: Idc45d6587be3ac3a2be1c9c941b4bad5b7a3fdb3 Reviewed-on: https://code-review.googlesource.com/5443 Reviewed-by: Paul Wankadia <[email protected]>
diff --git a/re2/compile.cc b/re2/compile.cc index f6774d8..5ac0a34 100644 --- a/re2/compile.cc +++ b/re2/compile.cc
@@ -243,7 +243,7 @@ int64 max_mem_; // Total memory budget. - map<uint64, int> rune_cache_; + std::map<uint64, int> rune_cache_; Frag rune_range_; RE2::Anchor anchor_; // anchor mode for RE2::Set @@ -491,7 +491,7 @@ int Compiler::CachedRuneByteSuffix(uint8 lo, uint8 hi, bool foldcase, int next) { uint64 key = MakeRuneCacheKey(lo, hi, foldcase, next); - map<uint64, int>::const_iterator it = rune_cache_.find(key); + std::map<uint64, int>::const_iterator it = rune_cache_.find(key); if (it != rune_cache_.end()) return it->second; int id = UncachedRuneByteSuffix(lo, hi, foldcase, next);
diff --git a/re2/dfa.cc b/re2/dfa.cc index 0293ca6..525c1d6 100644 --- a/re2/dfa.cc +++ b/re2/dfa.cc
@@ -31,6 +31,7 @@ #include <new> #include <string> #include <unordered_set> +#include <utility> #include <vector> #include "util/flags.h" @@ -85,7 +86,7 @@ // memory), it sets *failed and returns false. bool Search(const StringPiece& text, const StringPiece& context, bool anchored, bool want_earliest_match, bool run_forward, - bool* failed, const char** ep, vector<int>* matches); + bool* failed, const char** ep, std::vector<int>* matches); // Builds out all states for the entire DFA. FOR TESTING ONLY // Returns number of states. @@ -106,7 +107,7 @@ // byte c, the next state should be s->next_[c]. struct State { inline bool IsMatch() const { return (flag_ & kFlagMatch) != 0; } - void SaveMatch(vector<int>* v); + void SaveMatch(std::vector<int>* v); int* inst_; // Instruction pointers in the state. int ninst_; // # of inst_ pointers. @@ -156,7 +157,7 @@ } }; - typedef unordered_set<State*, StateHash, StateEqual> StateSet; + typedef std::unordered_set<State*, StateHash, StateEqual> StateSet; private: // Special "firstbyte" values for a state. (Values >= 0 denote actual bytes.) @@ -254,7 +255,7 @@ RWLocker *cache_lock; bool failed; // "out" parameter: whether search gave up const char* ep; // "out" parameter: end pointer for match - vector<int>* matches; + std::vector<int>* matches; private: DISALLOW_COPY_AND_ASSIGN(SearchParams); @@ -687,7 +688,7 @@ int* markp = ip; while (markp < ep && *markp != Mark) markp++; - sort(ip, markp); + std::sort(ip, markp); if (markp < ep) markp++; ip = markp; @@ -1022,6 +1023,7 @@ // Only useful to rerun on empty string if there are new, useful flags. if (beforeflag & ~oldbeforeflag & needflag) { RunWorkqOnEmptyString(q0_, q1_, beforeflag); + using std::swap; swap(q0_, q1_); } bool ismatch = false; @@ -1035,8 +1037,10 @@ // of the string, but we're at the end of the text so that's okay. // Leaving q0_ alone preseves the match instructions that led to // the current setting of ismatch. - if (c != kByteEndText || kind_ != Prog::kManyMatch) + if (c != kByteEndText || kind_ != Prog::kManyMatch) { + using std::swap; swap(q0_, q1_); + } // Save afterflag along with ismatch and isword in new state. uint flag = afterflag; @@ -1308,8 +1312,10 @@ const uint8* p = bp; // text scanning point const uint8* ep = BytePtr(params->text.end()); // end of text const uint8* resetp = NULL; // p at last cache reset - if (!run_forward) + if (!run_forward) { + using std::swap; swap(p, ep); + } const uint8* bytemap = prog_->bytemap(); const uint8* lastmatch = NULL; // most recent matching position in text @@ -1488,7 +1494,7 @@ matched = true; lastmatch = p; if (params->matches && kind_ == Prog::kManyMatch) { - vector<int>* v = params->matches; + std::vector<int>* v = params->matches; v->clear(); for (int i = 0; i < s->ninst_; i++) { Prog::Inst* ip = prog_->inst(s->inst_[i]); @@ -1731,7 +1737,7 @@ bool run_forward, bool* failed, const char** epp, - vector<int>* matches) { + std::vector<int>* matches) { *epp = NULL; if (!ok()) { *failed = true; @@ -1835,8 +1841,8 @@ // This is the only external interface (class DFA only exists in this file). // bool Prog::SearchDFA(const StringPiece& text, const StringPiece& const_context, - Anchor anchor, MatchKind kind, - StringPiece* match0, bool* failed, vector<int>* matches) { + Anchor anchor, MatchKind kind, StringPiece* match0, + bool* failed, std::vector<int>* matches) { *failed = false; StringPiece context = const_context; @@ -1913,7 +1919,7 @@ // Add start state to work queue. StateSet queued; - vector<State*> q; + std::vector<State*> q; queued.insert(params.start); q.push_back(params.start); @@ -1957,7 +1963,7 @@ // Also note that previously_visited_states[UnseenStatePtr] will, in the STL // tradition, implicitly insert a '0' value at first use. We take advantage // of that property below. - map<State*, int> previously_visited_states; + std::map<State*, int> previously_visited_states; // Pick out start state for anchored search at beginning of text. RWLocker l(&cache_mutex_);
diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc index 5dc471a..6bc4b46 100644 --- a/re2/filtered_re2.cc +++ b/re2/filtered_re2.cc
@@ -43,7 +43,7 @@ return code; } -void FilteredRE2::Compile(vector<string>* atoms) { +void FilteredRE2::Compile(std::vector<string>* atoms) { if (compiled_ || re2_vec_.size() == 0) { LOG(INFO) << "C: " << compiled_ << " S:" << re2_vec_.size(); return; @@ -66,12 +66,12 @@ } int FilteredRE2::FirstMatch(const StringPiece& text, - const vector<int>& atoms) const { + const std::vector<int>& atoms) const { if (!compiled_) { LOG(DFATAL) << "FirstMatch called before Compile"; return -1; } - vector<int> regexps; + std::vector<int> regexps; prefilter_tree_->RegexpsGivenStrings(atoms, ®exps); for (size_t i = 0; i < regexps.size(); i++) if (RE2::PartialMatch(text, *re2_vec_[regexps[i]])) @@ -81,10 +81,10 @@ bool FilteredRE2::AllMatches( const StringPiece& text, - const vector<int>& atoms, - vector<int>* matching_regexps) const { + const std::vector<int>& atoms, + std::vector<int>* matching_regexps) const { matching_regexps->clear(); - vector<int> regexps; + std::vector<int> regexps; prefilter_tree_->RegexpsGivenStrings(atoms, ®exps); for (size_t i = 0; i < regexps.size(); i++) if (RE2::PartialMatch(text, *re2_vec_[regexps[i]])) @@ -93,13 +93,13 @@ } void FilteredRE2::AllPotentials( - const vector<int>& atoms, - vector<int>* potential_regexps) const { + const std::vector<int>& atoms, + std::vector<int>* potential_regexps) const { prefilter_tree_->RegexpsGivenStrings(atoms, potential_regexps); } -void FilteredRE2::RegexpsGivenStrings(const vector<int>& matched_atoms, - vector<int>* passed_regexps) { +void FilteredRE2::RegexpsGivenStrings(const std::vector<int>& matched_atoms, + std::vector<int>* passed_regexps) { prefilter_tree_->RegexpsGivenStrings(matched_atoms, passed_regexps); }
diff --git a/re2/filtered_re2.h b/re2/filtered_re2.h index afcf8dd..be0020b 100644 --- a/re2/filtered_re2.h +++ b/re2/filtered_re2.h
@@ -27,7 +27,6 @@ #include "re2/re2.h" namespace re2 { -using std::vector; class PrefilterTree; @@ -49,7 +48,7 @@ // the search text should be lowercased first to find matching // strings from the set of strings returned by Compile. Call after // all Add calls are done. - void Compile(vector<string>* strings_to_match); + void Compile(std::vector<string>* strings_to_match); // Returns the index of the first matching regexp. // Returns -1 on no match. Can be called prior to Compile. @@ -61,21 +60,21 @@ // Returns -1 on no match. Compile has to be called before // calling this. int FirstMatch(const StringPiece& text, - const vector<int>& atoms) const; + const std::vector<int>& atoms) const; // Returns the indices of all matching regexps, after first clearing // matched_regexps. bool AllMatches(const StringPiece& text, - const vector<int>& atoms, - vector<int>* matching_regexps) const; + const std::vector<int>& atoms, + std::vector<int>* matching_regexps) const; // Returns the indices of all potentially matching regexps after first // clearing potential_regexps. // A regexp is potentially matching if it passes the filter. // If a regexp passes the filter it may still not match. // A regexp that does not pass the filter is guaranteed to not match. - void AllPotentials(const vector<int>& atoms, - vector<int>* potential_regexps) const; + void AllPotentials(const std::vector<int>& atoms, + std::vector<int>* potential_regexps) const; // The number of regexps added. int NumRegexps() const { return static_cast<int>(re2_vec_.size()); } @@ -89,11 +88,11 @@ void PrintPrefilter(int regexpid); // Useful for testing and debugging. - void RegexpsGivenStrings(const vector<int>& matched_atoms, - vector<int>* passed_regexps); + void RegexpsGivenStrings(const std::vector<int>& matched_atoms, + std::vector<int>* passed_regexps); // All the regexps in the FilteredRE2. - vector<RE2*> re2_vec_; + std::vector<RE2*> re2_vec_; // Has the FilteredRE2 been compiled using Compile() bool compiled_;
diff --git a/re2/fuzzing/re2_fuzzer.cc b/re2/fuzzing/re2_fuzzer.cc index df2afee..6fd8699 100644 --- a/re2/fuzzing/re2_fuzzer.cc +++ b/re2/fuzzing/re2_fuzzer.cc
@@ -12,7 +12,6 @@ using re2::FLAGS_minloglevel; using re2::StringPiece; -using std::map; using std::string; // NOT static, NOT signed. @@ -24,7 +23,7 @@ return; // Don't waste time fuzzing high-fanout programs. - map<int, int> histogram; + std::map<int, int> histogram; int fanout = re.ProgramFanout(&histogram); if (fanout > 10) return;
diff --git a/re2/nfa.cc b/re2/nfa.cc index bf0f330..1a7f927 100644 --- a/re2/nfa.cc +++ b/re2/nfa.cc
@@ -28,6 +28,7 @@ #include <string.h> #include <algorithm> #include <string> +#include <utility> #include <vector> #include "re2/prog.h" @@ -559,6 +560,7 @@ // This is a no-op the first time around the loop because runq is empty. int id = Step(runq, nextq, p < text.end() ? p[0] & 0xFF : -1, flag, p-1); DCHECK_EQ(runq->size(), 0); + using std::swap; swap(nextq, runq); nextq->clear(); if (id != 0) {
diff --git a/re2/onepass.cc b/re2/onepass.cc index bbef608..2584faf 100644 --- a/re2/onepass.cc +++ b/re2/onepass.cc
@@ -402,7 +402,7 @@ // Originally, nodes was a uint8[maxnodes*statesize], but that was // unnecessarily optimistic: why allocate a large amount of memory // upfront for a large program when it is unlikely to be one-pass? - vector<uint8> nodes; + std::vector<uint8> nodes; Instq tovisit(size), workq(size); AddQ(&tovisit, start()); @@ -483,8 +483,8 @@ } } if (ip->foldcase()) { - Rune lo = max<Rune>(ip->lo(), 'a') + 'A' - 'a'; - Rune hi = min<Rune>(ip->hi(), 'z') + 'A' - 'a'; + Rune lo = std::max<Rune>(ip->lo(), 'a') + 'A' - 'a'; + Rune hi = std::min<Rune>(ip->hi(), 'z') + 'A' - 'a'; for (int c = lo; c <= hi; c++) { int b = bytemap_[c]; // Skip any bytes immediately after c that are also in b. @@ -578,7 +578,7 @@ LOG(ERROR) << "bytemap:\n" << DumpByteMap(); LOG(ERROR) << "prog:\n" << Dump(); - map<int, int> idmap; + std::map<int, int> idmap; for (int i = 0; i < size; i++) if (nodebyid[i] != -1) idmap[nodebyid[i]] = i;
diff --git a/re2/parse.cc b/re2/parse.cc index 1fb3048..b8911e5 100644 --- a/re2/parse.cc +++ b/re2/parse.cc
@@ -353,7 +353,7 @@ // Add in the result of folding the range lo - f->hi // and that range's fold, recursively. Rune lo1 = lo; - Rune hi1 = min<Rune>(hi, f->hi); + Rune hi1 = std::min<Rune>(hi, f->hi); switch (f->delta) { default: lo1 += f->delta;
diff --git a/re2/prefilter.cc b/re2/prefilter.cc index 64792a0..19c2c50 100644 --- a/re2/prefilter.cc +++ b/re2/prefilter.cc
@@ -18,15 +18,15 @@ static const int Trace = false; -typedef set<string>::iterator SSIter; -typedef set<string>::const_iterator ConstSSIter; +typedef std::set<string>::iterator SSIter; +typedef std::set<string>::const_iterator ConstSSIter; // Initializes a Prefilter, allocating subs_ as necessary. Prefilter::Prefilter(Op op) { op_ = op; subs_ = NULL; if (op_ == AND || op_ == OR) - subs_ = new vector<Prefilter*>; + subs_ = new std::vector<Prefilter*>; VLOG(10) << "constructed: " << reinterpret_cast<intptr_t>(this); } @@ -140,7 +140,7 @@ return AndOr(OR, a, b); } -static void SimplifyStringSet(set<string> *ss) { +static void SimplifyStringSet(std::set<string> *ss) { // Now make sure that the strings aren't redundant. For example, if // we know "ab" is a required string, then it doesn't help at all to // know that "abc" is also a required string, so delete "abc". This @@ -161,7 +161,7 @@ } } -Prefilter* Prefilter::OrStrings(set<string>* ss) { +Prefilter* Prefilter::OrStrings(std::set<string>* ss) { SimplifyStringSet(ss); Prefilter* or_prefilter = NULL; if (!ss->empty()) { @@ -226,14 +226,14 @@ // Caller takes ownership of the Prefilter. Prefilter* TakeMatch(); - set<string>& exact() { return exact_; } + std::set<string>& exact() { return exact_; } bool is_exact() const { return is_exact_; } class Walker; private: - set<string> exact_; + std::set<string> exact_; // When is_exact_ is true, the strings that match // are placed in exact_. When it is no longer an exact @@ -272,7 +272,9 @@ if (is_exact_) { int n = 0; string s; - for (set<string>::iterator i = exact_.begin(); i != exact_.end(); ++i) { + for (std::set<string>::iterator i = exact_.begin(); + i != exact_.end(); + ++i) { if (n++ > 0) s += ","; s += *i; @@ -287,16 +289,17 @@ } // Add the strings from src to dst. -static void CopyIn(const set<string>& src, set<string>* dst) { +static void CopyIn(const std::set<string>& src, + std::set<string>* dst) { for (ConstSSIter i = src.begin(); i != src.end(); ++i) dst->insert(*i); } // Add the cross-product of a and b to dst. // (For each string i in a and j in b, add i+j.) -static void CrossProduct(const set<string>& a, - const set<string>& b, - set<string>* dst) { +static void CrossProduct(const std::set<string>& a, + const std::set<string>& b, + std::set<string>* dst) { for (ConstSSIter i = a.begin(); i != a.end(); ++i) for (ConstSSIter j = b.begin(); j != b.end(); ++j) dst->insert(*i + *j);
diff --git a/re2/prefilter.h b/re2/prefilter.h index aac06d4..91129ed 100644 --- a/re2/prefilter.h +++ b/re2/prefilter.h
@@ -41,14 +41,14 @@ int unique_id() const { return unique_id_; } // The children of the Prefilter node. - vector<Prefilter*>* subs() { + std::vector<Prefilter*>* subs() { CHECK(op_ == AND || op_ == OR); return subs_; } // Set the children vector. Prefilter takes ownership of subs and // subs_ will be deleted when Prefilter is deleted. - void set_subs(vector<Prefilter*>* subs) { subs_ = subs; } + void set_subs(std::vector<Prefilter*>* subs) { subs_ = subs; } // Given a RE2, return a Prefilter. The caller takes ownership of // the Prefilter and should deallocate it. Returns NULL if Prefilter @@ -76,7 +76,7 @@ static Prefilter* FromString(const string& str); - static Prefilter* OrStrings(set<string>* ss); + static Prefilter* OrStrings(std::set<string>* ss); static Info* BuildInfo(Regexp* re); @@ -86,7 +86,7 @@ Op op_; // Sub-matches for AND or OR Prefilter. - vector<Prefilter*>* subs_; + std::vector<Prefilter*>* subs_; // Actual string to match in leaf node. string atom_;
diff --git a/re2/prefilter_tree.cc b/re2/prefilter_tree.cc index c20ef51..ec4e755 100644 --- a/re2/prefilter_tree.cc +++ b/re2/prefilter_tree.cc
@@ -58,7 +58,7 @@ case Prefilter::AND: { int j = 0; - vector<Prefilter*>* subs = prefilter->subs(); + std::vector<Prefilter*>* subs = prefilter->subs(); for (size_t i = 0; i < subs->size(); i++) if (KeepPart((*subs)[i], level + 1)) (*subs)[j++] = (*subs)[i]; @@ -90,7 +90,7 @@ prefilter_vec_.push_back(f); } -void PrefilterTree::Compile(vector<string>* atom_vec) { +void PrefilterTree::Compile(std::vector<string>* atom_vec) { if (compiled_) { LOG(DFATAL) << "Compile after Compile."; return; @@ -141,7 +141,7 @@ Prefilter* PrefilterTree::CanonicalNode(Prefilter* node) { string node_string = NodeString(node); - map<string, Prefilter*>::iterator iter = node_map_.find(node_string); + std::map<string, Prefilter*>::iterator iter = node_map_.find(node_string); if (iter == node_map_.end()) return NULL; return (*iter).second; @@ -168,12 +168,12 @@ return s; } -void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) { +void PrefilterTree::AssignUniqueIds(std::vector<string>* atom_vec) { atom_vec->clear(); // Build vector of all filter nodes, sorted topologically // from top to bottom in v. - vector<Prefilter*> v; + std::vector<Prefilter*> v; // Add the top level nodes of each regexp prefilter. for (size_t i = 0; i < prefilter_vec_.size(); i++) { @@ -192,7 +192,7 @@ if (f == NULL) continue; if (f->op() == Prefilter::AND || f->op() == Prefilter::OR) { - const vector<Prefilter*>& subs = *f->subs(); + const std::vector<Prefilter*>& subs = *f->subs(); for (size_t j = 0; j < subs.size(); j++) v.push_back(subs[j]); } @@ -257,7 +257,7 @@ case Prefilter::OR: case Prefilter::AND: { - set<int> uniq_child; + std::set<int> uniq_child; for (size_t j = 0; j < prefilter->subs()->size(); j++) { Prefilter* child = (*prefilter->subs())[j]; Prefilter* canonical = CanonicalNode(child); @@ -296,8 +296,8 @@ // Functions for triggering during search. void PrefilterTree::RegexpsGivenStrings( - const vector<int>& matched_atoms, - vector<int>* regexps) const { + const std::vector<int>& matched_atoms, + std::vector<int>* regexps) const { regexps->clear(); if (!compiled_) { LOG(WARNING) << "Compile() not called"; @@ -306,7 +306,7 @@ } else { if (!prefilter_vec_.empty()) { IntMap regexps_map(static_cast<int>(prefilter_vec_.size())); - vector<int> matched_atom_ids; + std::vector<int> matched_atom_ids; for (size_t j = 0; j < matched_atoms.size(); j++) { matched_atom_ids.push_back(atom_index_to_id_[matched_atoms[j]]); VLOG(10) << "Atom id:" << atom_index_to_id_[matched_atoms[j]]; @@ -320,10 +320,10 @@ regexps->insert(regexps->end(), unfiltered_.begin(), unfiltered_.end()); } } - sort(regexps->begin(), regexps->end()); + std::sort(regexps->begin(), regexps->end()); } -void PrefilterTree::PropagateMatch(const vector<int>& atom_ids, +void PrefilterTree::PropagateMatch(const std::vector<int>& atom_ids, IntMap* regexps) const { IntMap count(static_cast<int>(entries_.size())); IntMap work(static_cast<int>(entries_.size())); @@ -375,14 +375,14 @@ for (size_t i = 0; i < entries_.size(); ++i) { StdIntMap* parents = entries_[i].parents; - const vector<int>& regexps = entries_[i].regexps; + const std::vector<int>& regexps = entries_[i].regexps; VLOG(10) << "EntryId: " << i << " N: " << parents->size() << " R: " << regexps.size(); for (StdIntMap::iterator it = parents->begin(); it != parents->end(); ++it) VLOG(10) << it->first; } VLOG(10) << "Map:"; - for (map<string, Prefilter*>::const_iterator iter = node_map_.begin(); + for (std::map<string, Prefilter*>::const_iterator iter = node_map_.begin(); iter != node_map_.end(); ++iter) VLOG(10) << "NodeId: " << (*iter).second->unique_id() << " Str: " << (*iter).first;
diff --git a/re2/prefilter_tree.h b/re2/prefilter_tree.h index 667ff99..f5f50f0 100644 --- a/re2/prefilter_tree.h +++ b/re2/prefilter_tree.h
@@ -26,7 +26,7 @@ namespace re2 { typedef SparseArray<int> IntMap; -typedef map<int, int> StdIntMap; +typedef std::map<int, int> StdIntMap; class Prefilter; @@ -46,15 +46,15 @@ // The caller should use the returned set of strings to do string matching. // Each time a string matches, the corresponding index then has to be // and passed to RegexpsGivenStrings below. - void Compile(vector<string>* atom_vec); + void Compile(std::vector<string>* atom_vec); // Given the indices of the atoms that matched, returns the indexes // of regexps that should be searched. The matched_atoms should // contain all the ids of string atoms that were found to match the // content. The caller can use any string match engine to perform // this function. This function is thread safe. - void RegexpsGivenStrings(const vector<int>& matched_atoms, - vector<int>* regexps) const; + void RegexpsGivenStrings(const std::vector<int>& matched_atoms, + std::vector<int>* regexps) const; // Print debug prefilter. Also prints unique ids associated with // nodes of the prefilter of the regexp. @@ -80,17 +80,17 @@ // When this node is ready to trigger the parent, what are the // regexps that are triggered. - vector<int> regexps; + std::vector<int> regexps; }; private: // This function assigns unique ids to various parts of the // prefilter, by looking at if these nodes are already in the // PrefilterTree. - void AssignUniqueIds(vector<string>* atom_vec); + void AssignUniqueIds(std::vector<string>* atom_vec); // Given the matching atoms, find the regexps to be triggered. - void PropagateMatch(const vector<int>& atom_ids, + void PropagateMatch(const std::vector<int>& atom_ids, IntMap* regexps) const; // Returns the prefilter node that has the same NodeString as this @@ -109,20 +109,20 @@ // These are all the nodes formed by Compile. Essentially, there is // one node for each unique atom and each unique AND/OR node. - vector<Entry> entries_; + std::vector<Entry> entries_; // Map node string to canonical Prefilter node. - map<string, Prefilter*> node_map_; + std::map<string, Prefilter*> node_map_; // indices of regexps that always pass through the filter (since we // found no required literals in these regexps). - vector<int> unfiltered_; + std::vector<int> unfiltered_; // vector of Prefilter for all regexps. - vector<Prefilter*> prefilter_vec_; + std::vector<Prefilter*> prefilter_vec_; // Atom index in returned strings to entry id mapping. - vector<int> atom_index_to_id_; + std::vector<int> atom_index_to_id_; // Has the prefilter tree been compiled. bool compiled_;
diff --git a/re2/prog.cc b/re2/prog.cc index 72a42e4..6710a20 100644 --- a/re2/prog.cc +++ b/re2/prog.cc
@@ -355,10 +355,10 @@ int Recolor(int oldcolor); Bitmap256 splits_; - vector<int> colors_; + std::vector<int> colors_; int nextcolor_; - vector<pair<int, int>> colormap_; - vector<pair<int, int>> ranges_; + std::vector<std::pair<int, int>> colormap_; + std::vector<std::pair<int, int>> ranges_; DISALLOW_COPY_AND_ASSIGN(ByteMapBuilder); }; @@ -379,7 +379,7 @@ } void ByteMapBuilder::Merge() { - for (vector<pair<int, int>>::const_iterator it = ranges_.begin(); + for (std::vector<std::pair<int, int>>::const_iterator it = ranges_.begin(); it != ranges_.end(); ++it) { int lo = it->first-1; @@ -431,9 +431,9 @@ // colors and there will typically be far fewer than that. // Also, we need to consider keys *and* values in order to // avoid recoloring a given range more than once per batch. - vector<pair<int, int>>::const_iterator it = + std::vector<std::pair<int, int>>::const_iterator it = std::find_if(colormap_.begin(), colormap_.end(), - [&](const pair<int, int>& kv) -> bool { + [&](const std::pair<int, int>& kv) -> bool { return kv.first == oldcolor || kv.second == oldcolor; }); if (it != colormap_.end()) @@ -525,7 +525,7 @@ // Scratch structures. It's important that these are reused by EmitList() // because we call it in a loop and it would thrash the heap otherwise. SparseSet q(size()); - vector<int> stk; + std::vector<int> stk; stk.reserve(size()); // First pass: Marks "roots". @@ -535,8 +535,8 @@ // Second pass: Emits "lists". Remaps outs to root-ids. // Builds the mapping from root-ids to flat-ids. - vector<int> flatmap(rootmap.size()); - vector<Inst> flat; + std::vector<int> flatmap(rootmap.size()); + std::vector<Inst> flat; flat.reserve(size()); for (SparseArray<int>::const_iterator i = rootmap.begin(); i != rootmap.end(); @@ -582,8 +582,8 @@ memmove(inst_, flat.data(), size_ * sizeof *inst_); } -void Prog::MarkRoots(SparseArray<int>* rootmap, - SparseSet* q, vector<int>* stk) { +void Prog::MarkRoots(SparseArray<int>* rootmap, SparseSet* q, + std::vector<int>* stk) { // Mark the kInstFail instruction. rootmap->set_new(0, rootmap->size()); @@ -636,8 +636,9 @@ } } -void Prog::EmitList(int root, SparseArray<int>* rootmap, vector<Inst>* flat, - SparseSet* q, vector<int>* stk) { +void Prog::EmitList(int root, SparseArray<int>* rootmap, + std::vector<Inst>* flat, SparseSet* q, + std::vector<int>* stk) { q->clear(); stk->clear(); stk->push_back(root);
diff --git a/re2/prog.h b/re2/prog.h index a017cec..b18e4ee 100644 --- a/re2/prog.h +++ b/re2/prog.h
@@ -252,9 +252,8 @@ // If matches != NULL and kind == kManyMatch and there is a match, // SearchDFA fills matches with the match IDs of the final matching state. bool SearchDFA(const StringPiece& text, const StringPiece& context, - Anchor anchor, MatchKind kind, - StringPiece* match0, bool* failed, - vector<int>* matches); + Anchor anchor, MatchKind kind, StringPiece* match0, + bool* failed, std::vector<int>* matches); // Build the entire DFA for the given match kind. FOR TESTING ONLY. // Usually the DFA is built out incrementally, as needed, which @@ -330,13 +329,14 @@ // Marks the "roots" in the Prog: the outs of kInstByteRange, kInstCapture // and kInstEmptyWidth instructions. - void MarkRoots(SparseArray<int>* rootmap, - SparseSet* q, vector<int>* stk); + void MarkRoots(SparseArray<int>* rootmap, SparseSet* q, + std::vector<int>* stk); // Emits one "list" via "tree" traversal from the given "root" instruction. // The new instructions are appended to the given vector. - void EmitList(int root, SparseArray<int>* rootmap, vector<Inst>* flat, - SparseSet* q, vector<int>* stk); + void EmitList(int root, SparseArray<int>* rootmap, + std::vector<Inst>* flat, SparseSet* q, + std::vector<int>* stk); private: friend class Compiler;
diff --git a/re2/re2.cc b/re2/re2.cc index 4f20711..5dbbd8a 100644 --- a/re2/re2.cc +++ b/re2/re2.cc
@@ -58,8 +58,8 @@ // static empty objects for use as const references. // To avoid global constructors, allocated in RE2::Init(). static const string* empty_string; -static const map<string, int>* empty_named_groups; -static const map<int, string>* empty_group_names; +static const std::map<string, int>* empty_named_groups; +static const std::map<int, string>* empty_group_names; // Converts from Regexp error code to RE2 error code. // Maybe some day they will diverge. In any event, this @@ -169,8 +169,8 @@ static std::once_flag empty_once; std::call_once(empty_once, []() { empty_string = new string; - empty_named_groups = new map<string, int>; - empty_group_names = new map<int, string>; + empty_named_groups = new std::map<string, int>; + empty_group_names = new std::map<int, string>; }); pattern_ = pattern.as_string(); @@ -264,7 +264,7 @@ return prog_->size(); } -int RE2::ProgramFanout(map<int, int>* histogram) const { +int RE2::ProgramFanout(std::map<int, int>* histogram) const { if (prog_ == NULL) return -1; SparseArray<int> fanout(prog_->size()); @@ -292,7 +292,7 @@ } // Returns named_groups_, computing it if needed. -const map<string, int>& RE2::NamedCapturingGroups() const { +const std::map<string, int>& RE2::NamedCapturingGroups() const { std::call_once(named_groups_once_, [this]() { if (suffix_regexp_ != NULL) named_groups_ = suffix_regexp_->NamedCaptures(); @@ -303,7 +303,7 @@ } // Returns group_names_, computing it if needed. -const map<int, string>& RE2::CapturingGroupNames() const { +const std::map<int, string>& RE2::CapturingGroupNames() const { std::call_once(group_names_once_, [this]() { if (suffix_regexp_ != NULL) group_names_ = suffix_regexp_->CaptureNames(); @@ -423,6 +423,7 @@ if (p < ep) out.append(p, ep - p); + using std::swap; swap(out, *str); return count; }
diff --git a/re2/re2.h b/re2/re2.h index ccad381..a1523f7 100644 --- a/re2/re2.h +++ b/re2/re2.h
@@ -190,11 +190,14 @@ #include "re2/stringpiece.h" namespace re2 { - -using std::string; -using std::map; class Prog; class Regexp; +} // namespace re2 + +namespace re2 { + +// TODO(junyer): Get rid of this. +using std::string; // Interface for regular expression matching. Also corresponds to a // pre-compiled regular expression. An "RE2" object is safe for @@ -280,7 +283,7 @@ // EXPERIMENTAL! SUBJECT TO CHANGE! // Outputs the program fanout as a histogram bucketed by powers of 2. // Returns the number of the largest non-empty bucket. - int ProgramFanout(map<int, int>* histogram) const; + int ProgramFanout(std::map<int, int>* histogram) const; // Returns the underlying Regexp; not for general use. // Returns entire_regexp_ so that callers don't need @@ -468,12 +471,12 @@ // The map records the index of the leftmost group // with the given name. // Only valid until the re is deleted. - const map<string, int>& NamedCapturingGroups() const; + const std::map<string, int>& NamedCapturingGroups() const; // Return a map from capturing indices to names. // The map has no entries for unnamed groups. // Only valid until the re is deleted. - const map<int, string>& CapturingGroupNames() const; + const std::map<int, string>& CapturingGroupNames() const; // General matching routine. // Match against text starting at offset startpos @@ -735,10 +738,10 @@ mutable int num_captures_; // Number of capturing groups // Map from capture names to indices - mutable const map<string, int>* named_groups_; + mutable const std::map<string, int>* named_groups_; // Map from capture indices to names - mutable const map<int, string>* group_names_; + mutable const std::map<int, string>* group_names_; // Onces for lazy computations. mutable std::once_flag rprog_once_;
diff --git a/re2/regexp.cc b/re2/regexp.cc index df701cc..93f5094 100644 --- a/re2/regexp.cc +++ b/re2/regexp.cc
@@ -71,7 +71,7 @@ // Lazily allocated. static Mutex* ref_mutex; -static map<Regexp*, int>* ref_map; +static std::map<Regexp*, int>* ref_map; int Regexp::Ref() { if (ref_ < kMaxRef) @@ -87,7 +87,7 @@ static std::once_flag ref_once; std::call_once(ref_once, []() { ref_mutex = new Mutex; - ref_map = new map<Regexp*, int>; + ref_map = new std::map<Regexp*, int>; }); // Store ref count in overflow map. @@ -419,7 +419,7 @@ // The stack (vector) has pairs of regexps waiting to // be compared. The regexps are only equal if // all the pairs end up being equal. - vector<Regexp*> stk; + std::vector<Regexp*> stk; for (;;) { // Invariant: TopEqual(a, b) == true. @@ -547,8 +547,8 @@ NamedCapturesWalker() : map_(NULL) {} ~NamedCapturesWalker() { delete map_; } - map<string, int>* TakeMap() { - map<string, int>* m = map_; + std::map<string, int>* TakeMap() { + std::map<string, int>* m = map_; map_ = NULL; return m; } @@ -557,7 +557,7 @@ if (re->op() == kRegexpCapture && re->name() != NULL) { // Allocate map once we find a name. if (map_ == NULL) - map_ = new map<string, int>; + map_ = new std::map<string, int>; // Record first occurrence of each name. // (The rule is that if you have the same name @@ -575,11 +575,11 @@ } private: - map<string, int>* map_; + std::map<string, int>* map_; DISALLOW_COPY_AND_ASSIGN(NamedCapturesWalker); }; -map<string, int>* Regexp::NamedCaptures() { +std::map<string, int>* Regexp::NamedCaptures() { NamedCapturesWalker w; w.Walk(this, 0); return w.TakeMap(); @@ -591,8 +591,8 @@ CaptureNamesWalker() : map_(NULL) {} ~CaptureNamesWalker() { delete map_; } - map<int, string>* TakeMap() { - map<int, string>* m = map_; + std::map<int, string>* TakeMap() { + std::map<int, string>* m = map_; map_ = NULL; return m; } @@ -601,7 +601,7 @@ if (re->op() == kRegexpCapture && re->name() != NULL) { // Allocate map once we find a name. if (map_ == NULL) - map_ = new map<int, string>; + map_ = new std::map<int, string>; (*map_)[re->cap()] = *re->name(); } @@ -615,11 +615,11 @@ } private: - map<int, string>* map_; + std::map<int, string>* map_; DISALLOW_COPY_AND_ASSIGN(CaptureNamesWalker); }; -map<int, string>* Regexp::CaptureNames() { +std::map<int, string>* Regexp::CaptureNames() { CaptureNamesWalker w; w.Walk(this, 0); return w.TakeMap(); @@ -719,13 +719,13 @@ if (lo <= 'z' && hi >= 'A') { // Overlaps some alpha, maybe not all. // Update bitmaps telling which ASCII letters are in the set. - Rune lo1 = max<Rune>(lo, 'A'); - Rune hi1 = min<Rune>(hi, 'Z'); + Rune lo1 = std::max<Rune>(lo, 'A'); + Rune hi1 = std::min<Rune>(hi, 'Z'); if (lo1 <= hi1) upper_ |= ((1 << (hi1 - lo1 + 1)) - 1) << (lo1 - 'A'); - lo1 = max<Rune>(lo, 'a'); - hi1 = min<Rune>(hi, 'z'); + lo1 = std::max<Rune>(lo, 'a'); + hi1 = std::min<Rune>(hi, 'z'); if (lo1 <= hi1) lower_ |= ((1 << (hi1 - lo1 + 1)) - 1) << (lo1 - 'a'); } @@ -841,7 +841,7 @@ void CharClassBuilder::Negate() { // Build up negation and then copy in. // Could edit ranges in place, but C++ won't let me. - vector<RuneRange> v; + std::vector<RuneRange> v; v.reserve(ranges_.size() + 1); // In negation, first range begins at 0, unless
diff --git a/re2/regexp.h b/re2/regexp.h index abcf439..733b508 100644 --- a/re2/regexp.h +++ b/re2/regexp.h
@@ -371,12 +371,12 @@ // Returns a map from names to capturing group indices, // or NULL if the regexp contains no named capture groups. // The caller is responsible for deleting the map. - map<string, int>* NamedCaptures(); + std::map<string, int>* NamedCaptures(); // Returns a map from capturing group indices to capturing group // names or NULL if the regexp contains no named capture groups. The // caller is responsible for deleting the map. - map<int, string>* CaptureNames(); + std::map<int, string>* CaptureNames(); // Returns a string representation of the current regexp, // using as few parentheses as possible. @@ -575,7 +575,7 @@ }; // Character class set: contains non-overlapping, non-abutting RuneRanges. -typedef set<RuneRange, RuneRangeLess> RuneRangeSet; +typedef std::set<RuneRange, RuneRangeLess> RuneRangeSet; class CharClassBuilder { public:
diff --git a/re2/set.cc b/re2/set.cc index aa84946..c456ee5 100644 --- a/re2/set.cc +++ b/re2/set.cc
@@ -93,7 +93,7 @@ return prog_ != NULL; } -bool RE2::Set::Match(const StringPiece& text, vector<int>* v) const { +bool RE2::Set::Match(const StringPiece& text, std::vector<int>* v) const { if (!compiled_) { LOG(DFATAL) << "RE2::Set::Match without Compile"; return false;
diff --git a/re2/set.h b/re2/set.h index 66366b2..ed6fccd 100644 --- a/re2/set.h +++ b/re2/set.h
@@ -16,7 +16,6 @@ } // namespace re2 namespace re2 { -using std::vector; // An RE2::Set represents a collection of regexps that can // be searched for simultaneously. @@ -42,12 +41,12 @@ // Match returns true if text matches any of the regexps in the set. // If so, it fills v (if not NULL) with the indices of the matching regexps. - bool Match(const StringPiece& text, vector<int>* v) const; + bool Match(const StringPiece& text, std::vector<int>* v) const; private: RE2::Options options_; RE2::Anchor anchor_; - vector<re2::Regexp*> re_; + std::vector<re2::Regexp*> re_; re2::Prog* prog_; bool compiled_; //DISALLOW_COPY_AND_ASSIGN(Set);
diff --git a/re2/stringpiece.cc b/re2/stringpiece.cc index 00f478a..57e4999 100644 --- a/re2/stringpiece.cc +++ b/re2/stringpiece.cc
@@ -39,7 +39,7 @@ StringPiece::size_type StringPiece::copy(char* buf, size_type n, size_type pos) const { - size_type ret = min(length_ - pos, n); + size_type ret = std::min(length_ - pos, n); memcpy(buf, ptr_ + pos, ret); return ret; } @@ -71,16 +71,17 @@ size_type pos) const { if (length_ < s.length_) return npos; const size_type ulen = length_; - if (s.length_ == 0) return min(ulen, pos); + if (s.length_ == 0) return std::min(ulen, pos); - const char* last = ptr_ + min(ulen - s.length_, pos) + s.length_; + const char* last = ptr_ + std::min(ulen - s.length_, pos) + s.length_; const char* result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_); return result != last ? result - ptr_ : npos; } StringPiece::size_type StringPiece::rfind(char c, size_type pos) const { if (length_ <= 0) return npos; - for (int i = static_cast<int>(min(pos, static_cast<size_type>(length_ - 1))); + for (int i = + static_cast<int>(std::min(pos, static_cast<size_type>(length_ - 1))); i >= 0; --i) { if (ptr_[i] == c) { return i;
diff --git a/re2/testing/dfa_test.cc b/re2/testing/dfa_test.cc index 18f5dbf..7067390 100644 --- a/re2/testing/dfa_test.cc +++ b/re2/testing/dfa_test.cc
@@ -67,7 +67,7 @@ Prog* prog = re->CompileToProg(0); CHECK(prog); - vector<BuildThread*> threads; + std::vector<BuildThread*> threads; for (int j = 0; j < FLAGS_threads; j++) { BuildThread *t = new BuildThread(prog); t->SetJoinable(true); @@ -142,7 +142,7 @@ CHECK_LT(n, static_cast<int>(8*sizeof(int))); CHECK_GT(n, 0); - vector<bool> did(1<<n); + std::vector<bool> did(1<<n); for (int i = 0; i < 1<<n; i++) did[i] = false; @@ -296,7 +296,7 @@ Prog* prog = re->CompileToProg(1<<n); CHECK(prog); - vector<SearchThread*> threads; + std::vector<SearchThread*> threads; for (int j = 0; j < FLAGS_threads; j++) { SearchThread *t = new SearchThread(prog, match, no_match); t->SetJoinable(true);
diff --git a/re2/testing/exhaustive1_test.cc b/re2/testing/exhaustive1_test.cc index 7c132c5..865d9b3 100644 --- a/re2/testing/exhaustive1_test.cc +++ b/re2/testing/exhaustive1_test.cc
@@ -16,7 +16,7 @@ // Test simple repetition operators TEST(Repetition, Simple) { - vector<string> ops = Split(" ", + std::vector<string> ops = Split(" ", "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} " "%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} " "%s* %s+ %s? %s*? %s+? %s??"); @@ -28,7 +28,7 @@ // Test capturing parens -- (a) -- inside repetition operators TEST(Repetition, Capturing) { - vector<string> ops = Split(" ", + std::vector<string> ops = Split(" ", "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} " "%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} " "%s* %s+ %s? %s*? %s+? %s??");
diff --git a/re2/testing/exhaustive2_test.cc b/re2/testing/exhaustive2_test.cc index b76a83f..ba38a6e 100644 --- a/re2/testing/exhaustive2_test.cc +++ b/re2/testing/exhaustive2_test.cc
@@ -24,8 +24,8 @@ // Test escaped versions of regexp syntax. TEST(Punctuation, Literals) { - vector<string> alphabet = Explode("()*+?{}[]\\^$."); - vector<string> escaped = alphabet; + std::vector<string> alphabet = Explode("()*+?{}[]\\^$."); + std::vector<string> escaped = alphabet; for (size_t i = 0; i < escaped.size(); i++) escaped[i] = "\\" + escaped[i]; ExhaustiveTest(1, 1, escaped, RegexpGenerator::EgrepOps(), @@ -63,7 +63,7 @@ // provides a mechanism, and RE2 could add new syntax if needed. // // TEST(Newlines, Exhaustive) { -// vector<string> empty_vector; +// std::vector<string> empty_vector; // ExhaustiveTest(1, 1, Split(" ", "\\n . a [^a]"), // RegexpGenerator::EgrepOps(), // 4, Explode("a\n"), "");
diff --git a/re2/testing/exhaustive3_test.cc b/re2/testing/exhaustive3_test.cc index 4f28bea..8e5b836 100644 --- a/re2/testing/exhaustive3_test.cc +++ b/re2/testing/exhaustive3_test.cc
@@ -16,7 +16,7 @@ // Test simple character classes by themselves. TEST(CharacterClasses, Exhaustive) { - vector<string> atoms = Split(" ", + std::vector<string> atoms = Split(" ", "[a] [b] [ab] [^bc] [b-d] [^b-d] []a] [-a] [a-] [^-a] [a-b-c] a b ."); ExhaustiveTest(2, 1, atoms, RegexpGenerator::EgrepOps(), 5, Explode("ab"), "", ""); @@ -24,7 +24,7 @@ // Test simple character classes inside a___b (for example, a[a]b). TEST(CharacterClasses, ExhaustiveAB) { - vector<string> atoms = Split(" ", + std::vector<string> atoms = Split(" ", "[a] [b] [ab] [^bc] [b-d] [^b-d] []a] [-a] [a-] [^-a] [a-b-c] a b ."); ExhaustiveTest(2, 1, atoms, RegexpGenerator::EgrepOps(), 5, Explode("ab"), "a%sb", ""); @@ -40,9 +40,9 @@ // Returns a vector of "interesting" UTF8 characters. // Unicode is now too big to just return all of them, // so UTF8Characters return a set likely to be good test cases. -static const vector<string>& InterestingUTF8() { +static const std::vector<string>& InterestingUTF8() { static bool init; - static vector<string> v; + static std::vector<string> v; if (init) return v; @@ -69,12 +69,12 @@ // Test interesting UTF-8 characters against character classes. TEST(InterestingUTF8, SingleOps) { - vector<string> atoms = Split(" ", + std::vector<string> atoms = Split(" ", ". ^ $ \\a \\f \\n \\r \\t \\v \\d \\D \\s \\S \\w \\W \\b \\B " "[[:alnum:]] [[:alpha:]] [[:blank:]] [[:cntrl:]] [[:digit:]] " "[[:graph:]] [[:lower:]] [[:print:]] [[:punct:]] [[:space:]] " "[[:upper:]] [[:xdigit:]] [\\s\\S] [\\d\\D] [^\\w\\W] [^\\d\\D]"); - vector<string> ops; // no ops + std::vector<string> ops; // no ops ExhaustiveTest(1, 0, atoms, ops, 1, InterestingUTF8(), "", ""); } @@ -82,13 +82,13 @@ // Test interesting UTF-8 characters against character classes, // but wrap everything inside AB. TEST(InterestingUTF8, AB) { - vector<string> atoms = Split(" ", + std::vector<string> atoms = Split(" ", ". ^ $ \\a \\f \\n \\r \\t \\v \\d \\D \\s \\S \\w \\W \\b \\B " "[[:alnum:]] [[:alpha:]] [[:blank:]] [[:cntrl:]] [[:digit:]] " "[[:graph:]] [[:lower:]] [[:print:]] [[:punct:]] [[:space:]] " "[[:upper:]] [[:xdigit:]] [\\s\\S] [\\d\\D] [^\\w\\W] [^\\d\\D]"); - vector<string> ops; // no ops - vector<string> alpha = InterestingUTF8(); + std::vector<string> ops; // no ops + std::vector<string> alpha = InterestingUTF8(); for (size_t i = 0; i < alpha.size(); i++) alpha[i] = "a" + alpha[i] + "b"; ExhaustiveTest(1, 0, atoms, ops,
diff --git a/re2/testing/exhaustive_tester.cc b/re2/testing/exhaustive_tester.cc index d63ed18..262b57b 100644 --- a/re2/testing/exhaustive_tester.cc +++ b/re2/testing/exhaustive_tester.cc
@@ -143,9 +143,10 @@ // Runs an exhaustive test on the given parameters. void ExhaustiveTest(int maxatoms, int maxops, - const vector<string>& alphabet, - const vector<string>& ops, - int maxstrlen, const vector<string>& stralphabet, + const std::vector<string>& alphabet, + const std::vector<string>& ops, + int maxstrlen, + const std::vector<string>& stralphabet, const string& wrapper, const string& topwrapper) { if (RE2_DEBUG_MODE && FLAGS_quick_debug_mode) {
diff --git a/re2/testing/exhaustive_tester.h b/re2/testing/exhaustive_tester.h index 4d31497..bbbe7e1 100644 --- a/re2/testing/exhaustive_tester.h +++ b/re2/testing/exhaustive_tester.h
@@ -36,10 +36,10 @@ public: ExhaustiveTester(int maxatoms, int maxops, - const vector<string>& alphabet, - const vector<string>& ops, + const std::vector<string>& alphabet, + const std::vector<string>& ops, int maxstrlen, - const vector<string>& stralphabet, + const std::vector<string>& stralphabet, const string& wrapper, const string& topwrapper) : RegexpGenerator(maxatoms, maxops, alphabet, ops), @@ -79,9 +79,10 @@ // Runs an exhaustive test on the given parameters. void ExhaustiveTest(int maxatoms, int maxops, - const vector<string>& alphabet, - const vector<string>& ops, - int maxstrlen, const vector<string>& stralphabet, + const std::vector<string>& alphabet, + const std::vector<string>& ops, + int maxstrlen, + const std::vector<string>& stralphabet, const string& wrapper, const string& topwrapper);
diff --git a/re2/testing/filtered_re2_test.cc b/re2/testing/filtered_re2_test.cc index 9759637..4e09456 100644 --- a/re2/testing/filtered_re2_test.cc +++ b/re2/testing/filtered_re2_test.cc
@@ -17,9 +17,9 @@ namespace re2 { struct FilterTestVars { - vector<string> atoms; - vector<int> atom_indices; - vector<int> matches; + std::vector<string> atoms; + std::vector<int> atom_indices; + std::vector<int> matches; RE2::Options opts; FilteredRE2 f; }; @@ -150,14 +150,14 @@ int n, const char* testname, struct FilterTestVars* v) { - vector<string> expected; + std::vector<string> expected; for (int i = 0; i < n; i++) expected.push_back(atoms[i]); bool pass = expected.size() == v->atoms.size(); - sort(v->atoms.begin(), v->atoms.end()); - sort(expected.begin(), expected.end()); + std::sort(v->atoms.begin(), v->atoms.end()); + std::sort(expected.begin(), expected.end()); for (int i = 0; pass && i < n; i++) pass = pass && expected[i] == v->atoms[i]; @@ -195,9 +195,9 @@ EXPECT_EQ(0, nfail); } -void FindAtomIndices(const vector<string>& atoms, - const vector<string>& matched_atoms, - vector<int>* atom_indices) { +void FindAtomIndices(const std::vector<string>& atoms, + const std::vector<string>& matched_atoms, + std::vector<int>* atom_indices) { atom_indices->clear(); for (size_t i = 0; i < matched_atoms.size(); i++) { for (size_t j = 0; j < atoms.size(); j++) { @@ -224,8 +224,8 @@ break; AddRegexpsAndCompile(t->regexps, nregexp, &v); string text = "0123"; - vector<int> atom_ids; - vector<int> matching_regexps; + std::vector<int> atom_ids; + std::vector<int> matching_regexps; EXPECT_EQ(0, v.f.FirstMatch(text, atom_ids)); } @@ -245,11 +245,11 @@ string text = "abc121212xyz"; // atoms = abc - vector<int> atom_ids; - vector<string> atoms; + std::vector<int> atom_ids; + std::vector<string> atoms; atoms.push_back("abc"); FindAtomIndices(v.atoms, atoms, &atom_ids); - vector<int> matching_regexps; + std::vector<int> matching_regexps; v.f.AllMatches(text, atom_ids, &matching_regexps); EXPECT_EQ(1, matching_regexps.size());
diff --git a/re2/testing/possible_match_test.cc b/re2/testing/possible_match_test.cc index 3a02699..e757219 100644 --- a/re2/testing/possible_match_test.cc +++ b/re2/testing/possible_match_test.cc
@@ -170,10 +170,10 @@ public: PossibleMatchTester(int maxatoms, int maxops, - const vector<string>& alphabet, - const vector<string>& ops, + const std::vector<string>& alphabet, + const std::vector<string>& ops, int maxstrlen, - const vector<string>& stralphabet) + const std::vector<string>& stralphabet) : RegexpGenerator(maxatoms, maxops, alphabet, ops), strgen_(maxstrlen, stralphabet), regexps_(0), tests_(0) { }
diff --git a/re2/testing/random_test.cc b/re2/testing/random_test.cc index 6060677..bd0842f 100644 --- a/re2/testing/random_test.cc +++ b/re2/testing/random_test.cc
@@ -22,9 +22,10 @@ // (Always uses the same random seeds for reproducibility. // Can give different seeds on command line.) static void RandomTest(int maxatoms, int maxops, - const vector<string>& alphabet, - const vector<string>& ops, - int maxstrlen, const vector<string>& stralphabet, + const std::vector<string>& alphabet, + const std::vector<string>& ops, + int maxstrlen, + const std::vector<string>& stralphabet, const string& wrapper) { // Limit to smaller test cases in debug mode, // because everything is so much slower. @@ -78,7 +79,7 @@ // character classes like \d. (Adding larger character classes would // make for too many possibilities.) TEST(Random, Complicated) { - vector<string> ops = Split(" ", + std::vector<string> ops = Split(" ", "%s%s %s|%s %s* %s*? %s+ %s+? %s? %s?? " "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} %s{1,2} " "%s{2} %s{2,} %s{3,4} %s{4,5}"); @@ -86,11 +87,11 @@ // Use (?:\b) and (?:\B) instead of \b and \B, // because PCRE rejects \b* but accepts (?:\b)*. // Ditto ^ and $. - vector<string> atoms = Split(" ", + std::vector<string> atoms = Split(" ", ". (?:^) (?:$) \\a \\f \\n \\r \\t \\v " "\\d \\D \\s \\S \\w \\W (?:\\b) (?:\\B) " "a (a) b c - \\\\"); - vector<string> alphabet = Explode("abc123\001\002\003\t\r\n\v\f\a"); + std::vector<string> alphabet = Explode("abc123\001\002\003\t\r\n\v\f\a"); RandomTest(10, 10, atoms, ops, 20, alphabet, ""); }
diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc index 7ecf0c9..5566812 100644 --- a/re2/testing/re2_test.cc +++ b/re2/testing/re2_test.cc
@@ -481,7 +481,7 @@ RE2 re100("(?:(?:(?:(?:(?:.)?){100})*)+)"); RE2 re1000("(?:(?:(?:(?:(?:.)?){1000})*)+)"); - map<int, int> histogram; + std::map<int, int> histogram; // 3 is the largest non-empty bucket and has 1 element. CHECK_EQ(3, re1.ProgramFanout(&histogram)); @@ -534,14 +534,14 @@ { RE2 re("(hello world)"); CHECK_EQ(re.NumberOfCapturingGroups(), 1); - const map<string, int>& m = re.NamedCapturingGroups(); + const std::map<string, int>& m = re.NamedCapturingGroups(); CHECK_EQ(m.size(), 0); } { RE2 re("(?P<A>expr(?P<B>expr)(?P<C>expr))((expr)(?P<D>expr))"); CHECK_EQ(re.NumberOfCapturingGroups(), 6); - const map<string, int>& m = re.NamedCapturingGroups(); + const std::map<string, int>& m = re.NamedCapturingGroups(); CHECK_EQ(m.size(), 4); CHECK_EQ(m.find("A")->second, 1); CHECK_EQ(m.find("B")->second, 2); @@ -563,7 +563,7 @@ const RE2::Arg* const matches[4] = {&arg0, &arg1, &arg2, &arg3}; EXPECT_TRUE(RE2::FullMatchN("directions from mountain view to san jose", re, matches, num_groups)); - const map<string, int>& named_groups = re.NamedCapturingGroups(); + const std::map<string, int>& named_groups = re.NamedCapturingGroups(); EXPECT_TRUE(named_groups.find("S") != named_groups.end()); EXPECT_TRUE(named_groups.find("D") != named_groups.end()); @@ -1503,8 +1503,8 @@ // 12 3 45 6 7 RE2 re("((abc)(?P<G2>)|((e+)(?P<G2>.*)(?P<G1>u+)))"); EXPECT_TRUE(re.ok()); - const map<int, string>& have = re.CapturingGroupNames(); - map<int, string> want; + const std::map<int, string>& have = re.CapturingGroupNames(); + std::map<int, string> want; want[3] = "G2"; want[6] = "G2"; want[7] = "G1";
diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 83b5fd7..9a5128f 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc
@@ -7,6 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <string> +#include <utility> #include "util/test.h" #include "re2/prog.h" @@ -802,7 +803,7 @@ CHECK_LT(n, 8*sizeof(int)); CHECK_GT(n, 0); - vector<bool> did(1<<n); + std::vector<bool> did(1<<n); for (int i = 0; i < 1<<n; i++) did[i] = false; @@ -831,6 +832,7 @@ string t; for (int i = n+1; i < 20; i++) { t = s + s; + using std::swap; swap(s, t); } srch(iters, StringPrintf("0[01]{%d}$", n).c_str(), s,
diff --git a/re2/testing/regexp_generator.cc b/re2/testing/regexp_generator.cc index 155472d..7e08a41 100644 --- a/re2/testing/regexp_generator.cc +++ b/re2/testing/regexp_generator.cc
@@ -34,7 +34,7 @@ namespace re2 { // Returns a vector of the egrep regexp operators. -const vector<string>& RegexpGenerator::EgrepOps() { +const std::vector<string>& RegexpGenerator::EgrepOps() { static const char *ops[] = { "%s%s", "%s|%s", @@ -43,13 +43,13 @@ "%s?", "%s\\C*", }; - static vector<string> v(ops, ops + arraysize(ops)); + static std::vector<string> v(ops, ops + arraysize(ops)); return v; } RegexpGenerator::RegexpGenerator(int maxatoms, int maxops, - const vector<string>& atoms, - const vector<string>& ops) + const std::vector<string>& atoms, + const std::vector<string>& ops) : maxatoms_(maxatoms), maxops_(maxops), atoms_(atoms), ops_(ops) { // Degenerate case. if (atoms_.size() == 0) @@ -61,7 +61,7 @@ // Generates all possible regular expressions (within the parameters), // calling HandleRegexp for each one. void RegexpGenerator::Generate() { - vector<string> postfix; + std::vector<string> postfix; GeneratePostfix(&postfix, 0, 0, 0); } @@ -71,7 +71,7 @@ acm_ = &acm; for (int i = 0; i < n; i++) { - vector<string> postfix; + std::vector<string> postfix; GenerateRandomPostfix(&postfix, 0, 0, 0); } @@ -102,7 +102,7 @@ // // The initial call should be GeneratePostfix([empty vector], 0, 0, 0). // -void RegexpGenerator::GeneratePostfix(vector<string>* post, int nstk, +void RegexpGenerator::GeneratePostfix(std::vector<string>* post, int nstk, int ops, int atoms) { if (nstk == 1) RunPostfix(*post); @@ -138,7 +138,7 @@ // Generates a random postfix command sequence. // Stops and returns true once a single sequence has been generated. -bool RegexpGenerator::GenerateRandomPostfix(vector<string>* post, int nstk, +bool RegexpGenerator::GenerateRandomPostfix(std::vector<string>* post, int nstk, int ops, int atoms) { for (;;) { // Stop if we get to a single element, but only sometimes. @@ -181,8 +181,8 @@ // Interprets the postfix command sequence to create a regular expression // passed to HandleRegexp. The results of operators like %s|%s are wrapped // in (?: ) to avoid needing to maintain a precedence table. -void RegexpGenerator::RunPostfix(const vector<string>& post) { - stack<string> regexps; +void RegexpGenerator::RunPostfix(const std::vector<string>& post) { + std::stack<string> regexps; for (size_t i = 0; i < post.size(); i++) { switch (CountArgs(post[i])) { default: @@ -230,8 +230,8 @@ } // Split s into an vector of strings, one for each UTF-8 character. -vector<string> Explode(const StringPiece& s) { - vector<string> v; +std::vector<string> Explode(const StringPiece& s) { + std::vector<string> v; for (const char *q = s.begin(); q < s.end(); ) { const char* p = q; @@ -245,8 +245,8 @@ // Split string everywhere a substring is found, returning // vector of pieces. -vector<string> Split(const StringPiece& sep, const StringPiece& s) { - vector<string> v; +std::vector<string> Split(const StringPiece& sep, const StringPiece& s) { + std::vector<string> v; if (sep.size() == 0) return Explode(s);
diff --git a/re2/testing/regexp_generator.h b/re2/testing/regexp_generator.h index 218929e..0851c7e 100644 --- a/re2/testing/regexp_generator.h +++ b/re2/testing/regexp_generator.h
@@ -28,8 +28,8 @@ // class RegexpGenerator { public: - RegexpGenerator(int maxatoms, int maxops, const vector<string>& atoms, - const vector<string>& ops); + RegexpGenerator(int maxatoms, int maxops, const std::vector<string>& atoms, + const std::vector<string>& ops); virtual ~RegexpGenerator() {} // Generates all the regular expressions, calling HandleRegexp(re) for each. @@ -42,29 +42,30 @@ virtual void HandleRegexp(const string& regexp) = 0; // The egrep regexp operators: * + ? | and concatenation. - static const vector<string>& EgrepOps(); + static const std::vector<string>& EgrepOps(); private: - void RunPostfix(const vector<string>& post); - void GeneratePostfix(vector<string>* post, int nstk, int ops, int lits); - bool GenerateRandomPostfix(vector<string>* post, int nstk, int ops, int lits); + void RunPostfix(const std::vector<string>& post); + void GeneratePostfix(std::vector<string>* post, int nstk, int ops, int lits); + bool GenerateRandomPostfix(std::vector<string>* post, int nstk, int ops, + int lits); - int maxatoms_; // Maximum number of atoms allowed in expr. - int maxops_; // Maximum number of ops allowed in expr. - vector<string> atoms_; // Possible atoms. - vector<string> ops_; // Possible ops. - ACMRandom* acm_; // Random generator. + int maxatoms_; // Maximum number of atoms allowed in expr. + int maxops_; // Maximum number of ops allowed in expr. + std::vector<string> atoms_; // Possible atoms. + std::vector<string> ops_; // Possible ops. + ACMRandom* acm_; // Random generator. DISALLOW_COPY_AND_ASSIGN(RegexpGenerator); }; // Helpers for preparing arguments to RegexpGenerator constructor. // Returns one string for each character in s. -vector<string> Explode(const StringPiece& s); +std::vector<string> Explode(const StringPiece& s); // Splits string everywhere sep is found, returning // vector of pieces. -vector<string> Split(const StringPiece& sep, const StringPiece& s); +std::vector<string> Split(const StringPiece& sep, const StringPiece& s); } // namespace re2
diff --git a/re2/testing/regexp_test.cc b/re2/testing/regexp_test.cc index 75e97bc..92f907f 100644 --- a/re2/testing/regexp_test.cc +++ b/re2/testing/regexp_test.cc
@@ -31,7 +31,7 @@ TEST(Regexp, BigConcat) { Regexp* x; x = Regexp::Parse("x", Regexp::NoParseFlags, NULL); - vector<Regexp*> v(90000, x); // ToString bails out at 100000 + std::vector<Regexp*> v(90000, x); // ToString bails out at 100000 for (size_t i = 0; i < v.size(); i++) x->Incref(); CHECK_EQ(x->Ref(), 1 + static_cast<int>(v.size())) << x->Ref(); @@ -50,11 +50,11 @@ "(?P<g1>a+)|(e)(?P<g2>w*)+(?P<g1>b+)", Regexp::PerlX, &status); EXPECT_TRUE(status.ok()); EXPECT_EQ(4, x->NumCaptures()); - const map<string, int>* have = x->NamedCaptures(); + const std::map<string, int>* have = x->NamedCaptures(); EXPECT_TRUE(have != NULL); EXPECT_EQ(2, have->size()); // there are only two named groups in // the regexp: 'g1' and 'g2'. - map<string, int> want; + std::map<string, int> want; want["g1"] = 1; want["g2"] = 3; EXPECT_EQ(want, *have); @@ -69,10 +69,10 @@ "(?P<g1>a+)|(e)(?P<g2>w*)+(?P<g1>b+)", Regexp::PerlX, &status); EXPECT_TRUE(status.ok()); EXPECT_EQ(4, x->NumCaptures()); - const map<int, string>* have = x->CaptureNames(); + const std::map<int, string>* have = x->CaptureNames(); EXPECT_TRUE(have != NULL); EXPECT_EQ(3, have->size()); - map<int, string> want; + std::map<int, string> want; want[1] = "g1"; want[3] = "g2"; want[4] = "g1";
diff --git a/re2/testing/search_test.cc b/re2/testing/search_test.cc index ac7cace..c14e6c8 100644 --- a/re2/testing/search_test.cc +++ b/re2/testing/search_test.cc
@@ -320,7 +320,7 @@ if (LOGGING) { // Build a dummy ExhaustiveTest call that will trigger just // this one test, so that we log the test case. - vector<string> atom, alpha, ops; + std::vector<string> atom, alpha, ops; atom.push_back(StringPiece(t.regexp).as_string()); alpha.push_back(StringPiece(t.text).as_string()); ExhaustiveTest(1, 0, atom, ops, 1, alpha, "", "");
diff --git a/re2/testing/set_test.cc b/re2/testing/set_test.cc index ea8c213..e84a5c6 100644 --- a/re2/testing/set_test.cc +++ b/re2/testing/set_test.cc
@@ -23,7 +23,7 @@ CHECK_EQ(s.Match("fooba", NULL), true); CHECK_EQ(s.Match("oobar", NULL), true); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("foobar", &v), true); CHECK_EQ(v.size(), 2); CHECK_EQ(v[0], 0); @@ -51,7 +51,7 @@ CHECK_EQ(s.Match("fooba", NULL), true); CHECK_EQ(s.Match("oobar", NULL), false); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("foobar", &v), true); CHECK_EQ(v.size(), 2); CHECK_EQ(v[0], 0); @@ -78,7 +78,7 @@ CHECK_EQ(s.Match("foo", NULL), true); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("foo", &v), true); CHECK_EQ(v.size(), 1); CHECK_EQ(v[0], 0); @@ -98,7 +98,7 @@ CHECK_EQ(s.Match("foo", NULL), true); CHECK_EQ(s.Match("bar", NULL), true); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("foobar", &v), false); CHECK_EQ(v.size(), 0); @@ -125,7 +125,7 @@ CHECK_EQ(s.Match("", NULL), false); CHECK_EQ(s.Match("foobar", NULL), false); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("", &v), false); CHECK_EQ(v.size(), 0); @@ -141,7 +141,7 @@ CHECK_EQ(s.Match("", NULL), false); CHECK_EQ(s.Match("foobar", NULL), false); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("", &v), false); CHECK_EQ(v.size(), 0); @@ -159,7 +159,7 @@ CHECK_EQ(s.Match("/prefix/", NULL), true); CHECK_EQ(s.Match("/prefix/42", NULL), true); - vector<int> v; + std::vector<int> v; CHECK_EQ(s.Match("/prefix", &v), false); CHECK_EQ(v.size(), 0);
diff --git a/re2/testing/string_generator.cc b/re2/testing/string_generator.cc index 15cfe1d..a2e1299 100644 --- a/re2/testing/string_generator.cc +++ b/re2/testing/string_generator.cc
@@ -15,7 +15,8 @@ namespace re2 { -StringGenerator::StringGenerator(int maxlen, const vector<string>& alphabet) +StringGenerator::StringGenerator(int maxlen, + const std::vector<string>& alphabet) : maxlen_(maxlen), alphabet_(alphabet), generate_null_(false), random_(false), nrandom_(0), acm_(NULL) {
diff --git a/re2/testing/string_generator.h b/re2/testing/string_generator.h index ba0ed93..798d062 100644 --- a/re2/testing/string_generator.h +++ b/re2/testing/string_generator.h
@@ -20,7 +20,7 @@ class StringGenerator { public: - StringGenerator(int maxlen, const vector<string>& alphabet); + StringGenerator(int maxlen, const std::vector<string>& alphabet); ~StringGenerator(); const StringPiece& Next(); bool HasNext() { return hasnext_; } @@ -39,14 +39,14 @@ bool RandomDigits(); // Global state. - int maxlen_; // Maximum length string to generate. - vector<string> alphabet_; // Alphabet, one string per letter. + int maxlen_; // Maximum length string to generate. + std::vector<string> alphabet_; // Alphabet, one string per letter. // Iteration state. StringPiece sp_; // Last StringPiece returned by Next(). string s_; // String data in last StringPiece returned by Next(). bool hasnext_; // Whether Next() can be called again. - vector<int> digits_; // Alphabet indices for next string. + std::vector<int> digits_; // Alphabet indices for next string. bool generate_null_; // Whether to generate a NULL StringPiece next. bool random_; // Whether generated strings are random. int nrandom_; // Number of random strings left to generate.
diff --git a/re2/testing/tester.h b/re2/testing/tester.h index 2dce8df..af2637d 100644 --- a/re2/testing/tester.h +++ b/re2/testing/tester.h
@@ -108,7 +108,7 @@ private: bool error_; - vector<TestInstance*> v_; + std::vector<TestInstance*> v_; DISALLOW_COPY_AND_ASSIGN(Tester); };
diff --git a/re2/walker-inl.h b/re2/walker-inl.h index 94ba1e9..ec997a6 100644 --- a/re2/walker-inl.h +++ b/re2/walker-inl.h
@@ -88,7 +88,7 @@ private: // Walk state for the entire traversal. - stack<WalkState<T> >* stack_; + std::stack<WalkState<T> >* stack_; bool stopped_early_; int max_visits_; @@ -132,7 +132,7 @@ }; template<typename T> Regexp::Walker<T>::Walker() { - stack_ = new stack<WalkState<T> >; + stack_ = new std::stack<WalkState<T> >; stopped_early_ = false; }
diff --git a/util/benchmark.cc b/util/benchmark.cc index 8319df1..2bdb9ec 100644 --- a/util/benchmark.cc +++ b/util/benchmark.cc
@@ -9,6 +9,7 @@ #else #include <time.h> #endif +#include <algorithm> #include "util/util.h" #include "util/flags.h" @@ -140,7 +141,7 @@ else n = (int)1e9 / static_cast<int>(ns/n); - n = max(last+1, min(n+n/2, 100*last)); + n = std::max(last+1, std::min(n+n/2, 100*last)); n = round(n); runN(b, n, siz); } @@ -177,7 +178,7 @@ Benchmark* b = benchmarks[i]; if(match(b->name, argc, argv)) for(int j = b->threadlo; j <= b->threadhi; j++) - for(int k = max(b->lo, 1); k <= max(b->hi, 1); k<<=1) + for(int k = std::max(b->lo, 1); k <= std::max(b->hi, 1); k<<=1) RunBench(b, j, k); } }
diff --git a/util/logging.h b/util/logging.h index 7e69ca5..5340a1d 100644 --- a/util/logging.h +++ b/util/logging.h
@@ -77,7 +77,7 @@ Flush(); } } - ostream& stream() { return str_; } + std::ostream& stream() { return str_; } private: const int severity_;
diff --git a/util/mutex.h b/util/mutex.h index 81121a4..d54ded3 100644 --- a/util/mutex.h +++ b/util/mutex.h
@@ -11,7 +11,6 @@ */ #include <stdlib.h> - #if !defined(_WIN32) #include <unistd.h> // For POSIX options #endif
diff --git a/util/pcre.cc b/util/pcre.cc index 87affdc..5839aae 100644 --- a/util/pcre.cc +++ b/util/pcre.cc
@@ -8,6 +8,8 @@ #include <errno.h> #include <limits> +#include <utility> + #include "util/util.h" #include "util/flags.h" #include "util/pcre.h" @@ -431,6 +433,7 @@ if (start < static_cast<int>(str->size())) out.append(*str, start, static_cast<int>(str->size()) - start); + using std::swap; swap(out, *str); return count; }
diff --git a/util/rune.cc b/util/rune.cc index e6231ce..4f625ea 100644 --- a/util/rune.cc +++ b/util/rune.cc
@@ -11,8 +11,10 @@ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */ + #include <stdarg.h> #include <string.h> + #include "util/utf.h" namespace re2 {
diff --git a/util/sparse_array.h b/util/sparse_array.h index c3de793..177419c 100644 --- a/util/sparse_array.h +++ b/util/sparse_array.h
@@ -93,6 +93,8 @@ // destroyed when the SparseArray destructor is called. #include <string.h> +#include <utility> +#include <vector> #include "util/util.h" @@ -109,8 +111,8 @@ class IndexValue; typedef IndexValue value_type; - typedef typename vector<IndexValue>::iterator iterator; - typedef typename vector<IndexValue>::const_iterator const_iterator; + typedef typename std::vector<IndexValue>::iterator iterator; + typedef typename std::vector<IndexValue>::const_iterator const_iterator; inline const IndexValue& iv(int i) const; @@ -155,14 +157,14 @@ // Comparison function for sorting. // Can sort the sparse array so that future iterations // will visit indices in increasing order using - // sort(arr.begin(), arr.end(), arr.less); + // std::sort(arr.begin(), arr.end(), arr.less); static bool less(const IndexValue& a, const IndexValue& b); public: // Set the value at index i to v. inline iterator set(int i, Value v); - pair<iterator, bool> insert(const value_type& new_value); + std::pair<iterator, bool> insert(const value_type& new_value); // Returns the value at index i // or defaultv if index i is not initialized in the array. @@ -233,7 +235,7 @@ int size_; int max_size_; int* sparse_to_dense_; - vector<IndexValue> dense_; + std::vector<IndexValue> dense_; DISALLOW_COPY_AND_ASSIGN(SparseArray); }; @@ -333,14 +335,16 @@ } template<typename Value> -pair<typename SparseArray<Value>::iterator, bool> SparseArray<Value>::insert( - const value_type& new_value) { +std::pair<typename SparseArray<Value>::iterator, bool> +SparseArray<Value>::insert(const value_type& new_value) { DebugCheckInvariants(); - pair<typename SparseArray<Value>::iterator, bool> p; + std::pair<typename SparseArray<Value>::iterator, bool> p; if (has_index(new_value.index_)) { - p = make_pair(dense_.begin() + sparse_to_dense_[new_value.index_], false); + p = std::make_pair( + dense_.begin() + sparse_to_dense_[new_value.index_], false); } else { - p = make_pair(set_new(new_value.index_, new_value.second), true); + p = std::make_pair( + set_new(new_value.index_, new_value.second), true); } DebugCheckInvariants(); return p;
diff --git a/util/sparse_set.h b/util/sparse_set.h index 9470052..176eff8 100644 --- a/util/sparse_set.h +++ b/util/sparse_set.h
@@ -162,7 +162,7 @@ // Comparison function for sorting. // Can sort the sparse array so that future iterations // will visit indices in increasing order using - // sort(arr.begin(), arr.end(), arr.less); + // std::sort(arr.begin(), arr.end(), arr.less); static bool less(int a, int b) { return a < b; } private:
diff --git a/util/test.cc b/util/test.cc index 0a751fe..fb31ed8 100644 --- a/util/test.cc +++ b/util/test.cc
@@ -6,6 +6,7 @@ #ifndef _WIN32 #include <sys/resource.h> #endif + #include "util/test.h" DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
diff --git a/util/util.h b/util/util.h index d7a274b..f70357d 100644 --- a/util/util.h +++ b/util/util.h
@@ -5,36 +5,9 @@ #ifndef UTIL_UTIL_H_ #define UTIL_UTIL_H_ -// C++ -#include <ctime> -#include <vector> +// TODO(junyer): Get rid of this. #include <string> -#include <algorithm> -#include <iosfwd> -#include <map> -#include <stack> -#include <ostream> -#include <utility> -#include <set> -#include <atomic> -#include <mutex> // For std::call_once -#include <unordered_set> -#include <initializer_list> - -// Use std names. -using std::set; -using std::pair; -using std::vector; using std::string; -using std::min; -using std::max; -using std::ostream; -using std::map; -using std::stack; -using std::sort; -using std::swap; -using std::make_pair; -using std::unordered_set; #ifdef _WIN32