本文整理汇总了C++中map::emplace方法的典型用法代码示例。如果您正苦于以下问题:C++ map::emplace方法的具体用法?C++ map::emplace怎么用?C++ map::emplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::emplace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
void set(int key, int value)
{
++op_count;
if (map_kv.find(key) == map_kv.end())
// insert new key
{
if (map_kv.size() == capacity)
{
map<int, int>::iterator it = map_tk.begin();
int k = it->second;
map_tk.erase(map_tk.begin());
map_kt.erase(map_kt.find(k));
map_kv.erase(map_kv.find(k));
}
map_kv.emplace(key, value);
map_tk.emplace(op_count, key);
map_kt.emplace(key, op_count);
}
else
{
int old_time = map_kt[key];
map_tk.erase(map_tk.find(old_time));
map_tk.emplace(op_count, key);
map_kt[key] = op_count;
map_kv[key] = value;
}
}
示例2: scanBanks
/** Scan lines for bank IDs
* @param lines :: vector of string of all non-empty lines in input file;
* @param useFileBankIDs :: use bank IDs as given in file rather than ordinal
* number of bank
* @param banks :: [output] vector of integers for existing banks in .irf file;
* @param bankstartindexmap :: [output] map to indicate the first line of each
* bank in vector lines.
* @param bankendindexmap :: [output] map to indicate the last line of each
* bank in vector lines
*/
void LoadFullprofResolution::scanBanks(const vector<string> &lines,
const bool useFileBankIDs,
vector<int> &banks,
map<int, int> &bankstartindexmap,
map<int, int> &bankendindexmap) {
int startindex = -1;
int endindex = -1;
int bankid = 0;
for (size_t i = 0; i < lines.size(); ++i) {
string line = lines[i];
if (line.find("Bank") != string::npos) {
// A new line found
if (startindex >= 0) {
// Previous line is in a bank range. Then finish the previous bank
// range
endindex = static_cast<int>(i) - 1;
bankstartindexmap.emplace(banks.back(), startindex);
bankendindexmap.emplace(banks.back(), endindex);
}
// Start the new pair
startindex = static_cast<int>(i);
endindex = -1;
// Get bank ID
if (useFileBankIDs) { // Get bank ID from line
vector<string> level1s;
boost::split(level1s, line, boost::is_any_of("Bank"));
vector<string> level2s;
string bankterm = level1s.back();
boost::algorithm::trim(bankterm);
boost::split(level2s, bankterm, boost::is_any_of(" "));
bankid = atoi(level2s[0].c_str());
} else { // Get bank ID as ordinal number of bank
bankid++;
}
banks.push_back(bankid);
}
}
if (startindex >= 0) {
endindex = static_cast<int>(lines.size()) - 1;
bankstartindexmap.emplace(banks.back(), startindex);
bankendindexmap.emplace(banks.back(), endindex);
}
g_log.debug() << "[DB1112] Number of bank IDs = " << banks.size() << ", "
<< "Number of ranges = " << bankstartindexmap.size() << endl;
for (auto &bank : banks) {
g_log.debug() << "Bank " << bank << " From line " << bankstartindexmap[bank]
<< " to " << bankendindexmap[bank] << endl;
}
return;
}
示例3: init_stage_map
void init_stage_map(map<float, shared_ptr<Stage>> &stage_map) {
float acute_max = (float) Parameters::instance()->getDoubleParameter(ACUTE_RANGE_MAX_NUMERATOR);
float chronic_max = (float) Parameters::instance()->getDoubleParameter(CHRONIC_RANGE_MAX_NUMERATOR);
float late_max = (float) Parameters::instance()->getDoubleParameter(LATE_RANGE_MAX_NUMERATOR);
float acute_mult = (float) Parameters::instance()->getDoubleParameter(ACUTE_MULTIPLIER);
float late_mult = (float) Parameters::instance()->getDoubleParameter(LATE_MULTIPLIER);
float baseline_infectivity = (float) Parameters::instance()->getDoubleParameter(MIN_CHRONIC_INFECTIVITY_UNADJ);
stage_map.emplace(acute_max, make_shared<AcuteStage>(baseline_infectivity, acute_mult, Range<float>(1, acute_max)));
stage_map.emplace(chronic_max,
make_shared<ChronicStage>(baseline_infectivity, Range<float>(acute_max, chronic_max)));
stage_map.emplace(late_max,
make_shared<LateStage>(baseline_infectivity, late_mult, Range<float>(chronic_max, late_max)));
}
示例4: RegisterType
void RegisterType(string strKey, std::function<T* ()> creator)
{
if (m_creatorMap.find(strKey) != m_creatorMap.end())
throw std::invalid_argument("this key has already exist!");
m_creatorMap.emplace(strKey, creator);
}
示例5:
DoctypeFixture *addDocType(const std::string &name, bool isGlobal = false) {
DocumenttypesConfigBuilder::Documenttype dt;
dt.bodystruct = -1270491200;
dt.headerstruct = 306916075;
dt.id = idcounter--;
dt.name = name;
dt.version = 0;
documenttypesBuilder.documenttype.push_back(dt);
ProtonConfigBuilder::Documentdb db;
db.inputdoctypename = name;
db.configid = configId + "/" + name;
db.global = isGlobal;
protonBuilder.documentdb.push_back(db);
DoctypeFixture::UP fixture = std::make_unique<DoctypeFixture>();
set.addBuilder(db.configid, &fixture->attributesBuilder);
set.addBuilder(db.configid, &fixture->rankProfilesBuilder);
set.addBuilder(db.configid, &fixture->rankingConstantsBuilder);
set.addBuilder(db.configid, &fixture->indexschemaBuilder);
set.addBuilder(db.configid, &fixture->summaryBuilder);
set.addBuilder(db.configid, &fixture->summarymapBuilder);
set.addBuilder(db.configid, &fixture->juniperrcBuilder);
set.addBuilder(db.configid, &fixture->importedFieldsBuilder);
return dbConfig.emplace(std::make_pair(name, std::move(fixture))).first->second.get();
}
示例6: prime_compatibles
void hftable::prime_compatibles(const cpset& M, const map<cp,cpset>& C, map<int,cp>& P) {
cpset done;
bool prime = false;
int index = 1;
done.clear();
int max_size = 0;
for(auto& m : M)
if(m.size() > max_size)
max_size = m.size();
for(int k = max_size; k >= 1; --k) {
for(auto& m : M)
if(m.size() == k)
P.emplace(index++,m);
for(auto& p : P) {
if(p.second.size() == k) {
cpset cs;
cs.clear();
//check if class set is empty.
if(class_set(p.second, C).empty())
continue;
for(auto& s : max_subsets(p.second)) {
if(done.find(s) != done.end()) {
continue;
}
cs = class_set(s, C);
prime = true;
map<int,cp>::iterator it1;
for(it1 = P.begin(); it1 != P.end(); ++it1) {
if(it1->second.size() >= k) {
if(subset(it1->second,s)) {
cpset cq = class_set(it1->second, C);
if(subset(cs,cq)) {
prime = false;
break;
}
}
}
}
if(prime) {
P.emplace(index++,s);
done.emplace(s);
}
}
}
}
}
}
示例7: CreateCoverart
/// <summary>
/// Loads settings.
/// </summary>
void CreateCoverart(LPCTSTR name) {
if (gCoverArt.find(name) == gCoverArt.end()) {
gCoverArt.emplace(std::piecewise_construct, std::forward_as_tuple(name),
std::forward_as_tuple(name));
} else {
ErrorHandler::Error(ErrorHandler::Level::Critical,
L"Attempt to (re)create the already existing CoverArt %s!", name);
}
}
示例8: storeHintToMask
// store the map from grid point offset to mask used in phase correlation peak finding
static void storeHintToMask(map<GridPtOff, Mat> &hintToMask, const Size &imSz, const Point2f &absHint, const MaxDists &dists) {
for (int xOff = -1; xOff <= 1; xOff++) {
for (int yOff = -1; yOff <= 1; yOff++) {
if (!xOff && !yOff) {
continue;
}
int maxDist;
if (xOff) {
if (yOff) {
maxDist = dists.xy;
} else {
maxDist = dists.x;
}
} else {
maxDist = dists.y;
}
Mat mask = Mat::zeros(Size(imSz.width + 2, imSz.height), CV_8UC1);
Point baseXY(fround(absHint.x * xOff), fround(absHint.y * yOff));
if (baseXY.x > imSz.width) {
baseXY.x -= imSz.width;
} else if (baseXY.x < 0) {
baseXY.x += imSz.width;
}
if (baseXY.y > imSz.height) {
baseXY.y -= imSz.height;
} else if (baseXY.y < 0) {
baseXY.y += imSz.height;
}
if (xOff) {
if (yOff) {
circle(mask, baseXY, maxDist, Scalar(255, 255, 255, 255), -1);
} else {
for (int y = baseXY.y - imSz.height; y <= baseXY.y + imSz.height; y += imSz.height) {
circle(mask, Point(baseXY.x, y), maxDist, Scalar(255, 255, 255, 255), -1);
}
}
} else {
for (int x = baseXY.x - imSz.width; x <= baseXY.x + imSz.width; x += imSz.width) {
circle(mask, Point(x, baseXY.y), maxDist, Scalar(255, 255, 255, 255), -1);
}
}
// Mat tmp;
// resize(mask, tmp, Size(), 0.4, 0.4);
// imshow("m", tmp);
// waitKey(0);
hintToMask.emplace(makeOff(xOff, yOff), mask);
}
}
}
示例9: parseAttributes
/** Parses a sequence of key-value pairs of the form KEY=VALUE or KEY="VALUE".
* If parameter 'requireValues' is false, attributes may also consist of a key only.
* @param[out] attr the scanned atributes
* @param[in] requireValues true if all attributes require a value
* @param[in] quotechars recognized quote characters used to enclose the attribute values
* @return number of attributes scanned */
int InputReader::parseAttributes (map<string,string> &attr, bool requireValues, const char *quotechars) {
while (!eof()) {
string key;
skipSpace();
if (!isalpha(peek())) // first character of attribute name must be a letter
break;
key += char(get());
while (isalnum(peek()) || strchr("-:._", peek()))
key += char(get());
skipSpace();
if (peek() == '=') {
get();
skipSpace();
string val = getQuotedString(quotechars);
attr.emplace(std::move(key), std::move(val));
}
else if (!requireValues)
attr.emplace(std::move(key), "");
}
return attr.size();
}
示例10: mount
//************************************************************************************************
//*** mount()
//*** Called by Scilab's slMount()
//***
//************************************************************************************************
DLLIMPORT void mount ( int *handle, int *OK )
{
*OK = 0;
// In the past, the <handle>, given by the Scilab call, created exactly this handle and
// returned 1 to <OK> if everything went fine (0 otherwise).
// Now, we return either 0, on failure or the number of the handle created or
// any number >0, representing the handle itself.
// Notice that there is _no_ (practical) limit to the amount of handles serial interface
// classes ano more. The code limit is set to 32000 8-)
// New behaviour, 4/2014: find next free number (the hard way, for now ;-) and
// return it as the new handle.
// For compatibility, we first check if the requested handle number (if any)
// is available...
if( ( *handle != 0 ) && ( mPort.find( *handle ) == mPort.end() ) )
{
// compatibility mode; check if requested handle is available
mPort.emplace( *handle, new asSerial() );
*OK = *handle;
}
else
{
// find first, free handle number >0
// I guess, 32000 interfaces are sufficient ;-)
for( int i=1; i<32000; ++i )
{
if( mPort.find( i ) == mPort.end() )
{
mPort.emplace( i, new asSerial() );
*OK = i;
break;
}
}// END for all possible handles
}//END else
}// END DLLIMPORT void mount
示例11: get
int get(int key)
{
++op_count;
if (map_kv.find(key) == map_kv.end()) return -1;
else
{
int old_time = map_kt[key];
map_tk.erase(map_tk.find(old_time));
map_tk.emplace(op_count, key);
map_kt[key] = op_count;
return map_kv[key];
}
}
示例12: combine_load_costs
void combine_load_costs(map<string, Expr> &result, const map<string, Expr> &partial) {
for (const auto &kv : partial) {
auto iter = result.find(kv.first);
if (iter == result.end()) {
result.emplace(kv.first, kv.second);
} else {
if (!iter->second.defined()) {
continue;
} else if (!kv.second.defined()) {
iter->second = Expr();
} else {
iter->second = simplify(iter->second + kv.second);
}
}
}
}
示例13: remapTops
static
void remapTops(const TamaInfo &tamaInfo,
vector<u32> &top_base,
map<pair<const NFA *, u32>, u32> &out_top_remap) {
u32 i = 0;
u32 cur = 0;
for (const auto &sub : tamaInfo.subengines) {
u32 base = cur;
top_base.push_back(base + MQE_TOP_FIRST);
DEBUG_PRINTF("subengine:%u\n", i);
for (const auto &t : tamaInfo.tops[i++]) {
cur = base + t;
DEBUG_PRINTF("top remapping %u:%u\n", t ,cur);
out_top_remap.emplace(make_pair(sub, t), cur++);
}
}
}
示例14: buildDic
void buildDic(map<string, string> &dic,string word){
string key,value;
int len = (int)word.size();
int flag = false;
for(int i = 0; i < len; i++){
if(word[i] == '_'){
flag = true;
continue;
}
if(flag){
value.push_back(word[i]);
}else{
key.push_back(word[i]);
}
}
dic.emplace(key,value);
}
示例15: decltype
namespace detail {
auto memo = [](auto f) {
return [=](auto... args) {
using args_t = std::tuple<decltype(args)...>;
using return_t = decltype(f(args...));
static map<args_t, return_t> m;
auto argsTuple = make_tuple(args...);
auto it = m.find(argsTuple);
if (it != m.end()) {
return it->second;
}
return m.emplace(move(argsTuple),
f(forward<decltype(args)>(args)...)).first->second;
};
};
};