本文整理汇总了C++中typenamestd::vector::base方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::base方法的具体用法?C++ vector::base怎么用?C++ vector::base使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenamestd::vector
的用法示例。
在下文中一共展示了vector::base方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add
// adds a value, returning false if the given token is not
// "reasonable". A reasonable token is one not currently in use,
// and if any previously used tokens are available, it must be one
// of the previously used ones. If no previously used tokens are
// available, it must be the smallest unused token. You'll get
// good performance if you never choose a bad token and use the
// most recently dropped token.
bool add(token_type known_token, T const& value) {
if (free_.empty()) {
if (known_token == values_.size()) {
values_.push_back(value);
#ifndef NDEBUG
is_free_.push_back(false);
#endif
return true;
} else {
return false;
}
} else {
// If a replicand used add(), then it picked the token
// from the bock of its free list. So the replicant, the
// presumed caller of this function, searches in reverse
// order.
typename std::vector<token_t>::reverse_iterator p = std::find(free_.rbegin(), free_.rend(), known_token);
if (p == free_.rend()) {
return false;
}
if (values_.size() > known_token) {
free_.erase(p.base() - 1);
values_[known_token] = value;
rassert(is_free_[known_token]);
#ifndef NDEBUG
is_free_[known_token] = false;
#endif
return true;
} else {
return false;
}
}
}