小编TJ *_*ese的帖子

符合c ++标准的迭代器迭代器

我想做什么

我有一个分区的方法.此方法不完全对数组进行排序; 它只是对数组进行分区,使得一侧的所有元素(某些预先确定的"中心"或"中点值" - 它不必导致偶数分裂)但小于"中心"和另一侧的所有元素都大于中心.要点:在传统意义上,它不是一种"排序"; 这是一个分区.

当我分割东西时,我需要保留一个键; 因此,当事情被交换时,密钥被交换; 如果在将来某个时候我想撤消分区,我可以根据密钥重新排列.

显然,基于关键值重新排列事物,我可以做类似的事情

std::vector< std::pair< std::size_t , my::thingie > > vp;
std::vector< std::size_t >::iterator itKey( key.begin() );
// itThingie_begin and itThingie_end exist; I don't have direct access to the container 
my::thingie::iterator itThingie( itThingie_begin );
for (; itKey != key.end(); ++itKey; ++itThingie ) vp.push_back( *itKey, *itThingie );
std::sort( vp.begin() , vp.end() , &comp_pair_first );
itThingie = itThingie_begin;
for ( std::vector< std::pair< std::size_t , my::thingie > >::const_iterator p=vp.begin(); p!=vp.end(); ++p, ++itThingie ) *itThingie …
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl

6
推荐指数
1
解决办法
2130
查看次数

标签 统计

c++ ×1

iterator ×1

stl ×1