本文整理匯總了C++中std::back_inserter方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::back_inserter方法的具體用法?C++ std::back_inserter怎麽用?C++ std::back_inserter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::back_inserter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: operator
inline typename boost::enable_if< boost::is_directed_graph<Graph>,
boost::tuple< typename boost::graph_traits<Graph>::vertex_descriptor,
typename boost::property_traits<PositionMap>::value_type,
typename Graph::edge_bundled > >::type
operator()(Graph& g,
RRGVisitor vis,
PositionMap g_position) const {
typedef typename boost::property_traits<PositionMap>::value_type PositionValue;
typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename Graph::edge_bundled EdgeProp;
typedef boost::tuple< typename boost::graph_traits<Graph>::vertex_descriptor,
typename boost::property_traits<PositionMap>::value_type,
typename Graph::edge_bundled > ResultType;
using std::back_inserter;
while(true) {
PositionValue p_new = get_sample(*space);
std::vector<Vertex> Pred, Succ;
select_neighborhood(p_new, back_inserter(Pred), back_inserter(Succ), g, *space, g_position);
Vertex x_near; bool was_expanded; EdgeProp ep;
boost::tie(x_near, was_expanded, ep) = detail::expand_to_nearest(p_new, Pred, g, vis);
if( was_expanded )
return ResultType(x_near, p_new, ep);
};
return ResultType();
};
示例2:
vector<string> vertex_cover(const graph g) {
vector<connection> list;
copy(g.begin(), g.end(), back_inserter(list));
sort(list.begin(), list.end(), [](connection a, connection b) {
return a.second.size() > b.second.size();
});
vector<string> cover;
while (list.size()) {
connection max = list.at(0);
cover.push_back(max.first);
list.erase(list.begin());
for (string conc : max.second) {
if (!list.size())
break;
auto to_remove = find_if(list.begin(), list.end(), [conc](connection c) {
return c.first == conc;
});
if (to_remove != list.end()) {
list.erase(to_remove);
}
}
}
return cover;
}
示例3: find_best_key
string find_best_key(vector<string> &v) {
//Sort the vector by size
//Gets the longest str length
sort (v.begin(), v.end(), [](const string& s1, const string& s2){
return s1.size() < s2.size();
}
);
//Gets the longest str length
long longest_str_len = v.back().length();
vector<string> best_keys;
//only copy if the word is the largest
copy_if(v.begin(),
v.end(),
back_inserter(best_keys),
[longest_str_len](string str) {
return str.length() == longest_str_len;
}
);
//sort by the value of the keys
sort(best_keys.begin(), best_keys.end());
//return the smallest key
return best_keys[0];
}
示例4: main
int main()
{
vector<int> vec(10); // default initialized to 0
fill(vec.begin(), vec.end(), 1); // reset each element to 1
// sum the elements in vec starting the summation with the value 0
int sum = accumulate(vec.cbegin(), vec.cend(), 0);
cout << sum << endl;
// set a subsequence of the container to 10
fill(vec.begin(), vec.begin() + vec.size()/2, 10);
cout << accumulate(vec.begin(), vec.end(), 0) << endl;
// reset the same subsequence to 0
fill_n(vec.begin(), vec.size()/2, 0);
cout << accumulate(vec.begin(), vec.end(), 0) << endl;
// create 10 elements on the end of vec each with the value 42
fill_n(back_inserter(vec), 10, 42);
cout << accumulate(vec.begin(), vec.end(), 0) << endl;
// concatenate elements in a vector of strings and store in sum
vector<string> v;
string s;
while (cin >> s)
v.push_back(s);
string concat = accumulate(v.cbegin(), v.cend(), string(""));
cout << concat << endl;
return 0;
}
示例5: loadAudioDevices
void DevSetup::loadAudioDevices (AudioDevices const& d, QComboBox * cb, QAudioDeviceInfo const& device, QAudioDeviceInfo const& defaultDevice)
{
using std::copy;
using std::back_inserter;
int currentIndex = -1;
int defaultIndex = 0;
for (AudioDevices::const_iterator p = d.cbegin (); p != d.cend (); ++p)
{
// convert supported channel counts into something we can store in the item model
QList<QVariant> channelCounts;
QList<int> scc (p->supportedChannelCounts ());
copy (scc.cbegin (), scc.cend (), back_inserter (channelCounts));
cb->addItem (p->deviceName (), channelCounts);
if (*p == device)
{
currentIndex = p - d.cbegin ();
}
else if (*p == defaultDevice)
{
defaultIndex = p - d.cbegin ();
}
}
cb->setCurrentIndex (currentIndex != -1 ? currentIndex : defaultIndex);
}
示例6: getUrl
void spider::PageDownloader::download() const {
using std::back_inserter;
using std::string;
using std::vector;
try {
Url const& url = getUrl();
std::cerr << "Downloading page: " << url << std::endl;
HttpResponse response = getResponse();
int statusCode = response.getStatusCode();
if (statusCode < 200 || statusCode >= 400) {
return; // ignore errors
}
if (statusCode >= 300 && statusCode < 400) {
handleRedirect(response);
return;
}
string content = getContent(response);
vector<Url> urls;
m_finder.getUrls(url, content, back_inserter(urls));
m_manager.download(url, urls.begin(), urls.end());
} catch (ConnectionException const& exception) {
std::cerr << exception.what() << std::endl;
}
}
示例7: main
int main()
{
CGAL::set_pretty_mode(cout);
// build a random convex 20-gon p
{
Polygon_2 p;
random_convex_set_2(20, back_inserter(p), Point_generator(1.0));
cout << "------------------------------\nInput:\n" << p << endl;
compute(p.vertices_begin(), p.vertices_end());
}
// try identical points
{
Polygon_2 p;
for (int i = 1; i < 3; ++i) {
cout << "------------------------------\nInput:\n" << p << endl;
compute(p.vertices_begin(), p.vertices_end());
p.push_back(Point_2(0,0));
}
}
return 0;
}
示例8: average_analysis
double average_analysis(const Vec<Student_info>& students)
{
Vec<double> grades;
transform(students.begin(), students.end(),
back_inserter(grades), average_grade);
return median(grades);
}
示例9: compute
void compute(ForwardIterator f, ForwardIterator l)
{
// compute the minimal enclosing rectangle p_m of p
Polygon_2 p_r;
min_rectangle_2(f, l, back_inserter(p_r));
cout << "Min_rectangle:\n" << p_r << endl;
// compute the minimal enclosing parallelogram p_p of p
Polygon_2 p_p;
min_parallelogram_2(f, l, back_inserter(p_p));
cout << "Min_parallelogram:\n" << p_p << endl;
// compute the minimal enclosing strip p_s of p
Line_2 lines[2];
min_strip_2(f, l, lines);
cout << "Min_strip:\n" << lines[0] << "\n" << lines[1] << endl;
}
示例10:
vector<Student_info>
extract_fails(vector<Student_info>& students) {
vector<Student_info> fail;
remove_copy_if(students.begin(), students.end(),
back_inserter(fail), pgrade);
students.erase(remove_if(students.begin(), students.end(),
fgrade), students.end());
return fail;
}
示例11: optimistic_median
// median of the nonzero elements of `s.homework', or `0' if no such elements exist
double optimistic_median(const Student_info& s)
{
Vec<double> nonzero;
remove_copy(s.homework.begin(), s.homework.end(),
back_inserter(nonzero), 0);
if (nonzero.empty())
return grade(s.midterm, s.final, 0);
else
return grade(s.midterm, s.final, median(nonzero));
示例12: splitSentenceAndResult
void splitSentenceAndResult(const vector<string> &input, vector<string> *sentence, vector<vector<string>> *correctResultList) {
for (const auto &str : input) {
auto split = Utility::splitString(str);
sentence->emplace_back(move(split[0]));
vector<string> temp;
temp.reserve(split.size() - 1);
move(split.begin() + 1, split.end(), back_inserter(temp));
correctResultList->emplace_back(move(temp));
}
}
示例13: make_bool_vec
static bool_vec make_bool_vec(const std::string& str) {
std::vector<bool> res;
res.reserve(str.size());
std::transform(begin(str), end(str), back_inserter(res), [](const char c) {
assert(c == '0' || c == '1');
return c == '1';
});
assert(res.size() == str.size());
return res;
}
示例14: main
int main() {
vector<int> vec{1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
list<int> lst;
copy(vec.crbegin() + 3, vec.crend() - 3, back_inserter(lst));
for (const auto i : lst){
cout << i << ' ';
}
cout << endl;
return 0;
}
示例15: chull
vector<Point> chull(const vector<Point>& pst){
vector<Point> points(pst);
vector<Point> lupper,llower,edges;
typedef vector<Point>::size_type vcs;
sort(points.begin(),points.end(),point_order_x);
vector<Point>::const_iterator it;
//Constructing the upper hull. The point with lowest x will be part of
//the hull
lupper.push_back(points[0]);
lupper.push_back(points[1]);
//Loop the rest of the points to obtain the upper hull
for(it=points.begin()+2;it!=points.end();++it){
lupper.push_back(*it);
//while size>2 and not a right turn
while ((lupper.size() > 2) && !iscw(lupper))
lupper.erase(lupper.end() - 2);
}
//Constructing the lower hull.
it = points.end()-1;
llower.push_back(*it);
llower.push_back(*(it-1));
for(it=points.end()-3;it>=points.begin();--it){
llower.push_back(*it);
//while size>2 and not a right turn
while ((llower.size() > 2) && !iscw(llower))
llower.erase(llower.end() - 2);
}
//First llower is already in lupper
copy(lupper.begin(),lupper.end(),back_inserter(edges));
copy(llower.begin()+1,llower.end(),back_inserter(edges));
return edges;
}