本文整理汇总了C++中std::list::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ list::swap方法的具体用法?C++ list::swap怎么用?C++ list::swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::list
的用法示例。
在下文中一共展示了list::swap方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: heuristic_search
void heuristic_search(const cholmod_sparse* const NNE,
std::list<int>& ordering,
std::list<int>& MIS) {
std::list<int> tempMIS;
size_t to_check = static_cast<size_t>(std::sqrt(static_cast<long double>(NNE->ncol))) + 10000;
if (to_check > NNE->ncol) {
to_check = NNE->ncol;
}
// 1,2,3,4,5
// 2,1,3,4,5
// 1,3,2,4,5
// 3,2,4,1,5
// 2,4,1,5,3
// etc...
std::list<int>::iterator insert_position = ordering.begin();
for (size_t i = 0; i < to_check; ++i) {
++insert_position;
ordering.insert(insert_position, ordering.front());
ordering.pop_front();
findMIS_in_sp_order(NNE, ordering, tempMIS);
if (tempMIS.size() > MIS.size()) {
MIS.swap(tempMIS);
}
tempMIS.clear();
}
}
示例2: GetMessages
bool BaseConnection::GetMessages(std::list<IncomingMessage::sptr>& messages) {
if (state_ != STATE_CONNECTED || incoming_.empty()) {
return false;
}
messages.swap(incoming_);
return true;
}
示例3: fpathSetBlockingMap
void fpathSetBlockingMap(PATHJOB *psJob)
{
if (fpathCurrentGameTime != gameTime)
{
// New tick, remove maps which are no longer needed.
fpathCurrentGameTime = gameTime;
fpathPrevBlockingMaps.swap(fpathBlockingMaps);
fpathBlockingMaps.clear();
}
// Figure out which map we are looking for.
PathBlockingType type;
type.gameTime = gameTime;
type.propulsion = psJob->propulsion;
type.owner = psJob->owner;
type.moveType = psJob->moveType;
// Find the map.
std::list<PathBlockingMap>::iterator i = std::find(fpathBlockingMaps.begin(), fpathBlockingMaps.end(), type);
if (i == fpathBlockingMaps.end())
{
// Didn't find the map, so i does not point to a map.
fpathBlockingMaps.push_back(PathBlockingMap());
--i;
// i now points to an empty map with no data. Fill the map.
i->type = type;
std::vector<bool> &map = i->map;
map.resize(mapWidth*mapHeight);
uint32_t checksumMap = 0, checksumDangerMap = 0, factor = 0;
for (int y = 0; y < mapHeight; ++y)
for (int x = 0; x < mapWidth; ++x)
{
map[x + y*mapWidth] = fpathBaseBlockingTile(x, y, type.propulsion, type.owner, type.moveType);
checksumMap ^= map[x + y*mapWidth]*(factor = 3*factor + 1);
}
if (!isHumanPlayer(type.owner) && type.moveType == FMT_MOVE)
{
std::vector<bool> &dangerMap = i->dangerMap;
dangerMap.resize(mapWidth*mapHeight);
for (int y = 0; y < mapHeight; ++y)
for (int x = 0; x < mapWidth; ++x)
{
dangerMap[x + y*mapWidth] = auxTile(x, y, type.owner) & AUXBITS_THREAT;
checksumDangerMap ^= map[x + y*mapWidth]*(factor = 3*factor + 1);
}
}
syncDebug("blockingMap(%d,%d,%d,%d) = %08X %08X", gameTime, psJob->propulsion, psJob->owner, psJob->moveType, checksumMap, checksumDangerMap);
}
else
{
syncDebug("blockingMap(%d,%d,%d,%d) = cached", gameTime, psJob->propulsion, psJob->owner, psJob->moveType);
}
// i now points to the correct map. Make psJob->blockingMap point to it.
psJob->blockingMap = &*i;
}
示例4: subdiv_circle
void UnionOfBallsView::subdiv_circle(const Weighted_point &wp, std::list<Segment> &segments, int subdiv)
{
if (wp.weight() > 0) {
for (int i=0; i<subdiv; ++i) {
std::list<Segment> segments2;
BOOST_FOREACH(Segment &s, segments) {
Bare_point m = CGAL::midpoint(s[0], s[1]);
Vector v = m-wp;
m = wp + sqrt(wp.weight()/v.squared_length()) * v;
segments2.push_back(Segment(s[0], m));
segments2.push_back(Segment(m, s[1]));
}
segments.swap(segments2);
}
}
示例5: RemoveStopedThreads
inline void ThreadPool::RemoveStopedThreads()
{
std::list<TaskThread*> tmp;
for (std::list<TaskThread*>::iterator i = stopThreads.begin();
i != stopThreads.end(); ++i)
{
if ((*i)->IsAlive())
{
tmp.push_back(*i);
}
else
{
delete *i;
}
}
stopThreads.swap(tmp);
}
示例6: FilterTargets
void FilterTargets(std::list<WorldObject*>& targets)
{
targets.sort(Trinity::ObjectDistanceOrderPred(GetCaster()));
if (targets.empty())
return;
std::list<WorldObject*> ranged, melee;
std::list<WorldObject*>::iterator itr = targets.begin();
if ((*itr)->ToCreature())
return;
while (itr != targets.end() && (*itr)->GetDistance(GetCaster()) < 5.0f)
{
melee.push_back((*itr)->ToUnit());
++itr;
}
while (itr != targets.end())
{
ranged.push_back((*itr)->ToUnit());
++itr;
}
uint32 minTargets = GetCaster()->GetMap()->Is25ManRaid() ? 8 : 3;
while (ranged.size() < minTargets)
{
if (melee.empty())
break;
WorldObject* target = Trinity::Containers::SelectRandomContainerElement(melee);
ranged.push_back(target);
melee.remove(target);
}
if (!ranged.empty())
Trinity::Containers::RandomResizeList(ranged, GetCaster()->GetMap()->Is25ManRaid() ? 3 : 1);
targets.swap(ranged);
}
示例7: ready
//----------------------------------------------------------------
// ready
//
static bool
ready(std::map<Task::TimePoint, std::list<TaskPtr> > & tasks,
std::list<TaskPtr> & next,
Task::TimePoint & next_time_point)
{
std::map<Task::TimePoint, std::list<TaskPtr> >::iterator i = tasks.begin();
if (i == tasks.end())
{
return false;
}
Task::TimePoint now = (boost::chrono::steady_clock::now() +
boost::chrono::milliseconds(1));
if (now < i->first)
{
next_time_point = i->first;
return false;
}
next.swap(i->second);
tasks.erase(i);
return true;
}
示例8: ProcessSelection
void CSearchDialog::ProcessSelection(std::list<int> &selected_files, std::list<CServerPath> &selected_dirs)
{
int sel = -1;
while ((sel = m_results->GetNextItem(sel, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1)
{
if (sel > (int)m_results->m_indexMapping.size())
continue;
int index = m_results->m_indexMapping[sel];
if (m_results->m_fileData[index].entry.is_dir())
{
CServerPath path = m_results->m_fileData[index].path;
path.ChangePath(m_results->m_fileData[index].entry.name);
if (path.IsEmpty())
continue;
bool replaced = false;
std::list<CServerPath>::iterator iter = selected_dirs.begin();
std::list<CServerPath>::iterator prev;
// Make sure that selected_dirs does not contain
// any directories that are in a parent-child relationship
// Resolve by only keeping topmost parents
while (iter != selected_dirs.end())
{
if (*iter == path)
{
replaced = true;
break;
}
if (iter->IsParentOf(path, false))
{
replaced = true;
break;
}
if (iter->IsSubdirOf(path, false))
{
if (!replaced)
{
*iter = path;
replaced = true;
}
else
{
prev = iter++;
selected_dirs.erase(prev);
continue;
}
}
++iter;
}
if (!replaced)
selected_dirs.push_back(path);
}
else
selected_files.push_back(index);
}
// Now in a second phase filter out all files that are also in a directory
std::list<int> selected_files_new;
for (std::list<int>::const_iterator iter = selected_files.begin(); iter != selected_files.end(); ++iter)
{
CServerPath path = m_results->m_fileData[*iter].path;
std::list<CServerPath>::const_iterator path_iter;
for (path_iter = selected_dirs.begin(); path_iter != selected_dirs.end(); ++path_iter)
{
if (*path_iter == path || path_iter->IsParentOf(path, false))
break;
}
if (path_iter == selected_dirs.end())
selected_files_new.push_back(*iter);
}
selected_files.swap(selected_files_new);
// At this point selected_dirs contains uncomparable
// paths and selected_files contains only files not
// covered by any of those directories.
}