本文整理汇总了C++中std::deque::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ deque::assign方法的具体用法?C++ deque::assign怎么用?C++ deque::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::deque
的用法示例。
在下文中一共展示了deque::assign方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
float KMeansClustering<T, TTraits>::doClusterAssignmentForAllItems(
const std::vector<T> &items,
const std::vector<T> &clusterCenters,
std::vector<int> &clusterAssignment,
std::deque<float> &squaredErrorForItems
) {
const size_t nItems = items.size();
const size_t k = clusterCenters.size();
float curSSEForAllItems = 0.0f;
squaredErrorForItems.assign(nItems, -1.0);
for(int j=0; j < nItems; ++j) {
assert(TTraits::validate(items[j]));
squaredErrorForItems[j] = 0.0f;
float minDistSoFar = std::numeric_limits<float>::max();
int clusterWithMinDist = -1;
for(int m=0; m < k; ++m) {
float curDist = TTraits::dist(clusterCenters[m], items[j]);
if(curDist < minDistSoFar) {
clusterWithMinDist = m;
minDistSoFar = curDist;
}
}
clusterAssignment[j] = clusterWithMinDist;
squaredErrorForItems[j] = minDistSoFar;
curSSEForAllItems += minDistSoFar;
}
//verification that each valid contour is assigned to a cluster
for(int j =0; j < clusterAssignment.size(); ++j) {
assert(clusterAssignment[j] >= 0);
}
return curSSEForAllItems;
}
示例2: setup_players
void setup_players(std::deque<player_t *> &tournament_players) {
tournament_players.assign(this->players.begin(), this->players.end());
std::random_shuffle(tournament_players.begin(), tournament_players.end());
/** Define o 1o elemento como "bye", se necessário" */
if(tournament_players.size() % 2)
tournament_players.push_front(nullptr);
}
示例3: assert
void
test(std::deque<int>& c1, int size, int v)
{
typedef std::deque<int> C;
typedef C::const_iterator CI;
std::size_t c1_osize = c1.size();
c1.assign(size, v);
assert(c1.size() == size);
assert(distance(c1.begin(), c1.end()) == c1.size());
for (CI i = c1.begin(); i != c1.end(); ++i)
assert(*i == v);
}
示例4: plan
void plan(){
ROS_INFO("planning");
//if((ros::Time::now()-local_map->header.stamp)>ros::Duration(5.0))
// return;
if(keepMoving){
if(planned && current_path.size()>0){
//look for farther free space straighline of previous trajectory
int i=0;
while(i<current_path.size() && segmentFeasibility(startState,current_path[i])){
++i;
}
--i;
State<2> s=startState+(current_path[i]-startState)*std::min((current_path[i]-startState).norm(),1.0f)*(1/(current_path[i]-startState).norm());
//set and send the waypoint
setWaypoint(s);
//plan from that waypoint
startState=s;
}
}else{
stop();
}
planned=false;
planning=true;
//Run the desired planner
//RRTstar_planning();
//MSPP_planning();
Astar_planning();
if(planned){
current_path=std::deque<State<2>>();
current_path.assign(current_path_raw.begin(),current_path_raw.end());
//*
std::cout << "smoothed solution" <<std::endl;
//for(int i=0;i<current_path_raw.size();++i)
for(int i=0;i<1;++i)
smoothTraj();
if(waypointMaxDistance>0)
densifyWaypoints();
/*std::cout << "Path length: " << current_path.size() << std::endl;
for(std::deque<State<2>>::iterator it=current_path.begin(),end=current_path.end();it!=end;++it){
std::cout << (*it) << " -- ";}
std::cout << std::endl << "raw:" <<std::endl;
for(std::deque<State<2>>::iterator it=current_path_raw.begin(),end=current_path_raw.end();it!=end;++it){
std::cout << (*it) << " -- ";
}
std::cout << std::endl;*/
//*/
setWaypoint(current_path.front());
}
planning=false;
}
示例5: clear
void clear(){
Data[0].front=&Data[0];
Data[0].back=&Data[0];
if(Data.size()==1){
Ptrs.clear();
return;
}else{
Ptrs.assign(Data.size()-1,0);
std::deque<Datum*>::iterator itr=Ptrs.begin(),enditr=Ptrs.end();
array<Datum>::iterator ditr=Data.begin();
++ditr; //Nullデータ部をよける
while(itr!=enditr){
(*itr)=&(*ditr);
++ditr;
++itr;
}
}
}
示例6: bad_assign_deque1
void bad_assign_deque1(std::deque<int> &D, int n) {
auto i0 = D.cbegin();
D.assign(10, n);
*i0; // expected-warning{{Invalidated iterator accessed}}
}