当前位置: 首页>>代码示例>>C++>>正文


C++ vector::cbegin方法代码示例

本文整理汇总了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> &params,
                     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 );
}
开发者ID:liyulun,项目名称:mantid,代码行数:58,代码来源:Regroup.cpp

示例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);
}
开发者ID:mantidproject,项目名称:mantid,代码行数:17,代码来源:Group.cpp

示例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();
}
开发者ID:socumbersome,项目名称:cpp,代码行数:15,代码来源:main.cpp

示例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);
}
开发者ID:Pingxia,项目名称:CS3202_SPA,代码行数:48,代码来源:QEvalTmpResultCore.cpp

示例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();
	}
}
开发者ID:RetroPie,项目名称:EmulationStation,代码行数:16,代码来源:GridGameListView.cpp

示例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;
  }
开发者ID:afidd,项目名称:Semi-Markov,代码行数:16,代码来源:contact_graph.hpp

示例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;
}
开发者ID:lynebetos,项目名称:StackCompilerTools,代码行数:16,代码来源:StakeInfo.cpp

示例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;
             }
         }
     }
 }
开发者ID:cmberryau,项目名称:utymap,代码行数:17,代码来源:StyleProvider.cpp

示例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);
}
开发者ID:allebacco,项目名称:cnpy,代码行数:47,代码来源:cnpy.cpp

示例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;
}
开发者ID:jlyharia,项目名称:Algorithm,代码行数:29,代码来源:ArrayQuiz.cpp

示例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;
}
开发者ID:afiskon,项目名称:cpp-opengl-textures,代码行数:17,代码来源:utils.cpp

示例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;
    }
}
开发者ID:dreamsxin,项目名称:rippled,代码行数:45,代码来源:Manifest.cpp

示例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;
}
开发者ID:erlerobot,项目名称:rclcpp,代码行数:18,代码来源:node.cpp

示例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!
  }
}
开发者ID:MindMil,项目名称:XCSoar,代码行数:18,代码来源:TaskSolveTravelled.cpp

示例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)
{

}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:18,代码来源:TaskMinTarget.cpp


注:本文中的std::vector::cbegin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。