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


C++ map::emplace方法代码示例

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


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

示例1: WillPathsCross

bool CrossingPaths::WillPathsCross(std::map<std::pair<int, int>, int>& pathMap, std::pair<int, int>& position, int changeX, int changeY)
{
	bool hasCrossed = false;
	bool isNegative = false;
	if (changeX != 0)
	{
		isNegative = changeX < 0;
		for (int i = 0; i < std::abs(changeX); i++)
		{
			position.first += isNegative ? -1 : 1;

			if (!hasCrossed)
			{
				hasCrossed = IsNodeInMap(pathMap, position);
			}
			pathMap.emplace(position, 1);
		}
	}

	else 
	{
		isNegative = changeY < 0;
		for (int i = 0; i < std::abs(changeY); i++)
		{
			position.second += isNegative ? -1 : 1;
			if (!hasCrossed)
			{
				hasCrossed = IsNodeInMap(pathMap, position);
			}
			pathMap.emplace(position, 1);
		}
	}

	return hasCrossed;
}
开发者ID:stshort,项目名称:CPPRandoms,代码行数:35,代码来源:CrossingPaths.cpp

示例2:

void
init_filters()
{
    filters.emplace("comb", std::make_unique<comb>());
    filters.emplace("echo", std::make_unique<echo>());
    filters.emplace("biquad", std::make_unique<biqd>());
}
开发者ID:biotty,项目名称:rmg,代码行数:7,代码来源:lib.cpp

示例3: emplaceString

static void emplaceString(std::map<std::string, Kdbx::XorredBuffer>& strings, const char* name, const QByteArray& data, bool protect, QWidget* widget){
	if (protect){
		std::vector<uint8_t> mask = getRandomBytes(data.size(), widget);
		strings.emplace(name, Kdbx::XorredBuffer::fromRaw(data.begin(), data.end(), mask.begin()));
	}else{
		strings.emplace(name, Kdbx::XorredBuffer(data.begin(), data.end()));
	}
}
开发者ID:j-kubik,项目名称:qtpass2,代码行数:8,代码来源:versioneditor.cpp

示例4:

static void
addRangeToDetails(std::map<std::string, std::string> &a, const char *minKey,
                  const char *maxKey,
                  const std::pair<uint16_t, uint16_t> &range)
{
    a.emplace(minKey, ring::to_string(range.first));
    a.emplace(maxKey, ring::to_string(range.second));
}
开发者ID:savoirfairelinux,项目名称:ring-daemon,代码行数:8,代码来源:sipaccountbase.cpp

示例5: add_color_info

void add_color_info(const config& v, bool build_defaults)
{
	if(build_defaults) {
		default_colors.clear();
	}

	for(const config& teamC : v.child_range("color_range")) {
		const config::attribute_value* a1 = teamC.get("id"), *a2 = teamC.get("rgb");
		if(!a1 || !a2) {
			continue;
		}

		std::string id = *a1;
		std::vector<color_t> temp;

		for(const auto& s : utils::split(*a2)) {
			try {
				temp.push_back(color_t::from_hex_string(s));
			} catch(const std::invalid_argument&) {
				std::stringstream ss;
				ss << "can't parse color string:\n" << teamC.debug() << "\n";
				throw config::error(ss.str());
			}
		}

		team_rgb_range.emplace(id, color_range(temp));
		team_rgb_name.emplace(id, teamC["name"].t_str());

		LOG_NG << "registered color range '" << id << "': " << team_rgb_range[id].debug() << '\n';

		// Ggenerate palette of same name;
		std::vector<color_t> tp = palette(team_rgb_range[id]);
		if(!tp.empty()) {
			team_rgb_colors.emplace(id, tp);
		}

		if(build_defaults && teamC["default"].to_bool()) {
			default_colors.push_back(*a1);
		}
	}

	for(const config &cp : v.child_range("color_palette")) {
		for(const config::attribute& rgb : cp.attribute_range()) {
			std::vector<color_t> temp;
			for(const auto& s : utils::split(rgb.second)) {
				try {
					temp.push_back(color_t::from_hex_string(s));
				} catch(const std::invalid_argument&) {
					ERR_NG << "Invalid color in palette: " << s << std::endl;
				}
			}

			team_rgb_colors.emplace(rgb.first, temp);
			LOG_NG << "registered color palette: " << rgb.first << '\n';
		}
	}
}
开发者ID:GregoryLundberg,项目名称:wesnoth,代码行数:57,代码来源:game_config.cpp

示例6: createBankToWorkspaceMap

/** create a map of the workspaces corresponding to each bank
  * @param banks :: [input] list of bank IDs; must not be empty. must not have
 * duplicate entries.
  * @param workspaces :: [input] list of corresponding workspaces or empty
 * vector for default  MAY NEED TO BE size_t <int, size_t>
  * @param workspaceOfBank :: [output] map to indicate the workspace that a
 * bank's parameters will be put in
  */
void LoadFullprofResolution::createBankToWorkspaceMap(
    const std::vector<int> &banks, const std::vector<int> &workspaces,
    std::map<int, size_t> &workspaceOfBank) {
  if (workspaces.size() == 0) {
    for (size_t i = 0; i < banks.size(); i++) {
      workspaceOfBank.emplace(banks[i], i + 1);
    }
  } else {
    for (size_t i = 0; i < banks.size(); i++) {
      workspaceOfBank.emplace(banks[i], workspaces[i]);
    }
  }
}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:21,代码来源:LoadFullprofResolution.cpp

示例7: getTextura

unsigned int getTextura(const char *path) {
	auto it = texturas.find(path);
	if(it != texturas.end())
		return it->second;
	else {
		GLuint textureID;
		unsigned int t[2], tw, th;
		unsigned char *texData;
		ilGenImages(2,t);
		ilBindImage(t[0]);
		ilLoadImage((ILstring)path);
		tw = ilGetInteger(IL_IMAGE_WIDTH);
		th = ilGetInteger(IL_IMAGE_HEIGHT);
		ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
		texData = ilGetData();
	
		glGenTextures(1,&textureID); // unsigned int texID  - variavel global;
	
		glBindTexture(GL_TEXTURE_2D,textureID);
		glTexParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_S,		GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D,	GL_TEXTURE_WRAP_T,		GL_REPEAT);

		glTexParameteri(GL_TEXTURE_2D,	GL_TEXTURE_MAG_FILTER,   	GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,	GL_TEXTURE_MIN_FILTER,    	GL_LINEAR);
		
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);

		texturas.emplace(path, textureID);
		return textureID;
	}
}
开发者ID:TiagoPinto,项目名称:Bar,代码行数:31,代码来源:texturas.cpp

示例8: pre_generation

 void pre_generation(std::array<TERRAIN_FEATURES, 6> & ambient_relief)
 {
     std::random_device rd;
     std::mt19937 gen(rd());
     std::vector<std::pair<TERRAIN_FEATURES, int>> features_and_frequencies = {std::make_pair(TERRAIN_FEATURES::WATER, 1)};
     for (size_t i = 0; i < 6; i++)
     {
         auto it = find_if(features_and_frequencies.begin(), features_and_frequencies.end(),
                         [&ambient_relief, i](std::pair<TERRAIN_FEATURES, int> & p){return p.first == ambient_relief[i];});
         if(it == features_and_frequencies.end())
             features_and_frequencies.push_back(std::make_pair(ambient_relief[i], 1));
         else
             it->second++;
     }
     std::vector<int> frequencies;
     for (size_t i = 0; i < features_and_frequencies.size(); i++)
         frequencies.push_back(features_and_frequencies[i].second);
     std::discrete_distribution<> d(frequencies.begin(), frequencies.end());
     for (int i = -SIDE_SIZE + 1; i < SIDE_SIZE; i++)
     {
         for (int j = -SIDE_SIZE + 1; j < SIDE_SIZE; j++)
         {
             for (int k = -SIDE_SIZE + 1; k < SIDE_SIZE; k++)
             {
                 if (i + j + k != 0)
                     continue;
                 TERRAIN_FEATURES feature = features_and_frequencies[d(gen)].first;
                 std::array<grid_tile *, 6> neighbours =
                         {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
                 battleground.emplace(std::make_tuple(i, j, k), grid_tile(neighbours, i, j, k, nullptr, feature));
                 //battleground[14*i + j] = grid_tile(neighbours, i, j, nullptr, feature);
             }
         }
     }
 }
开发者ID:koshinus,项目名称:CPP_programs,代码行数:35,代码来源:tactical_grid.hpp

示例9: fillUnitMap

/** Fills the unit map and ordered vector with the same data
  * @param orderedVector the vector to fill
  * @param unitMap the map to fill
  * @param caption the caption of the unit
  * @param unit the unit of measure of the unit
  */
void ConvertAxesToRealSpace::fillUnitMap(
    std::vector<std::string> &orderedVector,
    std::map<std::string, std::string> &unitMap, const std::string &caption,
    const std::string &unit) {
  unitMap.emplace(caption, unit);
  orderedVector.push_back(caption);
}
开发者ID:mducle,项目名称:mantid,代码行数:13,代码来源:ConvertAxesToRealSpace.cpp

示例10: FinishRead

static void FinishRead(u64 id, s64 cycles_late)
{
  // We can't simply pop s_result_queue and always get the ReadResult
  // we want, because the DVD thread may add ReadResults to the queue
  // in a different order than we want to get them. What we do instead
  // is to pop the queue until we find the ReadResult we want (the one
  // whose ID matches userdata), which means we may end up popping
  // ReadResults that we don't want. We can't add those unwanted results
  // back to the queue, because the queue can only have one writer.
  // Instead, we add them to a map that only is used by the CPU thread.
  // When this function is called again later, it will check the map for
  // the wanted ReadResult before it starts searching through the queue.
  ReadResult result;
  auto it = s_result_map.find(id);
  if (it != s_result_map.end())
  {
    result = std::move(it->second);
    s_result_map.erase(it);
  }
  else
  {
    while (true)
    {
      while (!s_result_queue.Pop(result))
        s_result_queue_expanded.Wait();

      if (result.first.id == id)
        break;
      else
        s_result_map.emplace(result.first.id, std::move(result));
    }
  }
  // We have now obtained the right ReadResult.

  const ReadRequest& request = result.first;
  const std::vector<u8>& buffer = result.second;

  DEBUG_LOG(DVDINTERFACE, "Disc has been read. Real time: %" PRIu64 " us. "
                          "Real time including delay: %" PRIu64 " us. "
                          "Emulated time including delay: %" PRIu64 " us.",
            request.realtime_done_us - request.realtime_started_us,
            Common::Timer::GetTimeUs() - request.realtime_started_us,
            (CoreTiming::GetTicks() - request.time_started_ticks) /
                (SystemTimers::GetTicksPerSecond() / 1000000));

  if (buffer.size() != request.length)
  {
    PanicAlertT("The disc could not be read (at 0x%" PRIx64 " - 0x%" PRIx64 ").",
                request.dvd_offset, request.dvd_offset + request.length);
  }
  else
  {
    if (request.copy_to_ram)
      Memory::CopyToEmu(request.output_address, buffer.data(), request.length);
  }

  // Notify the emulated software that the command has been executed
  DVDInterface::FinishExecutingCommand(request.reply_type, DVDInterface::INT_TCINT, cycles_late,
                                       buffer);
}
开发者ID:marissa2249,项目名称:dolphin,代码行数:60,代码来源:DVDThread.cpp

示例11: assert

std::pair<MatVec*, bool>
SimpleMatrixVectorProvider::
get_(std::size_t& id,
     std::map<std::size_t, MatVec*>& unused_map,
     std::map<MatVec*, std::size_t>& used_map,
     Args&&... args)
{
    if (id >= _next_id) {
        OGS_FATAL("An obviously uninitialized id argument has been passed."
            " This might not be a serious error for the current implementation,"
            " but it might become one in the future."
            " Hence, I will abort now.");
    }

    if (do_search)
    {
        auto it = unused_map.find(id);
        if (it != unused_map.end()) // unused matrix/vector found
            return { ::detail::transfer(unused_map, used_map, it), false };
    }

    // not searched or not found, so create a new one
    id = _next_id++;
    auto res = used_map.emplace(
        MathLib::MatrixVectorTraits<MatVec>::newInstance(std::forward<Args>(args)...).release(),
        id);
    assert(res.second && "Emplacement failed.");
    return { res.first->first, true };
}
开发者ID:wenqing,项目名称:ogs,代码行数:29,代码来源:SimpleMatrixVectorProvider.cpp

示例12: flood_name

// "flood fill" a tile name to adjacent tiles of certain terrain
static void flood_name(const map_location& start, const std::string& name, std::map<map_location,std::string>& tile_names,
	const t_translation::ter_match& tile_types, const terrain_map& terrain,
	unsigned width, unsigned height,
	size_t label_count, std::map<map_location,std::string>* labels, const std::string& full_name) {
	map_location adj[6];
	get_adjacent_tiles(start,adj);
	size_t n;
	//if adjacent tiles are tiles and unnamed, name them
	for(n = 0; n < 6; n++) {
		//we do not care for tiles outside the middle part
		//cast to unsigned to skip x < 0 || y < 0 as well.
		if(unsigned(adj[n].x) >= width / 3 || unsigned(adj[n].y) >= height / 3) {
			continue;
		}

		const t_translation::terrain_code terr = terrain[adj[n].x + (width / 3)][adj[n].y + (height / 3)];
		const map_location loc(adj[n].x, adj[n].y);
		if((t_translation::terrain_matches(terr, tile_types)) && (tile_names.find(loc) == tile_names.end())) {
			tile_names.emplace(loc, name);
			//labeling decision: this is result of trial and error on what looks best in game
			if(label_count % 6 == 0) { //ensure that labels do not occur more often than every 6 recursions
				labels->emplace(loc, full_name);
				label_count++; //ensure that no adjacent tiles get labeled
			}
			flood_name(adj[n], name, tile_names, tile_types, terrain, width, height, label_count++, labels, full_name);
		}
	}
}
开发者ID:fluffbeast,项目名称:wesnoth-old,代码行数:29,代码来源:default_map_generator_job.cpp

示例13: LockDirectory

bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only)
{
    std::lock_guard<std::mutex> ulock(cs_dir_locks);
    fs::path pathLockFile = directory / lockfile_name;

    // If a lock for this directory already exists in the map, don't try to re-lock it
    if (dir_locks.count(pathLockFile.string())) {
        return true;
    }

    // Create empty lock file if it doesn't exist.
    FILE* file = fsbridge::fopen(pathLockFile, "a");
    if (file) fclose(file);

    try {
        auto lock = MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str());
        if (!lock->try_lock()) {
            return false;
        }
        if (!probe_only) {
            // Lock successful and we're not just probing, put it into the map
            dir_locks.emplace(pathLockFile.string(), std::move(lock));
        }
    } catch (const boost::interprocess::interprocess_exception& e) {
        return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());
    }
    return true;
}
开发者ID:hungud,项目名称:bitcoin,代码行数:28,代码来源:util.cpp

示例14: argp_register

void cy::argp_register(const std::string& cmd, int32_t uid, argp_cmd_type cmd_type, argp_param_type param_type)
{
	// check arguments
	if(cmd.empty())
		throw std::runtime_error("no command given");
	if(cmd_type == ARGP_CT_SINGLE && cmd.size() != 1)
		throw std::runtime_error("command of type 'single' cannot contain multiple characters");

	// check for uid uniqueness
	if(g_cmd_registry.find(uid) != g_cmd_registry::end)
		throw std::runtime_error("given uid not unique");
	if(uid_is_reserved(uid))
		throw std::runtime_error("given uid is reserved!");
	
	// check for command uniqueness
	for(std::map<int32_t, cy::argp_arg_extra_info>::iterator it = g_cmd_registry.begin(); it != g_cmd_registry.end(); it++)
	{
		if(cmd == it->second.cmd && cmd_type == it->second.cmd_type)
			throw std::runtime_error("equivalent command already registered");
	}

	// construct the info struct
	cy::argp_arg_extra_info aaei = make_info_struct(cmd, cmd_type, param_type);

	// put in registry
	g_cmd_registry.emplace(uid, aaei);
}
开发者ID:cyangekko,项目名称:cy_argp,代码行数:27,代码来源:cy_argp.cpp

示例15: map_insert

void map_insert(std::map<RK,RV>& m, PK&& k, PV&& v) 
{
    static_assert(std::is_same<RK,typename std::decay<PK>::type>::value, "implicit conversions disallowed for the key!");
    m.emplace(std::piecewise_construct,
        std::forward_as_tuple(std::forward<PK>(k)),
        std::forward_as_tuple(std::forward<PV>(v)));
}
开发者ID:CCJY,项目名称:coliru,代码行数:7,代码来源:main.cpp


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