本文整理汇总了C++中std::vector::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::cbegin方法的具体用法?C++ vector::cbegin怎么用?C++ vector::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::cbegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newAxis
/** Creates a new output X array according to specific boundary defnitions
*
* @param params :: rebin parameters input [x_1, delta_1,x_2, ...
*,x_n-1,delta_n-1,x_n)
* @param xold :: the current x array
* @param xnew :: new output workspace x array
* @param xoldIndex :: indeces of new x in XValues_old
* @return The number of bin boundaries in the new X array
**/
int Regroup::newAxis(const std::vector<double> ¶ms,
const std::vector<double> &xold, std::vector<double> &xnew,
std::vector<int> &xoldIndex) {
double xcurr, xs;
int ibound(2), istep(1), inew(0);
int ibounds = static_cast<int>(
params.size()); // highest index in params array containing a bin boundary
int isteps = ibounds - 1; // highest index in params array containing a step
xcurr = params[0];
auto iup = std::find_if(xold.cbegin(), xold.cend(),
std::bind2nd(std::greater_equal<double>(), xcurr));
if (iup != xold.end()) {
xcurr = *iup;
xnew.push_back(xcurr);
xoldIndex.push_back(inew);
inew++;
} else
return 0;
while ((ibound <= ibounds) && (istep <= isteps)) {
// if step is negative then it is logarithmic step
if (params[istep] >= 0.0)
xs = params[istep];
else
xs = xcurr * fabs(params[istep]);
// xcurr += xs;
// find nearest x_i that is >= xcurr
iup = std::find_if(xold.begin(), xold.end(),
std::bind2nd(std::greater_equal<double>(), xcurr + xs));
if (iup != xold.end()) {
if (*iup <= params[ibound]) {
xcurr = *iup;
xnew.push_back(xcurr);
xoldIndex.push_back(inew);
inew++;
} else {
ibound += 2;
istep += 2;
}
} else
return inew;
}
// returns length of new x array or -1 if failure
return inew;
// return( (ibound == ibounds) && (istep == isteps) ? inew : -1 );
}
示例2: setSymmetryOperations
/// Assigns symmetry operations, throws std::invalid_argument if vector is
/// empty.
void Group::setSymmetryOperations(
const std::vector<SymmetryOperation> &symmetryOperations) {
if (symmetryOperations.empty()) {
throw std::invalid_argument("Group needs at least one element.");
}
m_operationSet.clear();
std::transform(symmetryOperations.cbegin(), symmetryOperations.cend(),
std::inserter(m_operationSet, m_operationSet.begin()),
&getUnitCellIntervalOperation);
m_allOperations = std::vector<SymmetryOperation>(m_operationSet.begin(),
m_operationSet.end());
m_axisSystem = getCoordinateSystemFromOperations(m_allOperations);
}
示例3: average_dbl
double average_dbl(const std::vector<double> & v)
{
double res = 0.0;
#if 0
for(auto it = v.cbegin(); it != v.cend(); ++it)
{
res += *it;
}
#endif
for(double e : v)
res += e;
return res / v.size();
}
示例4: addEdgeConstraint
void QEvalTmpResultCore::addEdgeConstraint(size_t lArgId, size_t rArgId, const std::vector<std::pair<idx_t, idx_t>>& edges)
{
assert(nodesLoaded[lArgId]);
assert(nodesLoaded[rArgId]);
assert(lArgId != rArgId);
bool swap = lArgId > rArgId;
std::vector<std::pair<idx_t, idx_t> > swappedEdge;
if (swap) {
swappedEdge.reserve(edges.size());
std::vector<std::pair<idx_t, idx_t> >::const_iterator edgeIter;
for (edgeIter = edges.cbegin(); edgeIter != edges.cend(); edgeIter++) {
swappedEdge.push_back(std::make_pair((*edgeIter).second, (*edgeIter).first));
}
}
else {
swappedEdge = edges;
}
size_t smallNodeId, largeNodeId;
if (swap) {
smallNodeId = rArgId;
largeNodeId = lArgId;
}
else {
smallNodeId = lArgId;
largeNodeId = rArgId;
}
size_t edgeId = matIdMapper.twoDToOneDNoBoundCheck(smallNodeId, largeNodeId);
// sort, unique
std::sort(swappedEdge.begin(), swappedEdge.end());
auto last = std::unique(swappedEdge.begin(), swappedEdge.end());
swappedEdge.erase(last, swappedEdge.end());
// first filtered by node
filterEdgeListByNodeSet(swappedEdge, true, nodeHashSets[smallNodeId]);
filterEdgeListByNodeSet(swappedEdge, false, nodeHashSets[largeNodeId]);
// second filtered by edge
if (!edgeLists[edgeId].empty()) {
filterSortedEdgeListBySortedUniqEdgeList(swappedEdge, edgeLists[edgeId]);
}
setEdgeInterTriggerUpdate(smallNodeId, largeNodeId, swappedEdge);
}
示例5: populateList
void GridGameListView::populateList(const std::vector<FileData*>& files)
{
mGrid.clear();
mHeaderText.setText(mRoot->getSystem()->getFullName());
if (files.size() > 0)
{
for (auto it = files.cbegin(); it != files.cend(); it++)
{
mGrid.add((*it)->getName(), (*it)->getThumbnailPath(), *it);
}
}
else
{
addPlaceholder();
}
}
示例6: Create
GraphType Create(const std::vector<VertexName>& names) {
ContactGraph graph;
auto name_iter=names.cbegin();
for (; name_iter!=names.cend(); ++name_iter) {
graph.add_vertex(name_iter);
}
auto left=boost::vertices(n);
for ( ; left.first!=left.second; ++left.first) {
auto right=left.first;
for ( ++right; right!=left.second; ++right) {
boost::add_edge(graph, left, right);
}
}
return GraphType;
}
示例7: IsShapePoint
bool CStakeInfo::IsShapePoint(const DCoord& coord, const std::vector<DCoord>& vecCoords, unsigned int& nPos)
{
auto itCoords = vecCoords.cbegin();
nPos = 0;
for (itCoords; itCoords != vecCoords.cend(); ++itCoords)
{
if (Equal(coord, *itCoords))
{
return true;
}
++nPos;
}
nPos = -1;
return false;
}
示例8: check
// Just checks whether style can be created without constructing actual style.
void check(const std::vector<Tag>& tags, const FilterMap& filters)
{
FilterMap::const_iterator iter = filters.find(levelOfDetails_);
if (iter != filters.end()) {
for (const Filter& filter : iter->second) {
bool isMatched = true;
for (auto it = filter.conditions.cbegin(); it != filter.conditions.cend() && isMatched; ++it) {
isMatched &= match_tags(tags.cbegin(), tags.cend(), *it);
}
if (isMatched) {
canBuild_ = true;
return;
}
}
}
}
示例9: npy_save_data
void cnpy::npy_save_data(const std::string& fname,
const unsigned char* data, const Type dtype,
const size_t elemSize, const std::vector<size_t>& shape,
const char mode)
{
FILE* fp = NULL;
if(mode == 'a')
fp = fopen(fname.c_str(),"r+b");
if(fp)
{
//file exists. we need to append to it. read the header, modify the array size
size_t word_size;
std::vector<size_t> tmp_shape;
bool fortran_order;
parse_npy_header(fp, word_size, tmp_shape, fortran_order);
assert(!fortran_order);
if(word_size != elemSize)
throw std::runtime_error("Attempting to append misdimensioned data to "+fname);
if(tmp_shape.size() != shape.size())
throw std::runtime_error("Attempting to append misdimensioned data to "+fname);
for(int i=1; i<shape.size(); ++i)
{
if(shape[i] != tmp_shape[i])
throw std::runtime_error("Attempting to append misshaped data to "+fname);
}
tmp_shape[0] += shape[0];
fseek(fp, 0, SEEK_SET);
std::vector<char> header = create_npy_header(dtype, elemSize, tmp_shape);
fwrite(header.data(), sizeof(char), header.size(), fp);
fseek(fp, 0, SEEK_END);
}
else
{
fp = fopen(fname.c_str(),"wb");
std::vector<char> header = create_npy_header(dtype, elemSize, shape);
fwrite(header.data(), sizeof(char), header.size(), fp);
}
size_t nels = std::accumulate(shape.cbegin(), shape.cend(), 1U, std::multiplies<size_t>());
std::fwrite(data, elemSize, nels, fp);
fclose(fp);
}
示例10: removeDuplicates
/**
* LeetCode 26 Remove Duplicates from Sorted Array 31.5% Easy
* Given a sorted array, remove the duplicates in place such that each element
*appear only once
* and return the new length.
* Do not allocate extra space for another array, you must do this in place with
*constant memory.
* For example,
* Given input array A = [1,1,2],
*
* Your function should return length = 2, and A is now [1,2].
*/
int ArrayQuiz::removeDuplicates(std::vector<int> &A) {
int n = A.size();
if (n == 0) return 0;
int index = 0;
for (int i = 0; i < n; i++) {
if (A[index] == A[i]) { continue; }
index++;
A[index] = A[i];
for_each(A.cbegin(), A.cend(), [&](int i) { cout << i << ", "; });
cout << endl;
}
// remove element from index+1 to end
A.erase(A.begin() + index + 1, A.end());
return index + 1;
// return length;
}
示例11: prepareProgram
GLuint prepareProgram(const std::vector<GLuint>& shaders, bool *errorFlagPtr) {
*errorFlagPtr = false;
GLuint programId = glCreateProgram();
for(auto it = shaders.cbegin(); it != shaders.cend(); ++it) {
glAttachShader(programId, *it);
}
glLinkProgram(programId);
*errorFlagPtr = checkProgramLinkStatus(programId);
if(*errorFlagPtr) {
glDeleteProgram(programId);
return 0;
}
return programId;
}
示例12: ValidatorToken
boost::optional<ValidatorToken>
ValidatorToken::make_ValidatorToken(std::vector<std::string> const& tokenBlob)
{
try
{
std::string tokenStr;
tokenStr.reserve (
std::accumulate (tokenBlob.cbegin(), tokenBlob.cend(), std::size_t(0),
[] (std::size_t init, std::string const& s)
{
return init + s.size();
}));
for (auto const& line : tokenBlob)
tokenStr += beast::rfc2616::trim(line);
tokenStr = beast::detail::base64_decode(tokenStr);
Json::Reader r;
Json::Value token;
if (! r.parse (tokenStr, token))
return boost::none;
if (token.isMember("manifest") && token["manifest"].isString() &&
token.isMember("validation_secret_key") &&
token["validation_secret_key"].isString())
{
auto const ret = strUnHex (token["validation_secret_key"].asString());
if (! ret.second || ! ret.first.size ())
return boost::none;
return ValidatorToken(
token["manifest"].asString(),
SecretKey(Slice{ret.first.data(), ret.first.size()}));
}
else
{
return boost::none;
}
}
catch (std::exception const&)
{
return boost::none;
}
}
示例13: lock
std::vector<uint8_t>
Node::get_parameter_types(
const std::vector<std::string> & names) const
{
std::lock_guard<std::mutex> lock(mutex_);
std::vector<uint8_t> results;
for (auto & kv : parameters_) {
if (std::any_of(names.cbegin(), names.cend(), [&kv](const std::string & name) {
return name == kv.first;
}))
{
results.push_back(kv.second.get_type());
} else {
results.push_back(rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET);
}
}
return results;
}
示例14: fixed
TaskSolveTravelled::TaskSolveTravelled(const std::vector<OrderedTaskPoint *> &tps,
const unsigned activeTaskPoint,
const AircraftState &_aircraft,
const GlideSettings &settings,
const GlidePolar &gp,
const fixed _xmin,
const fixed _xmax)
:ZeroFinder(_xmin, _xmax, fixed(TOLERANCE_CRUISE_EFFICIENCY)),
aircraft(_aircraft),
tm(tps.cbegin(), activeTaskPoint, settings, gp)
{
dt = aircraft.time-tps[0]->GetEnteredState().time;
if (positive(dt)) {
inv_dt = fixed(1)/dt;
} else {
inv_dt = fixed(0); // error!
}
}
示例15: fixed
TaskMinTarget::TaskMinTarget(const std::vector<OrderedTaskPoint*>& tps,
const unsigned activeTaskPoint,
const AircraftState &_aircraft,
const GlideSettings &settings,
const GlidePolar &_gp,
const fixed _t_remaining,
StartPoint *_ts)
:ZeroFinder(fixed(0), fixed(1), fixed(TOLERANCE_MIN_TARGET)),
tm(tps.cbegin(), tps.cend(), activeTaskPoint, settings, _gp,
/* ignore the travel to the start point */
false),
aircraft(_aircraft),
t_remaining(_t_remaining),
tp_start(_ts),
force_current(false)
{
}