本文整理汇总了C++中unordered_map::cend方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::cend方法的具体用法?C++ unordered_map::cend怎么用?C++ unordered_map::cend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::cend方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_primitive
void gui_theme::process_primitive(gui_ui_object::state* st, const xml::xml_node* node) {
// get/check primitive type
static const unordered_map<string, PRIMITIVE_TYPE> primitive_lookup {
{ "point", PRIMITIVE_TYPE::POINT },
{ "line", PRIMITIVE_TYPE::LINE },
{ "triangle", PRIMITIVE_TYPE::TRIANGLE },
{ "rectangle", PRIMITIVE_TYPE::RECTANGLE },
{ "rounded_rectangle", PRIMITIVE_TYPE::ROUNDED_RECTANGLE },
{ "circle", PRIMITIVE_TYPE::CIRCLE },
{ "circle_sector", PRIMITIVE_TYPE::CIRCLE_SECTOR },
{ "ellipsoid", PRIMITIVE_TYPE::ELLIPSOID },
{ "ellipsoid_sector", PRIMITIVE_TYPE::ELLIPSOID_SECTOR },
{ "text", PRIMITIVE_TYPE::TEXT },
};
const auto primitive_iter = primitive_lookup.find(node->name());
if(primitive_iter == primitive_lookup.cend()) {
oclr_error("invalid primitive type specified: %s!", node->name());
return;
}
const PRIMITIVE_TYPE primitive { primitive_iter->second };
// get/check primitive style
static const unordered_map<string, DRAW_STYLE> style_lookup {
{ "fill", DRAW_STYLE::FILL },
{ "gradient", DRAW_STYLE::GRADIENT },
{ "texture", DRAW_STYLE::TEXTURE },
{ "border_fill", DRAW_STYLE::BORDER_FILL },
{ "border_gradient", DRAW_STYLE::BORDER_GRADIENT },
{ "border_texture", DRAW_STYLE::BORDER_TEXTURE },
{ "text", DRAW_STYLE::TEXT },
};
const string style_str(primitive != PRIMITIVE_TYPE::TEXT ? (*node)["style"] : "text");
if(style_str == "INVALID") {
oclr_error("no style specified for primitive: %s", node->name());
return;
}
const auto style_iter = style_lookup.find(style_str);
if(style_iter == style_lookup.cend()) {
oclr_error("invalid style (%s) specified for primitive: %s", style_str, node->name());
return;
}
const DRAW_STYLE style { style_iter->second };
// make sure primitive and style tags got the necessary attributes (not completely achievable with dtd)
if((style == DRAW_STYLE::TEXTURE || style == DRAW_STYLE::BORDER_TEXTURE) &&
(*node)["name"] == "INVALID") {
oclr_error("no texture filename specified for primitive: %s!", node->name());
return;
}
// and load/process:
st->primitives.emplace_back(primitive_data {
primitive, style,
process_point_compute_data(primitive, node),
process_draw_style_data(style, node)
});
}
示例2: into_vector
void into_vector(const unordered_map<T, U>& um, Lambda& func, vector<W>& v) {
transform(
um.cbegin(),
um.cend(),
back_inserter(v),
func);
}
示例3: keys_into_set
void keys_into_set(const unordered_map<T, U>& um, unordered_set<T>& us) {
transform(
um.cbegin(),
um.cend(),
inserter(us, us.end()),
[](const typename unordered_map<T, U>::value_type &pair){
return pair.first;});
}
示例4: keys_into_queue
void keys_into_queue(const unordered_map<T, U>& um, queue<T>& q) {
transform(
um.cbegin(),
um.cend(),
datie::queuie::make_queue_inserter(q),
[](const typename unordered_map<T, U>::value_type &pair ){
return pair.first;});
}
示例5: getDeployments
void getDeployments(vector<string>& _return) {
ostringstream log;
log << "getting deployments" << endl;
cout << log.str();
vector<string> deployments;
for (auto iter = activeDeployments.cbegin(); iter != activeDeployments.cend(); ++iter) {
deployments.push_back(iter->first);
}
_return = deployments;
cout << "returning " << deployments.size() << " deploymentIds" << endl;
}
示例6: mk_contractor_eval
contractor mk_contractor_eval(box const & box, nonlinear_constraint const * const ctr) {
static thread_local unordered_map<nonlinear_constraint const *, contractor> cache;
auto const it = cache.find(ctr);
if (it == cache.cend()) {
contractor ctc(make_shared<contractor_eval>(box, ctr));
cache.emplace(ctr, ctc);
return ctc;
} else {
return it->second;
}
}
示例7: prune
box contractor_cache::prune(box b, SMTConfig & config) const {
// TODO(soonhok): implement this
thread_local static unordered_map<box, box> cache;
auto const it = cache.find(b);
if (it == cache.cend()) {
// Not Found
return m_ctc.prune(b, config);
} else {
// Found
return it->second;
}
}
示例8: isValidParentheses
/**
* @param s A string
* @return whether the string is a valid parentheses
*/
bool isValidParentheses(string& s) {
const unordered_map<char, char> symbol_pair = {{')', '('},
{']', '['},
{'}', '{'}
};
stack<char> parentheses;
for (const auto& c: s) {
const auto& it = symbol_pair.find(c);
if (it != symbol_pair.cend()) {
if (parentheses.empty() ||
parentheses.top() != it->second) {
return false;
}
parentheses.pop();
} else {
parentheses.emplace(c);
}
}
return parentheses.empty();
}
示例9: main
int main() {
int n;
in >> n;
for(int i = 0; i < n; ++i) {
int m;
in >> m;
for(int j = 0; j < m; ++j) {
int tp,val;
in >> tp >> val;
if(list.count(tp))
list[tp]+=val;
else
list[tp]=val;
}
}
out << list.size() << '\n';
for(auto it = list.cbegin(); it!=list.cend();++it){
out << it->first << ' ' << it->second << ' ';
}
out << '\n';
return 0;
}
示例10: eval_enode
double eval_enode(Enode * const e, unordered_map<Enode*, double> const & var_map) {
if (e->isVar()) {
auto const it = var_map.find(e);
if (it == var_map.cend()) {
throw runtime_error("variable not found");
} else {
// Variable is found in var_map
return it->second;
}
} else if (e->isConstant()) {
double const v = e->getValue();
return v;
} else if (e->isSymb()) {
throw runtime_error("eval_enode: Symb");
} else if (e->isNumb()) {
throw runtime_error("eval_enode: Numb");
} else if (e->isTerm()) {
assert(e->getArity() >= 1);
enodeid_t id = e->getCar()->getId();
double ret = 0.0;
Enode * tmp = e;
switch (id) {
case ENODE_ID_PLUS:
ret = eval_enode(tmp->get1st(), var_map);
tmp = tmp->getCdr()->getCdr(); // e is pointing to the 2nd arg
while (!tmp->isEnil()) {
ret = ret + eval_enode(tmp->getCar(), var_map);
tmp = tmp->getCdr();
}
return ret;
case ENODE_ID_MINUS:
ret = eval_enode(tmp->get1st(), var_map);
tmp = tmp->getCdr()->getCdr(); // e is pointing to the 2nd arg
while (!tmp->isEnil()) {
ret = ret - eval_enode(tmp->getCar(), var_map);
tmp = tmp->getCdr();
}
return ret;
case ENODE_ID_UMINUS:
ret = eval_enode(tmp->get1st(), var_map);
assert(tmp->getArity() == 1);
return (- ret);
case ENODE_ID_TIMES:
ret = eval_enode(tmp->get1st(), var_map);
tmp = tmp->getCdr()->getCdr(); // e is pointing to the 2nd arg
while (!tmp->isEnil()) {
ret = ret * eval_enode(tmp->getCar(), var_map);
tmp = tmp->getCdr();
}
return ret;
case ENODE_ID_DIV:
ret = eval_enode(tmp->get1st(), var_map);
tmp = tmp->getCdr()->getCdr(); // e is pointing to the 2nd arg
while (!tmp->isEnil()) {
ret = ret / eval_enode(tmp->getCar(), var_map);
tmp = tmp->getCdr();
}
return ret;
case ENODE_ID_ACOS:
assert(e->getArity() == 1);
return acos(eval_enode(e->get1st(), var_map));
case ENODE_ID_ASIN:
assert(e->getArity() == 1);
return asin(eval_enode(e->get1st(), var_map));
case ENODE_ID_ATAN:
assert(e->getArity() == 1);
return atan(eval_enode(e->get1st(), var_map));
case ENODE_ID_ATAN2:
assert(e->getArity() == 2);
return atan2(eval_enode(e->get1st(), var_map),
eval_enode(e->get2nd(), var_map));
case ENODE_ID_MIN:
assert(e->getArity() == 2);
return fmin(eval_enode(e->get1st(), var_map),
eval_enode(e->get2nd(), var_map));
case ENODE_ID_MAX:
assert(e->getArity() == 2);
return fmax(eval_enode(e->get1st(), var_map),
eval_enode(e->get2nd(), var_map));
case ENODE_ID_MATAN:
assert(e->getArity() == 1);
throw runtime_error("eval_enode: MATAN");
case ENODE_ID_SAFESQRT:
assert(e->getArity() == 1);
throw runtime_error("eval_enode: SAFESQRT");
case ENODE_ID_SQRT:
assert(e->getArity() == 1);
return sqrt(eval_enode(e->get1st(), var_map));
case ENODE_ID_EXP:
assert(e->getArity() == 1);
return exp(eval_enode(e->get1st(), var_map));
case ENODE_ID_LOG:
assert(e->getArity() == 1);
return log(eval_enode(e->get1st(), var_map));
case ENODE_ID_POW:
assert(e->getArity() == 2);
return pow(eval_enode(e->get1st(), var_map),
eval_enode(e->get2nd(), var_map));
case ENODE_ID_ABS:
assert(e->getArity() == 1);
//.........这里部分代码省略.........
示例11: deriv_enode
double deriv_enode(Enode * const e, Enode * const v, unordered_map<Enode*, double> const & var_map) {
if (e == v) {
return 1.0;
}
if (e->isVar()) {
auto const it = var_map.find(e);
if (it == var_map.cend()) {
throw runtime_error("variable not found");
} else {
// Variable is found in var_map
return 0.0;
}
} else if (e->isConstant()) {
return 0.0;
} else if (e->isSymb()) {
throw runtime_error("eval_enode: Symb");
} else if (e->isNumb()) {
throw runtime_error("eval_enode: Numb");
} else if (e->isTerm()) {
assert(e->getArity() >= 1);
enodeid_t id = e->getCar()->getId();
double ret = 0.0;
Enode * tmp = e;
switch (id) {
case ENODE_ID_PLUS:
ret = deriv_enode(tmp->get1st(), v, var_map);
tmp = tmp->getCdr()->getCdr(); // e is pointing to the 2nd arg
while (!tmp->isEnil()) {
ret = ret + deriv_enode(tmp->getCar(), v, var_map);
tmp = tmp->getCdr();
}
return ret;
case ENODE_ID_MINUS:
ret = deriv_enode(tmp->get1st(), v, var_map);
tmp = tmp->getCdr()->getCdr(); // e is pointing to the 2nd arg
while (!tmp->isEnil()) {
ret = ret - deriv_enode(tmp->getCar(), v, var_map);
tmp = tmp->getCdr();
}
return ret;
case ENODE_ID_UMINUS:
ret = deriv_enode(tmp->get1st(), v, var_map);
assert(tmp->getArity() == 1);
return (- ret);
case ENODE_ID_TIMES: {
// (f * g)' = f' * g + f * g'
if (tmp->getArity() != 2) {
throw runtime_error("deriv_enode: only support arity = 2 case for multiplication");
}
double const f = eval_enode(e->get1st(), var_map);
double const f_ = deriv_enode(e->get1st(), v, var_map);
double const g = eval_enode(e->get2nd(), var_map);
double const g_ = deriv_enode(e->get2nd(), v, var_map);
return f_ * g + f * g_;
}
case ENODE_ID_DIV: {
// (f / g)' = (f' * g - f * g') / g^2
if (tmp->getArity() != 2) {
throw runtime_error("deriv_enode: only support arity = 2 case for division");
}
double const f = eval_enode(e->get1st(), var_map);
double const f_ = deriv_enode(e->get1st(), v, var_map);
double const g = eval_enode(e->get2nd(), var_map);
double const g_ = deriv_enode(e->get2nd(), v, var_map);
return (f_ * g - f * g_) / (g * g);
}
case ENODE_ID_ACOS: {
// (acos f)' = -(1 / sqrt(1 - f^2)) f'
assert(e->getArity() == 1);
double const f = eval_enode(e->get1st(), var_map);
double const f_ = deriv_enode(e->get1st(), v, var_map);
return - (1 / sqrt(1 - f * f)) * f_;
}
case ENODE_ID_ASIN: {
// (asin f)' = (1 / sqrt(1 - f^2)) f'
assert(e->getArity() == 1);
double const f = eval_enode(e->get1st(), var_map);
double const f_ = deriv_enode(e->get1st(), v, var_map);
return 1 / sqrt(1 - f * f) * f_;
}
case ENODE_ID_ATAN: {
// (atan f)' = (1 / (1 + f^2)) * f'
assert(e->getArity() == 1);
double const f = eval_enode(e->get1st(), var_map);
double const f_ = deriv_enode(e->get1st(), v, var_map);
return 1 / (1 + f * f) * f_;
}
case ENODE_ID_ATAN2: {
// atan2(x,y)' = -y / (x^2 + y^2) dx + x / (x^2 + y^2) dy
// = (-y dx + x dy) / (x^2 + y^2)
assert(e->getArity() == 2);
double const f = eval_enode(e->get1st(), var_map);
double const f_ = deriv_enode(e->get1st(), v, var_map);
double const g = eval_enode(e->get2nd(), var_map);
double const g_ = deriv_enode(e->get2nd(), v, var_map);
return (-g * f_ + f * g_) / (f * f + g * g);
}
case ENODE_ID_MIN:
assert(e->getArity() == 2);
throw runtime_error("deriv_enode: no support for min");
//.........这里部分代码省略.........
示例12: ProcessDLLData
void ProcessDLLData(const wchar_t *filename, const wstring &mod_dir)
{
const IniFile *const dlldata = new IniFile(filename);
const IniGroup *group;
wstring dllname = dlldata->getWString("", "name");
HMODULE dllhandle;
if (dllhandles.find(dllname) != dllhandles.cend())
dllhandle = dllhandles[dllname];
else
{
dllhandle = GetModuleHandle(dllname.c_str());
dllhandles[dllname] = dllhandle;
}
if (dllexports.find(dllname) == dllexports.end())
{
group = dlldata->getGroup("Exports");
dllexportcontainer exp;
for (auto iter = group->cbegin(); iter != group->cend(); ++iter)
{
dllexportinfo inf;
inf.address = GetProcAddress(dllhandle, iter->first.c_str());
inf.type = iter->second;
exp.exports[iter->first] = inf;
}
dllexports[dllname] = exp;
}
const auto exports = &dllexports[dllname].exports;
dlltexlists.clear();
if (dlldata->hasGroup("TexLists"))
{
group = dlldata->getGroup("TexLists");
for (auto iter = group->cbegin(); iter != group->cend(); ++iter)
{
NJS_TEXLIST *key = (NJS_TEXLIST*)std::stoul(iter->first, nullptr, 16);
vector<string> valstr = split(iter->second, ',');
NJS_TEXLIST *value;
if (valstr.size() > 1)
value = ((NJS_TEXLIST**)(*exports)[valstr[0]].address)[std::stoul(valstr[1])];
else
value = (NJS_TEXLIST*)(*exports)[valstr[0]].address;
dlltexlists[key] = value;
}
}
dlllabels.clear();
group = dlldata->getGroup("Files");
for (auto iter = group->cbegin(); iter != group->cend(); ++iter)
{
auto type = dllfilefuncmap.find(split(iter->second, '|')[0]);
if (type != dllfilefuncmap.end())
type->second(mod_dir + L'\\' + MBStoUTF16(iter->first, CP_UTF8));
}
char buf[16];
for (unsigned int k = 0; k < 9999; k++)
{
snprintf(buf, sizeof(buf), "Item%u", k);
if (dlldata->hasGroup(buf))
{
group = dlldata->getGroup(buf);
const dllexportinfo &exp = (*exports)[group->getString("Export")];
auto type = dlldatafuncmap.find(exp.type);
if (type != dlldatafuncmap.end())
type->second(group, exp.address);
}
}
delete dlldata;
}
示例13: comma_pos
unique_ptr<gui_theme::draw_style_data> gui_theme::process_draw_style_data(const gui_theme::DRAW_STYLE style, const xml::xml_node* node) {
//
const auto str_to_float4 = [](const string& float4_str) -> float4 {
const vector<string> float4_tokens { core::tokenize(float4_str, ',') };
if(float4_tokens.size() != 4) {
oclr_error("invalid float4 token count: %u!", float4_tokens.size());
return float4(0.0f, 1.0f, 0.0f, 1.0f); // green -> invalid color/float4
}
return float4(string2float(float4_tokens[0]),
string2float(float4_tokens[1]),
string2float(float4_tokens[2]),
string2float(float4_tokens[3]));
};
const auto str_to_ui_color = [&str_to_float4](const string& color_str) -> ui_color {
const auto comma_pos(color_str.find(","));
// no comma -> must be a scheme reference
if(comma_pos == string::npos) {
return ui_color { color_str }; // validity must be checked later
}
// comma -> must be a raw color
return ui_color { str_to_float4(color_str) };
};
// gradient helpers:
const auto str_to_gradient = [](const string& gradient_str) -> gfx2d::GRADIENT_TYPE {
static const unordered_map<string, gfx2d::GRADIENT_TYPE> types {
{ "horizontal", gfx2d::GRADIENT_TYPE::HORIZONTAL },
{ "vertical", gfx2d::GRADIENT_TYPE::VERTICAL },
{ "diagonal_lr", gfx2d::GRADIENT_TYPE::DIAGONAL_LR },
{ "diagonal_rl", gfx2d::GRADIENT_TYPE::DIAGONAL_RL },
};
const auto iter = types.find(gradient_str);
if(iter == types.cend()) {
oclr_error("invalid gradient type: %s!", gradient_str);
return gfx2d::GRADIENT_TYPE::HORIZONTAL;
}
return iter->second;
};
const auto str_to_gradient_stops = [](const string& stops_str) -> float4 {
const auto tokens = core::tokenize(stops_str, ',');
float4 ret(0.0f);
for(size_t i = 0; i < std::min(tokens.size(), (size_t)4); i++) {
ret[i] = string2float(tokens[i]);
}
return ret;
};
const auto str_to_gradient_colors = [&str_to_ui_color](const string& gradient_colors) -> vector<ui_color> {
const auto color_tokens = core::tokenize(gradient_colors, ';');
vector<ui_color> colors;
for(size_t i = 0; i < std::min(color_tokens.size(), (size_t)4); i++) {
colors.emplace_back(str_to_ui_color(color_tokens[i]));
}
return colors;
};
// texture helpers:
const auto str_to_coords = [](const string& coords_str) -> pair<float2, float2> {
if(coords_str == "INVALID") return make_pair(float2(0.0f), float2(1.0f)); // default
const auto coords_tokens = core::tokenize(coords_str, ';');
if(coords_tokens.size() != 2) {
oclr_error("invalid coord token count (%u) for coords: %s!", coords_tokens.size(), coords_str);
return make_pair(float2(0.0f), float2(1.0f));
}
const auto bottom_left_tokens = core::tokenize(coords_tokens[0], ',');
const auto top_right_tokens = core::tokenize(coords_tokens[1], ',');
return make_pair(bottom_left_tokens.size() >= 2 ?
float2(string2float(bottom_left_tokens[0]), string2float(bottom_left_tokens[1])) :
float2(string2float(bottom_left_tokens[0])),
top_right_tokens.size() >= 2 ?
float2(string2float(top_right_tokens[0]), string2float(top_right_tokens[1])) :
float2(string2float(top_right_tokens[0])));
};
//
switch(style) {
case DRAW_STYLE::FILL:
return make_unique<ds_fill>(str_to_ui_color((*node)["color"]));
case DRAW_STYLE::BORDER_FILL:
return make_unique<ds_border_fill>(str_to_ui_float(str_to_ui_float_pair((*node)["thickness"])),
str_to_ui_color((*node)["color"]));
case DRAW_STYLE::GRADIENT:
return make_unique<ds_gradient>(str_to_gradient((*node)["gradient"]),
str_to_gradient_stops((*node)["stops"]),
str_to_gradient_colors((*node)["colors"]));
case DRAW_STYLE::BORDER_GRADIENT:
return make_unique<ds_border_gradient>(str_to_ui_float(str_to_ui_float_pair((*node)["thickness"])),
str_to_gradient((*node)["gradient"]),
str_to_gradient_stops((*node)["stops"]),
str_to_gradient_colors((*node)["colors"]));
case DRAW_STYLE::BORDER_TEXTURE:
case DRAW_STYLE::TEXTURE: {
string tex_name = (*node)["name"];
image* texture = nullptr;
if(tex_name.find(".png") != string::npos) {
//.........这里部分代码省略.........