当前位置: 首页>>代码示例>>C++>>正文


C++ list::insert方法代码示例

本文整理汇总了C++中std::list::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ list::insert方法的具体用法?C++ list::insert怎么用?C++ list::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::list的用法示例。


在下文中一共展示了list::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: packIntoPlace

Rect packIntoPlace(std::list<Vec2>& Skyline, const Vec2& r, std::list<Vec2>::iterator place) {
	float x = 0;
	auto width = r.width();
	//Initialize x
	auto first = Skyline.begin();
	auto last = Skyline.end();
	while (first != last && first != place) {
		x += first->width();
		first++;
	}

	auto newHeight = place->height() + r.height();
	auto rectangle = newRect(Vec2(x, place->height()), r);

	while (place != last && width > 0) {
		if (width >= place->width()) {
			auto newPlace = Skyline.insert(std::next(place), Vec2(place->width(), newHeight));
			Skyline.erase(place);
			place = newPlace;
			width -= place->width();
		}
		else { //need to split skyline
			Skyline.insert(place, Vec2(width, newHeight));
			auto newPlace1 = Skyline.insert(std::next(place), Vec2(place->width() - width, place->height()));
			Skyline.erase(place);
			place = newPlace1;
			width = 0;
		}
		place++;
	}

	return rectangle;
}
开发者ID:danskcarvalho,项目名称:ColorNShapes,代码行数:33,代码来源:Skyline.cpp

示例2: getSourcesAndHeaders

static void getSourcesAndHeaders(const std::list<std::string> &paths,
								std::list<std::string> &headers,
								std::list<std::string> &sources)
{
	std::list<std::string> exts;
	std::list<std::string> aux;


	std::cout << "Obteniendo Headers\n";

	exts.push_back(".h");
	headers.clear();
	for(std::list<std::string>::const_iterator it = paths.begin(); it != paths.end(); ++it){
		assert(FileManager::getInstance()->getAllFiles(*it, aux, exts));

		headers.insert(headers.begin(), aux.begin(), aux.end());
	}


	std::cout << "Obteniendo Sources\n";

	exts.clear();
	aux.clear();
	exts.push_back(".cpp");
	sources.clear();
	for(std::list<std::string>::const_iterator it = paths.begin(); it != paths.end(); ++it){
		assert(FileManager::getInstance()->getAllFiles(*it, aux, exts));

		sources.insert(sources.begin(), aux.begin(), aux.end());
	}

}
开发者ID:agudpp,项目名称:CordobaZombie,代码行数:32,代码来源:autogenCmake.cpp

示例3: draw_previous_suggestions

void draw_previous_suggestions(std::vector<std::string> words, bool contextChange,
			       const int starty, int startx)
{
    static std::list< std::vector<std::string> > previousSuggestions;
    static std::vector< WINDOW* > windows;

    // clear out existing windows
    for (std::vector< WINDOW* >::iterator winit = windows.begin();
         winit != windows.end();
         winit++) {
        wclear(*winit);
        wrefresh(*winit);
        delwin(*winit);
    }
    windows.clear();

    if (contextChange) {
	// insert a context change marker in the list of previous
	// suggestions
	// 
	std::vector< std::string > marker;
	for (int i = 0; i < atoi(suggestions.c_str()); i++) {
	    marker.push_back("|");
	}
	previousSuggestions.insert(previousSuggestions.begin(), marker);
    }

    previousSuggestions.insert(previousSuggestions.begin(), words);

    for (std::list< std::vector<std::string> >::const_iterator listit = previousSuggestions.begin();
	 (listit != previousSuggestions.end() && startx < COLS); // don't draw window off the screen
	 listit++) {

	int height = listit->size() + 2;
	int width = getGreatestSuggestionLength(*listit) + 2;

	WINDOW* win = newwin(height, width, starty, startx);
	wclear(win);
	box(win, 0, 0);

	int line = 1;
	for (std::vector<std::string>::const_iterator strit = listit->begin();
	     strit != listit->end();
	     strit++) {
	    
	    mvwprintw(win, line, 1, strit->c_str());
	    line++;
	}

	wrefresh(win);
        windows.push_back(win);
	startx += width + 2;
    }
}
开发者ID:sukki89,项目名称:Word-Prediction,代码行数:54,代码来源:presageDemo.cpp

示例4: fig_make_comp

// заключить fig-объекты в составной объект.
void fig_make_comp(std::list<fig_object> & objects){
  if ((objects.size()<1) || (objects.begin()->size()<1)) return;
  iRect r = fig_range(objects);

  fig_object o;
  o.type=6;
  o.push_back(r.TLC());
  o.push_back(r.BRC());
  objects.insert(objects.begin(), o);
  o.type = -6;
  objects.insert(objects.end(), o);
}
开发者ID:ushakov,项目名称:mapsoft,代码行数:13,代码来源:fig_utils.cpp

示例5: insert

 void insert(OnlineFileRequest* request) {
     if (request->resource.priority == Resource::Priority::Regular) {
         firstLowPriorityRequest = queue.insert(firstLowPriorityRequest, request);
         firstLowPriorityRequest++;
     }
     else {
         if (firstLowPriorityRequest == queue.end()) {
             firstLowPriorityRequest = queue.insert(queue.end(), request);
         }
         else {
             queue.insert(queue.end(), request);
         }
     }
 }
开发者ID:jingsam,项目名称:mapbox-gl-native,代码行数:14,代码来源:online_file_source.cpp

示例6: insertIntoList

void VoronoiSeedsGenerator::insertIntoList(std::list<Seed>& list, Seed& seed)
{
    /*
     * If the list is empty, just pushing back the new seed.
     * Otherwise, we have to determine the position to insert the seed to.
     *  In order to do so, we simply iterate over the seeds, comparing the
     *  distance to center of the one to insert with the latter's ones.
     *  The last comparison needs extra care, since we may have to push
     *  back the seed to insert if its distance to center is greater than
     *  the one of the list's last seed.
     */
    if (list.empty()) {
        list.push_back(seed);
    } else {
        auto current = list.begin();
        auto last = list.end();
        float distance = DIST_TO_CENTER(seed);
        while ((current != last) && (distance > DIST_TO_CENTER(*current))) {
            current++;   
        }
		if (current != last) {
			list.insert(current, seed);
		} else {
			list.push_back(seed);
        }
    }
}
开发者ID:Shutter-Island-Team,项目名称:Shutter-island,代码行数:27,代码来源:VoronoiSeedsGenerator.cpp

示例7: add_open

	/*
	 * Adds the given item to the cache and opens it.
	 * Returns the key.
	 */
	LRUKey add_open(T *data_ptr) {
		std::unique_lock<SpinLock> lock(slock);

		typename std::list<LRUPair<T>>::iterator it;
		LRUPair<T> data_pair;

		LRUKey key;
		do {
			key = next_key++;
		} while ((bool)(map.count(key)) || key == 0);

		byte_count += data_ptr->bytes();

		// Remove last element(s) if necessary to make room
		while (byte_count >= max_bytes) {
			if (!erase_last())
				break;
		}

		// Add the new data
		data_pair.key = key;
		data_pair.data_ptr = data_ptr;
		data_pair.active_readers = 1;
		it = elements.begin();
		it = elements.insert(it, data_pair);

		// Log it in the map
		map[key] = it;

		return key;
	}
开发者ID:bagobor,项目名称:psychopath,代码行数:35,代码来源:lru_cache.hpp

示例8: 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();
  }
}
开发者ID:vcbradley,项目名称:appopt,代码行数:32,代码来源:appopt_block.cpp

示例9: addToList

void addToList( container &c ) {
	c.time = c.fixed_time;
	c.time += time_passed;
	if( time_passed > c.time ) {
		// reset time_passed
		for( auto &e : time_list ) {
			e.time -= time_passed;
		}
		time_passed = 0;
	}

	if( time_list.size() > 0 ) {
		// find place to insert
		bool found = false;
		for( auto it = time_list.begin(); it != time_list.end(); it++ ) {
			if( it->time > c.time ) {
				time_list.insert( it, c );
				found = true;
				break;
			}
		}
		if( !found )
			time_list.push_back( c );
	} else {
		time_list.push_front( c );
	}
}
开发者ID:MrJookie,项目名称:Galaxy31,代码行数:27,代码来源:Timer.cpp

示例10: reorderList

    static void reorderList(GraphNodeIndex id_suc, DistanceType newdist,
                            std::list<std::pair<GraphNodeIndex, DistanceType>>& nodeSet) {
        typedef std::pair<GraphNodeIndex, DistanceType> DijkstraElement;
        typename std::list<DijkstraElement>::iterator it;

        // Searching for the node "id_suc" in the list
        for (it = nodeSet.begin(); it != nodeSet.end(); it++) {
            if (it->first == id_suc) {
                break;
            }
        }

        // 'it' is in the right place...
        if (it != nodeSet.end()) {
            nodeSet.erase(it);
        }

        // Searching for the new position of "id_suc"
        for (it = nodeSet.begin(); (it != nodeSet.end()) && (it->second < newdist);
                it++) {
            // do nothing
        }

        nodeSet.insert(it, DijkstraElement(id_suc, newdist));
    }
开发者ID:Celeborn2BeAlive,项目名称:pg2015-code,代码行数:25,代码来源:DijkstraAlgorithm.hpp

示例11: create_model

CVdMdlIfs* CNotFactory::create_model( char* name, char* in_cir_name )
{
  std::list<CNot*>::iterator inot_mdl;

  if( strcmp( pNotModelName, name )!= 0 )
  {
    // TODO: Error message - unsupported model
    return 0;
  }

  for( inot_mdl=not_mdls.begin(); 
    inot_mdl!=not_mdls.end(); inot_mdl++ )
  {
    if((*inot_mdl)->name.compare( in_cir_name )== 0 )
    {
      // TODO: Error msg - Already exists
      return 0;
    }
  }

  CNot* pNot  = 0;
  pNot        = new CNot();
  pNot->name  = in_cir_name;
  pNot->msgI  = pMsgI;

  msg_info( "Subckt[%p] Model[%s] was created", 
    pNot, name );

  not_mdls.insert( not_mdls.end(), pNot );

  return pNot;
}
开发者ID:ruarka,项目名称:vpcb,代码行数:32,代码来源:not.cpp

示例12: sleep

void sleep(uint32 seconds) {
	IBMRAS_DEBUG(fine,"in thread.cpp->sleep");
	/* each sleep has its own mutex and condvar - the condvar will either
		be triggered by condBroadcast or it will timeout.*/
	pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
	pthread_cond_t c = PTHREAD_COND_INITIALIZER;

	IBMRAS_DEBUG(debug,"Updating condvar map");
	// lock the condvar map for update
	pthread_mutex_lock(&condMapMux);
	std::list<pthread_cond_t>::iterator it = condMap.insert(condMap.end(),c);
	pthread_mutex_unlock(&condMapMux);
	pthread_mutex_lock(&m);

	struct timespec t;
	clock_gettime(CLOCK_REALTIME, &t);
	t.tv_sec += seconds;		/* configure the sleep interval */
	IBMRAS_DEBUG_1(finest,"Sleeping for %d seconds", seconds);
	pthread_cond_timedwait(&c, &m, &t);
	IBMRAS_DEBUG(finest,"Woke up");
	pthread_mutex_unlock(&m);
	
	pthread_mutex_lock(&condMapMux);
	condMap.erase(it);
	pthread_mutex_unlock(&condMapMux);
}
开发者ID:RuntimeTools,项目名称:omr-agentcore,代码行数:26,代码来源:Thread.cpp

示例13:

void                   ModuleManager::getSortedList(zAPI::IModule::Hook hook, zAPI::IModule::Event event,
                                                    std::list<zAPI::IModuleInfo*>& nList)
{
    std::list<RefCounter<zAPI::IModuleInfo*>*>::iterator  it = this->_modules.back().ptr.hooks[hook].begin();
    std::list<RefCounter<zAPI::IModuleInfo*>*>::iterator  ite = this->_modules.back().ptr.hooks[hook].end();
    for (; it != ite; ++it)
    {
        int prio = (*it)->ptr->getInstance()->getPriority(event);
        std::list<zAPI::IModuleInfo*>::iterator  nIt = nList.begin();
        std::list<zAPI::IModuleInfo*>::iterator  nIte = nList.end();
        bool    inserted = false;

        if (nIt == nIte)
            nList.push_back((*it)->ptr);
        else
        {
            for (; nIt != nIte; ++nIt)
            {
                int nPrio = (*nIt)->getInstance()->getPriority(event);
                if (prio < nPrio)
                {
                    nList.insert(nIt, (*it)->ptr);
                    inserted = true;
                    break;
                }
            }
            if (!inserted)
                nList.push_back((*it)->ptr);
        }
    }
}
开发者ID:kri5,项目名称:zia,代码行数:31,代码来源:ModuleManager.cpp

示例14: makeText

//Вспомогательная функция формирования текста статьи из Gumbo-дерева
void makeText(GumboNode *a_entry, std::list<std::u32string> &a_lines)
{
	assert(a_entry != nullptr);
	std::list<std::u32string> l_lines;
	Utility::Gumbo::traverse(a_entry, [&](GumboNode *a)->bool
	{
		if (a->type == GUMBO_NODE_ELEMENT && (a->v.element.tag == GUMBO_TAG_P ||
			a->v.element.tag == GUMBO_TAG_H1 || a->v.element.tag == GUMBO_TAG_H2 ||
			a->v.element.tag == GUMBO_TAG_H3 || a->v.element.tag == GUMBO_TAG_H4))
		{
			l_lines.push_back(std::u32string());
			l_lines.push_back(std::u32string());
		}
		if (a->type != GUMBO_NODE_TEXT)
			return false;
		if (a->parent->v.element.tag != GUMBO_TAG_SCRIPT &&
			a->parent->v.element.tag != GUMBO_TAG_STYLE && a->parent->v.element.tag != GUMBO_TAG_TEXTAREA)
		{
			const std::u32string l_utf32text(Encoding::utf8to32(a->v.text.text));
			Text::format(l_lines, l_utf32text, 80);
		}
		if (a->parent->v.element.tag == GUMBO_TAG_A &&
			a->index_within_parent + 1 == a->parent->v.element.children.length)
		{
			GumboAttribute *const l_href = ::gumbo_get_attribute(&a->parent->v.element.attributes, "href");
			if (l_href != nullptr)
			{
				const std::string l_asText(std::string(" [") + l_href->value + "]");
				Text::format(l_lines, Encoding::utf8to32(l_asText), 80);
			}
		}
		return false;
	});
	a_lines.insert(a_lines.end(), l_lines.begin(), l_lines.end());
}
开发者ID:rasim-valiullin,项目名称:d512388b-9b91-45f9-8f88-b6d4e252c270,代码行数:36,代码来源:miniread.cpp

示例15:

boost::shared_ptr<Shape> CompOperator::apply(boost::shared_ptr<Shape>& shape, const Grammar& grammar, std::list<boost::shared_ptr<Shape> >& stack) {
	std::vector<boost::shared_ptr<Shape> > shapes;
	
	shape->comp(name_map, shapes);
	stack.insert(stack.end(), shapes.begin(), shapes.end());

	return boost::shared_ptr<Shape>();
}
开发者ID:gnishida,项目名称:SketchBuilding,代码行数:8,代码来源:CompOperator.cpp


注:本文中的std::list::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。