inline void GAppSetOpts_ranged(const char *value, Cont& cont) { cont.clear(); bool had_range = false; const char *comma = value; do { uint32_t low = abs(atoi(comma)), high = low; const char *delim = strchr(comma, '-'); const char *nextc = strchr(comma, ','); if (delim && (nextc == 0 || nextc > delim)) { had_range = true; high = abs(atoi(delim + 1)); } for (; low <= high; ++low) { cont.push_back(low); } } while ((comma = strchr(comma, ',')) != 0 && ++comma && *comma != 0); if (cont.size() == 1 && !had_range) { uint32_t val = cont.front(); cont.clear(); for (uint32_t i = 1; i <= val; ++i) { cont.push_back(i); } } }
void insert_back(Cont& c, long& avg, const int& num_op) { cout << "\nCounting..." << "time of " << num_op << " back_insert"; clock_t t = 0; for(int j = 0; j < REPEAT_TEST; ++j) { c.push_back(0); c.push_back(0); auto it = c.end(); t = clock(); for (int i = 1; i <= num_op ; ++i) { it = c.end(); c.insert(it, i); } t = clock() - t; avg += t; c.clear(); } avg /= REPEAT_TEST; }
Cont keep_if(Pred pred, const Cont& xs) { Cont ys; for (const auto x : xs) { if (pred(x)) { ys.push_back(x); } } return ys; }
void strategy1() { int numElems; cin >> numElems; Cont container; for (int ii = 0; ii < numElems; ii++) { container.push_back(0); cin >> container.back(); } for (int day = 0; ; day++) { list<ContIter> toDelete; ContIter iThis(container.begin()); ContIter iPrev(iThis); iThis++; while (iThis != container.end()) { if (*iThis > *iPrev) { toDelete.push_back(iThis); } iThis++; iPrev++; } if (toDelete.empty()) { cout << day << endl; break; } // cout << "toDelete "; // dump(toDelete); for (list<ContIter>::reverse_iterator iDel = toDelete.rbegin(); iDel != toDelete.rend(); iDel++) { container.erase(*iDel); } // dump(container); } }
void push_back(Cont& c, long& avg, const int& num_op) { cout << "\nCounting..." << "time of " << num_op << " push_back"; clock_t t = 0; for(int j = 0; j < REPEAT_TEST; ++j) { t = clock(); for (int i = 1; i <= num_op ; ++i) { c.push_back(i); } t = clock() - t; avg += t; c.clear(); } c.clear(); avg /= REPEAT_TEST; }
void operator()() const { cont->push_back(argument_type()); }
void operator()(const V&v) const { cont->push_back(v); }
void operator()(Cont& c, long count) { for (long i = 0; i < count; i++) c.push_back(fs); }
Back_inserter& operator=(typename Cont::const_reference val) { c->push_back(val); return *this; }