本文整理汇总了C++中std::vector::cend方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::cend方法的具体用法?C++ vector::cend怎么用?C++ vector::cend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::cend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: icase_equal
static inline uint16_t bind_port(util::csview scheme, const uint16_t port_from_uri) noexcept {
static const std::vector<std::pair<util::csview, uint16_t>> port_table
{
{"ftp", 21U},
{"http", 80U},
{"https", 443U},
{"irc", 6667U},
{"ldap", 389U},
{"nntp", 119U},
{"rtsp", 554U},
{"sip", 5060U},
{"sips", 5061U},
{"smtp", 25U},
{"ssh", 22U},
{"telnet", 23U},
{"ws", 80U},
{"wss", 443U},
{"xmpp", 5222U},
};
if (port_from_uri not_eq 0) return port_from_uri;
const auto it = std::find_if(port_table.cbegin(), port_table.cend(), [scheme](const auto& _) {
return icase_equal(_.first, scheme);
});
return (it not_eq port_table.cend()) ? it->second : 0xFFFFU;
}
示例2: test_singletons
void test_singletons(CompareT cmp, std::vector<T> values, direction M)
{
std::cout << "Test singletons" << std::endl;
die_unless(cmp(cmp.min_value(), cmp.max_value()));
size_t pos_compares = 0;
size_t neg_compares = 0;
for (auto i1 = values.cbegin(); i1 != values.cend(); ++i1) {
die_unless(!cmp(*i1, *i1));
die_unless(cmp(*i1, cmp.max_value()));
die_unless(cmp(cmp.min_value(), *i1));
for (auto i2 = values.cbegin(); i2 != values.cend(); ++i2) {
const bool expected = (M == direction::Less) ? (*i1 < *i2) : (*i1 > *i2);
const bool compared = cmp(*i1, *i2);
pos_compares += compared;
neg_compares += !compared;
die_unless(expected == compared);
}
}
die_unless(pos_compares + values.size() == neg_compares);
}
示例3: parseArgument
/** A specialisation for bool to allow more, better values. */
bool CommandSystem::parseArgument(std::string &message, bool *result)
{
const static std::vector<std::string> trueValues = { "on", "true", "yes", "1" };
const static std::vector<std::string> allValues = { "on", "true", "yes", "1",
"off", "false", "no", "0" };
std::vector<std::string> possible = chooseWord(allValues, message);
if (possible.empty())
return false;
// Look what possibilities were found
bool foundTrue = false;
bool foundFalse = false;
for (const auto &p : possible)
{
if (std::find(trueValues.cbegin(), trueValues.cend(), p) != trueValues.cend())
foundTrue = true;
else
foundFalse = true;
}
if (foundTrue && foundFalse)
return false;
*result = foundTrue;
return true;
}
示例4: printUI
/**
* Wyświetla informacje na ekranie.
*/
void printUI(unsigned int step,
const std::vector<Conveyor *>& conveyors,
const std::vector<Tank *>& tanks)
{
using namespace std;
clearScreen();
cout << "Krok symulacji: " << step << '\n';
// Wyświetl kilka przenosników
cout << "Przenośniki:\n";
int num = 15;
for (auto it = conveyors.cbegin(); it != conveyors.cend() && num > 0; ++it) {
Conveyor *c = *it;
cout << setw(10) << c->name()
<< " (Q_we: " << setw(4) << c->m_chwilowaWydajnoscNaWejsciu << " t/h) ";
(*it)->printMaterialDistribution(100); // Wyświetl odcinkami po 100 [m]
cout << " (Q_wy: " << setw(4) << c->m_chwilowaWydajnoscNaWyjsciu << " t/h)\n";
--num;
}
cout << endl;
// Wyświetl kilka zbiorników
cout << "Zbiorniki:\n";
num = 5;
for (auto it = tanks.cbegin(); it != tanks.cend() && num > 0; ++it) {
cout << setw(10) << (*it)->name() << ' ';
(*it)->printMaterialDistribution();
--num;
}
}
示例5: return
/** Add a keyword from it's definition
*
* @param _lines : lines which define the keyword
* @return keyword
*
* Returns a nullptr if keyword the keyword
*/
std::shared_ptr<Keyword>
KeyFile::add_keyword(const std::vector<std::string>& _lines,
int64_t _line_index)
{
// find keyword name
const auto it =
std::find_if(_lines.cbegin(), _lines.cend(), [](const std::string& line) {
return (line.size() > 0 && line[0] == '*');
});
if (it == _lines.cend())
throw(std::invalid_argument(
"Can not find keyword definition (line must begin with *)"));
// determine type
auto kw_type = Keyword::determine_keyword_type(*it);
// do the thing
auto kw = create_keyword(_lines, kw_type, _line_index);
if (kw)
keywords[kw->get_keyword_name()].push_back(kw);
return kw;
}
示例6: containsVirtualCall
SourceLocation VirtualCallsFromCTOR::containsVirtualCall(clang::CXXRecordDecl *classDecl, clang::Stmt *stmt, std::vector<Stmt*> &processedStmts)
{
if (stmt == nullptr)
return {};
// already processed ? we don't want recurring calls
if (std::find(processedStmts.cbegin(), processedStmts.cend(), stmt) != processedStmts.cend())
return {};
processedStmts.push_back(stmt);
std::vector<CXXMemberCallExpr*> memberCalls;
Utils::getChilds2<CXXMemberCallExpr>(stmt, memberCalls);
for (CXXMemberCallExpr *callExpr : memberCalls) {
CXXMethodDecl *memberDecl = callExpr->getMethodDecl();
if (memberDecl == nullptr || dyn_cast<CXXThisExpr>(callExpr->getImplicitObjectArgument()) == nullptr)
continue;
if (memberDecl->getParent() == classDecl) {
if (memberDecl->isPure()) {
return callExpr->getLocStart();
} else {
if (containsVirtualCall(classDecl, memberDecl->getBody(), processedStmts).isValid())
return callExpr->getLocStart();
}
}
}
return {};
}
示例7: fromBitsToBytes
std::vector<uint8_t> fromBitsToBytes(const std::vector<uint8_t>& bitVec)
{
std::vector<uint8_t> byteVec{};
if (bitVec.size() % 8 != 0) // The number of bits is not a multiple of 8
return byteVec;
// We make sure that each element is either a one or a zero
auto it = std::find_if_not(bitVec.cbegin(), bitVec.cend(), [](uint8_t x) {
return x == 0 || x == 1;
});
if (it == bitVec.cend())
{
// All the values were 0 or 1
for(auto it8 = bitVec.cbegin(); it8 < bitVec.cend(); it8 += 8)
{
// We get all the bits one by one
uint8_t tmp{};
for(auto index = 0 ; index < 8; ++index)
{
tmp |= (*(it8 + index)) << index;
}
byteVec.push_back(tmp);
}
}
return byteVec;
}
示例8: getCommonParentPath
std::string getCommonParentPath(const std::vector<std::string> &paths)
{
if(paths.size() == 0)
return std::string();
std::size_t maxCommonSize =
string_utils::getMaxCommonSize(paths.cbegin(), paths.cend());
const char *refStart = paths.back().c_str();
const char *refEnd = refStart + maxCommonSize;
while(refStart != refEnd)
{
bool same = true;
for(auto it = paths.cbegin(); it != paths.cend() - 1; ++it)
{
if(!std::equal(refStart, refEnd, it->c_str()))
{
same = false;
break;
}
}
if(same)
break;
--refEnd;
}
if(refStart == refEnd)
return std::string();
return std::string(refStart, refEnd);
}
示例9: select
types::DiscoveryEntryWithMetaInfo QosArbitrationStrategyFunction::select(
const std::map<std::string, types::CustomParameter> customParameters,
const std::vector<types::DiscoveryEntryWithMetaInfo>& discoveryEntries) const
{
std::ignore = customParameters;
auto selectedDiscoveryEntryIt = discoveryEntries.cend();
std::int64_t highestPriority = types::ProviderQos().getPriority(); // get default value
for (auto it = discoveryEntries.cbegin(); it != discoveryEntries.cend(); ++it) {
const types::ProviderQos& providerQos = it->getQos();
JOYNR_LOG_TRACE(logger(), "Looping over discoveryEntry: {}", it->toString());
if (providerQos.getPriority() >= highestPriority) {
selectedDiscoveryEntryIt = it;
JOYNR_LOG_TRACE(logger(),
"setting selectedParticipantId to {}",
selectedDiscoveryEntryIt->getParticipantId());
highestPriority = providerQos.getPriority();
}
}
if (selectedDiscoveryEntryIt == discoveryEntries.cend()) {
std::stringstream errorMsg;
errorMsg << "There was more than one entry in capabilitiesEntries, but none of the "
"compatible entries had a priority >= " << types::ProviderQos().getPriority();
JOYNR_LOG_WARN(logger(), errorMsg.str());
throw exceptions::DiscoveryException(errorMsg.str());
}
return *selectedDiscoveryEntryIt;
}
示例10: cartProductSorted
void QEvalTmpResultCore::cartProductSorted(std::vector<std::pair<idx_t, idx_t>>& result, const std::vector<idx_t>& left, const std::vector<idx_t>& right)
{
result.reserve(left.size()*right.size());
std::vector<idx_t>::const_iterator lIter, rIter;
for (lIter = left.cbegin(); lIter != left.cend(); lIter++) {
for (rIter = right.cbegin(); rIter != right.cend(); rIter++) {
result.push_back(std::make_pair(*lIter, *rIter));
}
}
std::sort(result.begin(), result.end());
}
示例11: assert
std::size_t
colidx(const std::vector<std::string> & colnames, const std::string & name)
{
std::vector<std::string>::const_iterator found = std::find(colnames.cbegin(), colnames.cend(), name);
if (found == colnames.cend())
{
std::cerr << "Bad column name: " << name << std::endl;
}
assert(found != colnames.cend());
return found - colnames.cbegin();
}
示例12: broadcast_impl
void broadcast_impl(std::vector<hpx::id_type> ids,
hpx::util::function<void(hpx::id_type)> fun, std::size_t fan_out)
{
// Call some action for the fan_out first ids here ...
std::vector<hpx::future<void> > broadcast_futures;
broadcast_futures.reserve((std::min)(ids.size(), fan_out));
for(std::size_t i = 0; i < (std::min)(fan_out, ids.size()); ++i)
{
broadcast_futures.push_back(
hpx::async(fun, ids[i])
);
}
if(ids.size() > fan_out)
{
typedef std::vector<hpx::id_type>::const_iterator iterator;
iterator begin = ids.cbegin() + fan_out;
for(std::size_t i = 0; i < fan_out; ++i)
{
std::size_t next_dist = (ids.size() - fan_out)/fan_out + 1;
iterator end
= ((i == fan_out-1) || ((std::distance(ids.cbegin() +
fan_out, begin) + next_dist) >= ids.size()))
? ids.cend()
: begin + next_dist;
std::vector<hpx::id_type> next(begin, end);
if(next.size() > 0)
{
hpx::id_type dst = hpx::naming::get_locality_from_id(next[0]);
broadcast_futures.push_back(
hpx::async<broadcast_impl_action>(dst, std::move(next),
fun, fan_out)
);
/*
hpx::apply<broadcast_impl_action>(dst, std::move(next),
fun, fan_out);
*/
}
if(end == ids.cend()) break;
begin = end;
}
}
if(broadcast_futures.size() > 0)
{
hpx::wait_all(broadcast_futures);
}
}
示例13: lk
std::vector<LogicalSessionId> LogicalSessionCacheImpl::listIds(
const std::vector<SHA256Block>& userDigests) const {
stdx::lock_guard<stdx::mutex> lk(_cacheMutex);
std::vector<LogicalSessionId> ret;
for (const auto& it : _activeSessions) {
if (std::find(userDigests.cbegin(), userDigests.cend(), it.first.getUid()) !=
userDigests.cend()) {
ret.push_back(it.first);
}
}
return ret;
}
示例14:
std::vector<tpoint>
intersection(const std::vector<tpoint>& lhs, const std::vector<tpoint>& rhs)
{
std::vector<tpoint> result;
std::set_intersection(lhs.cbegin(),
lhs.cend(),
rhs.cbegin(),
rhs.cend(),
std::back_inserter(result));
return result;
}
示例15: find
boost::optional<const User&> find(const std::string & nick) const
{
auto result = std::find_if(
users_alpha_.cbegin(),
users_alpha_.cend(),
[&nick, this](const User* u){
return this->locale_(nick, u->nick);
});
if (result != users_alpha_.cend())
return boost::optional<const User&>(*(*result));
return boost::none;
}