本文整理汇总了C++中std::vector::rend方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::rend方法的具体用法?C++ vector::rend怎么用?C++ vector::rend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::rend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nextPermutation
void Solution::nextPermutation(std::vector<int>& numbers)
{
auto it = numbers.rbegin();
for (; it != numbers.rend(); ++it)
{
auto head_it = it.base();
if (head_it == numbers.end())
{
continue;
}
if (*it < *head_it)
{
break;
}
}
if (it == numbers.rend())
{
std::reverse(numbers.rbegin(), numbers.rend());
return;
}
const auto find_it = std::upper_bound(numbers.rbegin(), it, *it, std::less<>());
assert(find_it != numbers.rend());
std::iter_swap(it, find_it);
std::reverse(numbers.rbegin(), it);
}
示例2: hasByValue
/// \param[in] t_params the list of params to search
/// \param[in] t_value the value to search for
/// \returns the JobParam matching the given value. Throws an exception if it is not found
static bool hasByValue(const std::vector<JobParam> &t_params, const std::string &t_value)
{
auto itr = std::find_if(t_params.rbegin(), t_params.rend(), JobParamValueCompare(t_value));
if (itr != t_params.rend())
{
return true;
}
return false;
}
示例3: prevPerm
std::vector<int> prevPerm(std::vector<int> data)
{
auto inversionPoint = std::is_sorted_until(data.rbegin(), data.rend(), [&data](const int& a, const int& b) { return a > b; });
if (inversionPoint == data.rend())
{
return {};
}
auto mostLowerBound = std::lower_bound(data.rbegin(), inversionPoint, *inversionPoint, cmp);
std::iter_swap(mostLowerBound, inversionPoint);
std::reverse(data.rbegin(), inversionPoint);
return data;
}
示例4: createActionChain
void HelloWorld::createActionChain(const std::vector<TileData*>& path)
{
if (path.size() <= 0) return;
Size mapSize = m_gamemap->getMapSize();
Size tilesize = m_gamemap->getTileSize();
int mapheight = mapSize.height * tilesize.height;
Vector<FiniteTimeAction*> actions;
std::vector<TileData*>::const_reverse_iterator rIter = path.rbegin();
rIter++;
while (rIter != path.rend())
{
int destination_x = (*rIter)->position().first * tilesize.width + tilesize.width / 2;
int destination_y = (*rIter)->position().second * tilesize.height + tilesize.height / 2;
Vec2 destination(destination_x, mapheight - destination_y);
MoveTo* action = MoveTo::create(0.5f, destination);
actions.pushBack(action);
rIter++;
}
if (actions.size() > 0)
{
Sequence* action_seq = Sequence::create(actions);
m_player->runAction(action_seq);
}
}
示例5: traverseSprites
void SpritesPanelImpl::traverseSprites(const std::vector<d2d::ISprite*>& sprites,
IVisitor& visitor, TraverseType type/* = e_allExisting*/,
bool order/* = true*/)
{
if (order)
{
std::vector<ISprite*>::const_iterator itr = sprites.begin();
for ( ; itr != sprites.end(); ++itr)
{
bool hasNext;
visitor.visit(*itr, hasNext);
if (!hasNext) break;
}
}
else
{
std::vector<ISprite*>::const_reverse_iterator itr = sprites.rbegin();
for ( ; itr != sprites.rend(); ++itr)
{
bool hasNext;
visitor.visit(*itr, hasNext);
if (!hasNext) break;
}
}
}
示例6: updateLeavesSpawn
bool updateLeavesSpawn() {
bool fullGridSpawn = (newLeaves.size() == (unsigned)theHeriswapGridSystem.GridSize*theHeriswapGridSystem.GridSize);
ADSR(haveToAddLeavesInGrid)->active = true;
for ( std::vector<Feuille>::reverse_iterator it = newLeaves.rbegin(); it != newLeaves.rend(); ++it ) {
if (it->entity == 0) {
it->entity = createCell(*it, fullGridSpawn);
} else {
HeriswapGridComponent* gc = HERISWAPGRID(it->entity);
if (fullGridSpawn) {
gc->i = gc->j = -1;
}
TransformationComponent* tc = TRANSFORM(it->entity);
//leaves grow up from 0 to fixed size
glm::vec2 s = HeriswapGame::CellSize(theHeriswapGridSystem.GridSize, gc->type);
if (ADSR(haveToAddLeavesInGrid)->value == 1){
tc->size = glm::vec2(s.x, s.y);
gc->i = it->X;
gc->j = it->Y;
} else {
tc->size = s * ADSR(haveToAddLeavesInGrid)->value;
}
}
}
return (ADSR(haveToAddLeavesInGrid)->value == 1);
}
示例7: rcsort
void CountingSort::rcsort(std::vector<unsigned int>& A, std::vector<unsigned int>& B, unsigned int d)
{
std::vector<unsigned int> C(10);
for (auto c = C.begin(); c != C.end(); ++c)
*c = 0;
//std::cout << "C: "; print(C);
for (auto a = A.begin(); a != A.end(); ++a)
++C[digit(*a,d)];
//std::cout << "A: "; print(A);
//std::cout << "C: "; print(C);
for (auto c = C.begin() + 1; c != C.end(); ++c)
*c += *(c - 1);
//std::cout << "C: "; print(C);
for (auto a = A.rbegin(); a != A.rend(); ++a) {
B[C[digit(*a,d)] - 1] = *a;
--C[digit(*a,d)];
}
}
示例8: testFindDistanceBetween
int testFindDistanceBetween(const std::string & s1, const std::string & s2,
const std::vector<std::string> & fileAsAnArray) {
if (s1.compare(s2) == 0) { return 0; }
int minDistance = INT_MAX;
bool found = false;
for (auto it = fileAsAnArray.begin(); it != fileAsAnArray.end(); ++it) {
if (it->compare(s1) == 0) {
found = true;
auto itBack = std::vector<std::string>::const_reverse_iterator(it);
--itBack; // When converted, it points to predecessor of it
auto beginR = itBack;
assert(beginR->compare(*it) == 0);
auto itForth = it;
auto distance = INT_MAX;
while (itBack != fileAsAnArray.rend()) {
if (itBack->compare(s2) == 0) {
distance = abs(std::distance(itBack, beginR));
break;
}
++itBack;
}
while (itForth != fileAsAnArray.end()) {
if (itForth->compare(s2) == 0) {
distance = min(distance, abs(std::distance(it, itForth)));
break;
}
++itForth;
}
minDistance = min(distance, minDistance);
}
}
if (!found) { return -1; }
return minDistance;
}
示例9: extractEuclideanClusters
template <typename PointT> void
pcl16::EuclideanClusterExtraction<PointT>::extract (std::vector<PointIndices> &clusters)
{
if (!initCompute () ||
(input_ != 0 && input_->points.empty ()) ||
(indices_ != 0 && indices_->empty ()))
{
clusters.clear ();
return;
}
// Initialize the spatial locator
if (!tree_)
{
if (input_->isOrganized ())
tree_.reset (new pcl16::search::OrganizedNeighbor<PointT> ());
else
tree_.reset (new pcl16::search::KdTree<PointT> (false));
}
// Send the input dataset to the spatial locator
tree_->setInputCloud (input_, indices_);
extractEuclideanClusters (*input_, *indices_, tree_, static_cast<float> (cluster_tolerance_), clusters, min_pts_per_cluster_, max_pts_per_cluster_);
//tree_->setInputCloud (input_);
//extractEuclideanClusters (*input_, tree_, cluster_tolerance_, clusters, min_pts_per_cluster_, max_pts_per_cluster_);
// Sort the clusters based on their size (largest one first)
std::sort (clusters.rbegin (), clusters.rend (), comparePointClusters);
deinitCompute ();
}
示例10: switch
extern "C" NS_EXPORT pid_t
WRAP(fork)(void)
{
pid_t pid;
for (std::vector<AtForkFuncs>::reverse_iterator it = atfork.rbegin();
it < atfork.rend(); ++it)
if (it->prepare)
it->prepare();
switch ((pid = __fork())) {
case 0:
cpuacct_add(getuid());
for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
it < atfork.end(); ++it)
if (it->child)
it->child();
break;
default:
for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
it < atfork.end(); ++it)
if (it->parent)
it->parent();
}
return pid;
}
示例11: Shrink
/*
** Trims empty element in vector and white-space in each string.
**
*/
void CConfigParser::Shrink(std::vector<std::wstring>& vec)
{
if (!vec.empty())
{
std::vector<std::wstring>::reverse_iterator iter = vec.rbegin();
while (iter != vec.rend())
{
std::wstring::size_type pos = (*iter).find_first_not_of(L" \t\r\n");
if (pos != std::wstring::npos)
{
std::wstring::size_type lastPos = (*iter).find_last_not_of(L" \t\r\n");
if (pos != 0 || lastPos != ((*iter).size() - 1))
{
// Trim white-space
(*iter).assign((*iter), pos, lastPos - pos + 1);
}
++iter;
}
else
{
// Remove empty element
vec.erase((++iter).base());
}
}
}
}
示例12: processData
void CSVExporter::processData(const unsigned char* buffer, size_t bufferSize, float baseTime, const std::vector<ProcedureDescription>& proceduresDescriptions)
{
file << "name;pid;num_threads;item_input;input_size;shared_memory" << std::endl;
for (auto p = proceduresDescriptions.rbegin(); p != proceduresDescriptions.rend(); ++p)
{
file << p->name << ';' << p->ProcedureId << ';' << p->NumThreads << ';' << p->ItemInput << ';' << p->inputSize << ';' << p->sharedMemory << '\n';
}
file << std::endl;
file << "t0;t1;pid;mpid;active_threads;overhead_counter;dequeue_time;{enqueue_stats_pid;enqueue_stats_count}" << std::endl;
for (const unsigned char* data = buffer; data < buffer + bufferSize;)
{
int num_enqueue_stats = Instrumentation::unpack_num_enqueue_stats(data);
file << Instrumentation::unpack_t0(data) << ';'
<< Instrumentation::unpack_t1(data) << ';'
<< Instrumentation::unpack_pid(data) << ';'
<< Instrumentation::unpack_mpid(data) << ';'
<< Instrumentation::unpack_active_threads(data) << ';'
<< Instrumentation::unpack_overhead_counter(data) << ';'
<< Instrumentation::unpack_dequeue_time(data);
if (num_enqueue_stats > 0)
{
for (int i = 0; i < num_enqueue_stats; ++i)
file << ';'<< Instrumentation::unpack_enqueue_stat_pid(data, i) << ';'<< Instrumentation::unpack_enqueue_stat_count(data, i);
}
file << std::endl;
data = Instrumentation::next_element(data, num_enqueue_stats);
}
file << std::endl;
}
示例13: convertStringElementsToPackageElements
bool ParserMixin::convertStringElementsToPackageElements(const ParseContextSPtr& context,
const std::vector<std::string>& string_elements,
std::vector<PackageElementSPtr>& package_elements)
{
std::vector<PackageElementSPtr>::const_reverse_iterator eit = context->mSourceId->externalElements().rbegin();
std::vector<std::string>::const_reverse_iterator it;
for (it = string_elements.rbegin(); it != string_elements.rend(); ++it)
{
PackageElementSPtr pe;
if (*it == "*")
{
if (eit == context->mSourceId->externalElements().rend())
{
context->mMessageCollector->addMessage(errorMessage(context, Message::p_asteriskPackageElement));
return false;
}
pe = *eit;
++eit;
}
else
{
if (*eit && (*eit)->value() == *it)
++eit;
pe = boost::make_shared<PackageElement>();
pe->set_value(*it);
}
package_elements.insert(package_elements.begin(), pe);
}
return true;
}
示例14: CountDistinctValues
size_t CountDistinctValues(std::vector<int> numbers){
size_t abs_count = numbers.size();
auto f_it = numbers.begin();
auto r_it = numbers.rbegin();
while(f_it != numbers.end() && r_it != numbers.rend()){
//std::cout << "Forward iterator: " << *f_it << std::endl;
//std::cout << "Reverse iterator: " << *r_it << std::endl;
if((f_it - numbers.begin()) + (r_it - numbers.rbegin()) == numbers.size()-1) break;
if(*f_it == *(f_it+1)){ // considering duplicates on the left side of an array
--abs_count;
++f_it;
continue;
}
if(*r_it == *(r_it+1)){ // considering duplicates on the right side of an array
--abs_count;
++r_it;
continue;
}
if(abs(*f_it) == abs(*r_it)){
--abs_count;
++f_it;
++r_it;
} else if(abs(*f_it) > abs(*r_it))
++f_it;
else
++r_it;
}
return abs_count;
}
示例15: mouse
void sdl_event_handler::mouse(const ui_event event, const point& position)
{
DBG_GUI_E << "Firing: " << event << ".\n";
if(mouse_focus) {
mouse_focus->fire(
event, dynamic_cast<widget&>(*mouse_focus), position);
} else {
for(std::vector<dispatcher*>::reverse_iterator ritor
= dispatchers_.rbegin();
ritor != dispatchers_.rend();
++ritor) {
if((**ritor).get_mouse_behavior() == dispatcher::all) {
(**ritor)
.fire(event, dynamic_cast<widget&>(**ritor), position);
break;
}
if((**ritor).get_mouse_behavior() == dispatcher::none) {
continue;
}
if((**ritor).is_at(position)) {
(**ritor)
.fire(event, dynamic_cast<widget&>(**ritor), position);
break;
}
}
}
}