本文整理汇总了C++中Cont::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Cont::begin方法的具体用法?C++ Cont::begin怎么用?C++ Cont::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cont
的用法示例。
在下文中一共展示了Cont::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert_front
void insert_front(Cont& c, long& avg, const int& num_op)
{
cout << "\nCounting..."
<< "time of " << num_op << " front_insert";
clock_t t = 0;
for(int j = 0; j < REPEAT_TEST; ++j)
{
c.push_back(0);
c.push_back(0);
auto it = c.begin();
t = clock();
for (int i = 1; i <= num_op ; ++i)
{
it = c.begin();
c.insert(it, i);
}
t = clock() - t;
avg += t;
c.clear();
}
avg /= REPEAT_TEST;
}
示例2: insert
bool insert(T t) {
ContIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it != elements.end() && t >= it->lb && t <= it->ub) {
return false;
}
ContIter pr = it - 1;
if (it != elements.begin() && pr->ub + 1 == t) {
++pr->ub;
if (it != elements.end() && pr->ub + 1 == it->lb) {
pr->ub = it->ub;
elements.erase(it);
}
}
else if (it != elements.end() && it->lb == t + 1) {
--it->lb;
if (it != elements.begin() && pr->ub + 1 == it->lb) {
pr->ub = it->ub;
elements.erase(it);
}
}
else {
elements.insert(it, interval(t));
}
++_size;
return true;
}
示例3: midInsertion
void midInsertion(Cont& ci) {
typename Cont::iterator it = ci.begin();
it++;
it++;
it++;
copy(a, a + sizeof(a)/(sizeof(int)*2), inserter(ci, it));
copy(ci.begin(), ci.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
示例4: midInsertion
template<class Cont> void midInsertion(Cont& ci) {
typename Cont::iterator it = ci.begin();
++it; ++it; ++it;
copy(a, a + sizeof(a)/(sizeof(Cont::value_type) * 2),
inserter(ci, it));
copy(ci.begin(), ci.end(),
ostream_iterator<typename Cont::value_type>(
cout, " "));
cout << endl;
}
示例5: operator
void operator()(Cont& c, long count) {
int middle = c.size() / 2;
typename Cont::iterator it = c.begin(),
mid = c.begin();
it++; // Put it in the middle
for (int x = 0; x < middle + 1; x++)
mid++;
long cnt = count * 10;
for (long i = 0; i < cnt; i++)
swap(*it, *mid);
}
示例6: erase
bool erase(T t) {
ContIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it == elements.end()) {
return false;
}
if (it->ub < t || it->lb > t) {
return false;
}
if (it->lb == t && it->ub == t) {
elements.erase(it);
--_size;
return true;
}
if (it->ub == t) {
--it->ub;
--_size;
return true;
}
if (it->lb == t) {
++it->lb;
--_size;
return true;
}
if (it->lb < t && it->ub > t) {
elements.insert(it + 1, interval(t + 1, it->ub));
it->ub = t - 1;
--_size;
return true;
}
assert(false && "interval_vector.erase() should never reach this place...");
return false;
}
示例7: intersect
interval_vector intersect(const interval_vector& o) const {
interval_vector rv;
if (!empty() && !o.empty()) {
ContConstIter a = elements.begin();
ContConstIter b = o.elements.begin();
while (a != elements.end() && b != o.elements.end()) {
while (a != elements.end() && b != o.elements.end() && a->ub < b->lb) {
++a;
}
while (a != elements.end() && b != o.elements.end() && b->ub < a->lb) {
++b;
}
while (a != elements.end() && b != o.elements.end() && a->ub >= b->lb && b->ub >= a->lb) {
const T lb = std::max(a->lb, b->lb);
const T ub = std::min(a->ub, b->ub);
if (!rv.elements.empty() && rv.elements.back().ub + 1 == lb) {
rv.elements.back().ub = ub;
}
else {
rv.elements.push_back(interval(lb, ub));
}
rv._size += ub - lb + 1;
if (a->ub < b->ub) {
++a;
}
else {
++b;
}
}
}
}
return rv;
}
示例8: apply
void apply(Cont& c, PtrMemFun f) {
typename Cont::iterator it = c.begin();
while (it != c.end()) {
//(it->*f)(); // Compact form //! gcc-4.4 gcc-4.6 ±àÒ벻ͨ¹ý
((*it).*f)(); // Alternate form
it++;
}
}
示例9: backInsertion
template<class Cont> void backInsertion(Cont& ci) {
copy(a, a + sizeof(a)/sizeof(Cont::value_type),
back_inserter(ci));
copy(ci.begin(), ci.end(),
ostream_iterator<typename Cont::value_type>(
cout, " "));
cout << endl;
}
示例10: dump
void dump(Cont & container)
{
for (ContIter iter = container.begin(); iter != container.end(); iter++)
{
cout << *iter << " ";
}
cout << endl;
}
示例11: do_move
static void do_move(Cont& styls, int type, int& first, int& last, bool storage) {
auto begin = styls.begin();
// Move up
if (type == 0) {
if (first == 0) return;
rotate(begin + first - 1, begin + first, begin + last + 1);
first--;
last--;
}
// Move to top
else if (type == 1) {
rotate(begin, begin + first, begin + last + 1);
last = last - first;
first = 0;
}
// Move down
else if (type == 2) {
if (last + 1 == (int)styls.size()) return;
rotate(begin + first, begin + last + 1, begin + last + 2);
first++;
last++;
}
// Move to bottom
else if (type == 3) {
rotate(begin + first, begin + last + 1, styls.end());
first = styls.size() - (last - first + 1);
last = styls.size() - 1;
}
// Sort
else if (type == 4) {
// Get confirmation
if (storage) {
int res = wxMessageBox(_("Are you sure? This cannot be undone!"), _("Sort styles"), wxYES_NO | wxCENTER);
if (res == wxNO) return;
}
sort(styls.begin(), styls.end(), cmp_name());
first = 0;
last = 0;
}
}
示例12: hasher
typename std::enable_if<is_hashable<typename Cont::value_type>::value, void>::type
hash_container_object(const Cont & cont, Hasher & hasher)
{
// some containers don't have size() (ie, forward_list)
size_t d = static_cast<size_t>(std::distance(cont.begin(), cont.end()));
hasher(d);
for(const auto & it : cont)
hasher(it);
}
示例13: find
const_iterator find(T t) const {
ContConstIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it == elements.end()) {
return end();
}
if (it->ub < t || it->lb > t) {
return end();
}
return const_iterator(elements, it, t);
}
示例14: contains
bool contains(T t) const {
ContConstIter it = std::lower_bound(elements.begin(), elements.end(), t);
if (it == elements.end()) {
return false;
}
if (it->ub < t || it->lb > t) {
return false;
}
return true;
}
示例15: T
const_iterator& operator--() {
if (it == elements->end() || t == it->lb) {
if (it == elements->begin()) {
t = T();
it = elements->end();
}
else {
--it;
t = it->ub;
}
}
else {
--t;
}
return *this;
}