本文整理汇总了C++中std::map::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ map::cbegin方法的具体用法?C++ map::cbegin怎么用?C++ map::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::map
的用法示例。
在下文中一共展示了map::cbegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: answer
// Construct the answer after parsing an input string
std::string answer(const std::map<std::string, coef_type, std::greater<std::string>>& tokens) {
std::string ans;
for (auto cit = tokens.cbegin(); cit != tokens.cend(); ++cit) {
if (cit != tokens.cbegin() && cit->second > 0) {
ans += "+";
}
if (cit->first != "1") {
if (cit ->second > 1 || cit ->second < 1) {
ans += std::to_string(cit->second);
ans += "*";
}
ans += cit->first;
}
else {
ans += std::to_string(cit->second);
}
}
return ans;
}
示例2: findByName_helper
//fills lst or const_lst (depending on which is null) with all borrowers with specified name
static void findByName_helper(const std::map<unsigned int, Borrower>& borrowers, const std::string name,
list<Borrower*const> *const lst, list<const Borrower*const> *const const_lst){
borrowers_citer iter = borrowers.cbegin();
while (iter != borrowers.cend())
{
if (iter->second.getName() == name)
{
const_lst == NULL ? lst->push_back(const_cast<Borrower*>(&iter->second)) : const_lst->push_back(&iter->second);
}
iter++;
}
}
示例3: optionsToString
std::string optionsToString(std::map<std::string, std::string> const &options) {
if (!options.empty()) {
std::ostringstream resultStream;
auto optionsKvpIt = options.cbegin();
auto const &firstKvp = (*optionsKvpIt);
resultStream << firstKvp.first << "='" << firstKvp.second << '\'';
for (; optionsKvpIt != options.cend(); ++optionsKvpIt) {
auto kvp = (*optionsKvpIt);
resultStream << ", " << kvp.first << "='" << kvp.second << '\'';
}
return resultStream.str();
} else {
return std::string();
}
}
示例4: InitializeMeshNeiboNum
int MeshInfoSet::InitializeMeshNeiboNum(const std::map<MeshPair, int>& meshPair, std::map<int, std::vector<std::pair<int, int>>>& meshNeiboNum)
{
int rtn = 0;
meshNeiboNum.clear();
for (map<MeshPair, int>::const_iterator it = meshPair.cbegin(); it != meshPair.cend(); ++it)
{
rtn = AddMeshNeiboNum(it->first.first, it->first.second, it->second, meshNeiboNum);
CHECK_RTN(rtn);
rtn = AddMeshNeiboNum(it->first.second, it->first.first, it->second, meshNeiboNum);
CHECK_RTN(rtn);
}
for (map<int, vector<pair<int, int>>>::iterator it = meshNeiboNum.begin(); it != meshNeiboNum.end(); ++it)
sort(it->second.begin(), it->second.end(), CmpPairByLagerSecond<int, int>);
return 0;
}
示例5: GetServerIDsFromHostMap
// assuming the namenode id is 0
void GetServerIDsFromHostMap(std::vector<int32_t> *server_ids,
const std::map<int32_t, HostInfo>& host_map){
int32_t num_servers = host_map.size() - 1;
server_ids->resize(num_servers);
int32_t i = 0;
for (auto host_info_iter = host_map.cbegin();
host_info_iter != host_map.cend(); host_info_iter++) {
if (host_info_iter->first == 0)
continue;
(*server_ids)[i] = host_info_iter->first;
++i;
}
}
示例6: wakeSleepingThreads
/**
* Function: wakeSleepingThreads
* Iterates over all threads alive and wakes them up if needed.
* If a thread is awaken it is added to the READY list.
*/
void wakeSleepingThreads()
{
uthread *curr;
// Add waking threads to READY list
for (auto th=livingThreads.cbegin(); th != livingThreads.cend(); ++th)
{
// curr is the current thread in the for loop
curr = th->second;
// If the thread is sleeping and it should wake up, wake it up
if (curr->get_state() == uthread::state::SLEEPING &&
uthread_get_time_until_wakeup(curr->get_id())==SHOULD_WAKE)
{
curr->set_state(uthread::state::READY);
readyThreads.push_back(curr->get_id());
}
}
}
示例7: garbage_collection
void garbage_collection()
{
for (auto i = rx_pkt_queue.cbegin(); i != rx_pkt_queue.cend(); /* NO INCREMENT*/)
{
if (i->second->id <= last_fw_id)
{
#ifdef VERBOSE
printf("Erasing pkt with id=%u, last_fw_id %u\n", i->first, last_fw_id);
#endif
rx_pkt_queue.erase(i++);
}
else
{
++i;
}
}
}
示例8: check_types
bool check_types(const std::map<std::string, uint16_t>& expected) {
// holds the type names we see at runtime
std::map<std::string, uint16_t> found;
// fetch all available type names
auto types = uniform_type_info::instances();
for (auto tinfo : types) {
found.insert(std::make_pair(tinfo->name(), tinfo->type_nr()));
}
// compare the two maps
if (expected == found) {
CAF_CHECKPOINT();
return true;
}
CAF_CHECK(false);
using const_iterator = std::map<std::string, uint16_t>::const_iterator;
using std::setw;
using std::left;
std::ostringstream oss;
oss << left << setw(20) << ("found (" + tostr(found.size(), 1) + ")")
<< " | expected (" << expected.size() << ")";
CAF_PRINT(oss.str());
oss.seekp(0);
oss << std::setfill('-') << setw(22) << "" << "|" << setw(22) << "";
CAF_PRINT(oss.str());
auto fi = found.cbegin();
auto fe = found.cend();
auto ei = expected.cbegin();
auto ee = expected.cend();
std::string dummy(20, ' ');
auto out = [&](const_iterator& i, const_iterator last) -> std::string {
if (i == last) {
return dummy;
}
std::ostringstream tmp;
tmp << left << setw(16) << i->first << "[" << tostr(i->second) << "]";
++i;
return tmp.str();
};
while (fi != fe || ei != ee) {
CAF_PRINT(out(fi, fe) << " | " << out(ei, ee));
}
return false;
}
示例9: check_martialarts
void check_martialarts()
{
for( auto style = martialarts.cbegin(); style != martialarts.cend(); ++style ) {
for( auto technique = style->second.techniques.cbegin();
technique != style->second.techniques.cend(); ++technique ) {
if( ma_techniques.find( *technique ) == ma_techniques.end() ) {
debugmsg( "Technique with id %s in style %s doesn't exist.",
technique->c_str(), style->second.name.c_str() );
}
}
for( auto weapon = style->second.weapons.cbegin();
weapon != style->second.weapons.cend(); ++weapon ) {
if( !item::type_is_defined( *weapon ) ) {
debugmsg( "Weapon %s in style %s doesn't exist.",
weapon->c_str(), style->second.name.c_str() );
}
}
}
}
示例10: main
int main()
{
const std::map< int, std::vector<double> > map =
{
{ 247, { 1.2, 2.3, 3.4, 4.5 } },
{ 106, { 5.6, 6.7, 7.8, 8.9, 9.1, 1.2, 2.3 } },
{ 184, { 3.4, 4.5 } }
};
{
// option 1: range-based loops
for( const auto& pair : map )
{
std::cout << "key: " << pair.first << " value: [ " ;
for( double d : pair.second ) std::cout << d << " " ;
std::cout << "]\n" ;
}
}
std::cout << "----------------\n" ;
{
// option 2: iterators
for( auto map_iter = map.cbegin() ; map_iter != map.cend() ; ++map_iter )
{
std::cout << "key: " << map_iter->first << " value: [ " ;
for( auto vec_iter = map_iter->second.cbegin() ; vec_iter != map_iter->second.cend() ; ++vec_iter )
std::cout << *vec_iter << " " ;
std::cout << "]\n" ;
}
}
std::cout << "----------------\n" ;
{
// option 3: range-based loop for map, subscript operator for vector
for( const auto& pair : map )
{
std::cout << "key: " << pair.first << " value: [ " ;
for( std::size_t i = 0 ; i < pair.second.size() ; ++i ) std::cout << pair.second[i] << " " ;
std::cout << "]\n" ;
}
}
// options 4, 5 ...
}
示例11: ModelData
DRAWABLE_PTR_CONTAINER_TEMPLATE_CPP
const model_map ModelData::readModelList(GLFWwindow* window, const std::map<std::string, std::string>& fileNamesAndPaths, const DescriptorType descType){
model_map models;
std::map<std::string, std::string>::const_iterator it;
// Start to asynchronously load models
for (it = fileNamesAndPaths.cbegin(); it != fileNamesAndPaths.cend(); ++it){
models.emplace(it->first, new ModelData(it->second, false, descType)); // Do not create voxel space, also
}
// Wait for individual models to load
std::map<std::string, ModelData*>::const_iterator m_i;
for (m_i = models.cbegin(); m_i != models.cend(); ++m_i){
Framework::GL::initObjectToDraw(m_i->second, window);
}
Framework::ModelUtils::updateModelTransforms(models);
return models;
}
示例12: GetLanguageString
static std::string GetLanguageString(DiscIO::IVolume::ELanguage language, std::map<DiscIO::IVolume::ELanguage, std::string> strings)
{
auto end = strings.end();
auto it = strings.find(language);
if (it != end)
return it->second;
// English tends to be a good fallback when the requested language isn't available
if (language != DiscIO::IVolume::ELanguage::LANGUAGE_ENGLISH)
{
it = strings.find(DiscIO::IVolume::ELanguage::LANGUAGE_ENGLISH);
if (it != end)
return it->second;
}
// If English isn't available either, just pick something
if (!strings.empty())
return strings.cbegin()->second;
return "";
}
示例13: uthread_spawn
/*
* Description: This function creates a new thread, whose entry point is the
* function f with the signature void f(void). The thread is added to the end
* of the READY threads list. The uthread_spawn function should fail if it
* would cause the number of concurrent threads to exceed the limit
* (MAX_THREAD_NUM). Each thread should be allocated with a stack of size
* STACK_SIZE bytes.
* Return value: On success, return the ID of the created thread.
* On failure, return -1.
*/
int uthread_spawn(void (*f)(void))
{
// If the current number of threads is MAX_THREAD_NUM, no
// more threads can be spawned.
if (livingThreads.size() >= MAX_THREAD_NUM)
{
std::cerr << LIB_ERROR_MSG << "Number of threads exceeded "
<< "the maximum number allowed." << std::endl;
return EXIT_FAIL;
}
// Block SIGTVALRM signal
sigset_t oldSet;
blockSignal(SIGVTALRM, &oldSet);
// Find the smallest id available, starting from MAIN_ID + 1.
uthread::id newId = MAIN_THREAD_ID + 1;
for (auto it = ++livingThreads.cbegin(); /* start from the second */
it != livingThreads.cend();
++it)
{
if (newId < it->first)
{
// If the threads ids numbering doesn't match natural
// incremental numbering, we found an empty spot.
break;
}
++newId;
}
// Create a fresh thread with the found id and entry function f
// Then put it in the living threads list and READY list.
uthread *newThread = new uthread(newId, f);
livingThreads.insert(std::make_pair(newId, newThread));
readyThreads.push_back(newId);
// Unblock SIGVTALRM and return
resetSigMask(&oldSet);
return newId;
}
示例14: particleRadii
/******************************************************************************
* Determines the the display particle radii.
******************************************************************************/
void ParticleDisplay::particleRadii(std::vector<FloatType>& output, ParticlePropertyObject* radiusProperty, ParticleTypeProperty* typeProperty)
{
OVITO_ASSERT(radiusProperty == nullptr || radiusProperty->type() == ParticleProperty::RadiusProperty);
OVITO_ASSERT(typeProperty == nullptr || typeProperty->type() == ParticleProperty::ParticleTypeProperty);
if(radiusProperty) {
// Take particle radii directly from the radius property.
OVITO_ASSERT(radiusProperty->size() == output.size());
std::copy(radiusProperty->constDataFloat(), radiusProperty->constDataFloat() + output.size(), output.begin());
}
else if(typeProperty) {
// Assign radii based on particle types.
OVITO_ASSERT(typeProperty->size() == output.size());
// Build a lookup map for particle type radii.
const std::map<int,FloatType> radiusMap = typeProperty->radiusMap();
// Skip the following loop if all per-type radii are zero. In this case, simply use the default radius for all particles.
if(std::any_of(radiusMap.cbegin(), radiusMap.cend(), [](const std::pair<int,FloatType>& it) { return it.second != 0; })) {
// Fill radius array.
const int* t = typeProperty->constDataInt();
for(auto c = output.begin(); c != output.end(); ++c, ++t) {
auto it = radiusMap.find(*t);
// Set particle radius only if the type's radius is non-zero.
if(it != radiusMap.end() && it->second != 0)
*c = it->second;
}
}
else {
// Assign a constant radius to all particles.
std::fill(output.begin(), output.end(), defaultParticleRadius());
}
}
else {
// Assign a constant radius to all particles.
std::fill(output.begin(), output.end(), defaultParticleRadius());
}
}
示例15: main
int main()
{
{
typedef std::pair<const int, double> V;
V ar[] =
{
V(1, 1),
V(1, 1.5),
V(1, 2),
V(2, 1),
V(2, 1.5),
V(2, 2),
V(3, 1),
V(3, 1.5),
V(3, 2),
V(4, 1),
V(4, 1.5),
V(4, 2),
V(5, 1),
V(5, 1.5),
V(5, 2),
V(6, 1),
V(6, 1.5),
V(6, 2),
V(7, 1),
V(7, 1.5),
V(7, 2),
V(8, 1),
V(8, 1.5),
V(8, 2)
};
std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
assert(std::distance(m.begin(), m.end()) == m.size());
assert(std::distance(m.rbegin(), m.rend()) == m.size());
std::map<int, double>::iterator i;
i = m.begin();
std::map<int, double>::const_iterator k = i;
assert(i == k);
for (int j = 1; j <= m.size(); ++j, ++i)
{
assert(i->first == j);
assert(i->second == 1);
i->second = 2.5;
assert(i->second == 2.5);
}
}
{
typedef std::pair<const int, double> V;
V ar[] =
{
V(1, 1),
V(1, 1.5),
V(1, 2),
V(2, 1),
V(2, 1.5),
V(2, 2),
V(3, 1),
V(3, 1.5),
V(3, 2),
V(4, 1),
V(4, 1.5),
V(4, 2),
V(5, 1),
V(5, 1.5),
V(5, 2),
V(6, 1),
V(6, 1.5),
V(6, 2),
V(7, 1),
V(7, 1.5),
V(7, 2),
V(8, 1),
V(8, 1.5),
V(8, 2)
};
const std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
assert(std::distance(m.begin(), m.end()) == m.size());
assert(std::distance(m.cbegin(), m.cend()) == m.size());
assert(std::distance(m.rbegin(), m.rend()) == m.size());
assert(std::distance(m.crbegin(), m.crend()) == m.size());
std::map<int, double>::const_iterator i;
i = m.begin();
for (int j = 1; j <= m.size(); ++j, ++i)
{
assert(i->first == j);
assert(i->second == 1);
}
}
#if __cplusplus >= 201103L || defined(_LIBCPP_MSVC)
{
typedef std::pair<const int, double> V;
V ar[] =
{
V(1, 1),
V(1, 1.5),
V(1, 2),
V(2, 1),
V(2, 1.5),
V(2, 2),
V(3, 1),
//.........这里部分代码省略.........