本文整理匯總了C++中std::copy方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::copy方法的具體用法?C++ std::copy怎麽用?C++ std::copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::copy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: runtime_error
cheby_coeff::cheby_coeff(const mxArray *c_in){
if (!is_valid_input(c_in)){
throw std::runtime_error("cheby_coeff constructor called with invalid input");
}
s=mxGetNumberOfElements(c_in);
m=mxGetNumberOfElements(mxGetCell(c_in,0));
c.resize(s);
double *pr_tmp;
for (int ks=0;ks<s;ks++){
c[ks].resize(m);
pr_tmp=mxGetPr(mxGetCell(c_in,ks));
copy(pr_tmp,pr_tmp+m,c[ks].begin());
}
}
示例2: main
int main()
{
vector<string> p;
p.push_back("this is an");
p.push_back("example");
p.push_back("to");
p.push_back("illustrate");
p.push_back("framing");
ostream_iterator<string> ofile(cout, "\n");
copy(p.begin(), p.end(), ofile);
cout << endl;
vector<string> f = frame(p);
copy(f.begin(), f.end(), ofile);
cout << endl;
vector<string> h = hcat(frame(p), p);
copy(h.begin(), h.end(), ofile);
cout << endl;
return 0;
}
示例3: processNode
void AnalyzerManager::processNode(GNode* node, const vector<int>& context) {
string tag = "AnalyzerManager";
Logger::d(tag) << "analysis node " << node->getIndex() << endl;
copy(context.begin(), context.end(),
ostream_iterator<int>(Logger::d(tag), "->\n"));
if (mAnalyzersMap.find(node->getTreeCode()) != mAnalyzersMap.end()) {
//cout<<node->getTreeCode()<<endl;
vector<BaseAnalyzer*> &analyzerVector =
mAnalyzersMap[node->getTreeCode()];
for (vector<BaseAnalyzer*>::iterator itor = analyzerVector.begin();
itor != analyzerVector.end(); ++itor) {
(*itor)->analyzeNode(node, context);
}
}
}
示例4: main
int main() {
vector<int> vec{1, 2, 3, 4, 5, 6, 7, 8, 9};
vector<int> vec1, vec2;
list<int> lst;
auto it1 = back_inserter(vec1);
auto it2 = front_inserter(lst);
auto it3 = inserter(vec2, vec2.begin());
copy(vec.begin(), vec.end(), it1);
for (auto& x : vec1) {
cout << x << ' ';
}
cout << endl;
copy(vec.begin(), vec.end(), it2);
for (auto& x : lst) {
cout << x << ' ';
}
cout << endl;
copy(vec.begin(), vec.end(), it3);
for (auto& x : vec2) {
cout << x << ' ';
}
cout << endl;
return 0;
}
示例5: compose_name
// The output buffer should be at least 256 bytes long. This used to use
// a std::string but it worked about 50% slower, so this is somehow
// unsafe but a lot faster.
uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
const uint8_t* start_ptr = ptr;
const uint8_t* end = &records_data_[0] + records_data_.size();
const uint8_t* end_ptr = 0;
char* current_out_ptr = out_ptr;
while (*ptr) {
// It's an offset
if ((*ptr & 0xc0)) {
if (ptr + sizeof(uint16_t) > end) {
throw malformed_packet();
}
uint16_t index;
memcpy(&index, ptr, sizeof(uint16_t));
index = Endian::be_to_host(index) & 0x3fff;
// Check that the offset is neither too low or too high
if (index < 0x0c || (&records_data_[0] + (index - 0x0c)) >= end) {
throw malformed_packet();
}
// We've probably found the end of the original domain name. Save it.
if (end_ptr == 0) {
end_ptr = ptr + sizeof(uint16_t);
}
// Now this is our pointer
ptr = &records_data_[index - 0x0c];
}
else {
// It's a label, grab its size.
uint8_t size = *ptr;
ptr++;
if (ptr + size > end || current_out_ptr - out_ptr + size + 1 > 255) {
throw malformed_packet();
}
// Append a dot if it's not the first one.
if (current_out_ptr != out_ptr) {
*current_out_ptr++ = '.';
}
copy(ptr, ptr + size, current_out_ptr);
current_out_ptr += size;
ptr += size;
}
}
// Add the null terminator.
*current_out_ptr = 0;
if (!end_ptr) {
end_ptr = ptr + 1;
}
return end_ptr - start_ptr;
}
示例6: main
int main()
{ // demonstrate match_results::format
string result("The URL '");
string tail("' was found.");
regex rgx("http://([^/: ]+)");
string text("The site http://www.petebecker.com has"
" useful information.");
smatch match;
if (regex_search(text, match, rgx))
{ // show result of successful match
copy(tail.begin(), tail.end(),
match.format(back_inserter(result), "$&"));
cout << result << '\n';
}
return 0;
}
示例7: main
int main()
{
istream_iterator<int>int_it(cin); //reads ints from cin
istream_iterator<int>int_eof; //end iterator value
vector<int>v(int_it, int_eof); //initialize v by reading cin
sort(v.begin(), v.end());
ostream_iterator<int>out(cout, " "); //writes ints to cout
unique_copy(v.begin(), v.end(), out); //write unique elements to cout
cout << endl; //write a newline after the output
ofstream out_file("data"); //writes int to named file
ostream_iterator<int>out_iter(out_file, " ");
copy(v.begin(), v.end(), out_iter);
out_file << endl; //write a newline at end of the file
getchar();
}
示例8: assert
T*
newCopy(const T *src, size_t src_size, size_t dest_size)
{
assert(dest_size >= src_size);
T *dest = new T[dest_size];
try
{
copy(src, src + src_size, dest);
}
catch (...)
{
delete[] dest;
throw;
}
return dest;
}
示例9:
DocumentInfo& DocumentInfo::operator=(const DocumentInfo& other)
{
if (this != &other)
{
m_title = other.m_title;
m_location = other.m_location;
m_type = other.m_type;
m_language = other.m_language;
m_timestamp = other.m_timestamp;
m_labels.clear();
copy(other.m_labels.begin(), other.m_labels.end(),
inserter(m_labels, m_labels.begin()));
}
return *this;
}
示例10: first_permutation
void first_permutation(int idx){
char p[16]={};
char pp[16]={};
for ( int i=0; i<len; ++i )
p[i] = i;
for ( int i=len-1; i>0; --i ) {
int d = idx / fact[i];
count[i] = d;
idx = idx % fact[i];
copy( &p[0], &p[i+1], &pp[0] );
for ( int j=0; j<=i; ++j ){
p[j] = j+d <= i ? pp[j+d] : pp[j+d-i-1];
}
}
this->p.assign(p, 16);
}
示例11: URI
/**
* @brief Converts a url into a local filename.
*
* @retval fn a character buffer to hold the local filename.
* @param nfn the number of elements in the buffer @p fn points to.
*/
bool doc2::filename(char * fn, const size_t nfn) {
using std::copy;
using std::string;
fn[0] = '\0';
const char * s = 0;
const std::string protocol = this->url_protocol();
if (protocol == "file") {
# ifdef _WIN32
string name = URI(this->url_).getPath().substr(1);
# else
string name = URI(this->url_).getPath();
# endif
size_t len = (name.length() < (nfn - 1))
? name.length()
: nfn - 1;
copy(name.begin(), name.begin() + len, fn);
fn[len] = '\0';
return true;
} else if (protocol == "http") {
//
// Get a local copy of http files.
//
if (this->tmpfile_) { // Already fetched it
s = this->tmpfile_;
} else if ((s = the_system->http_fetch(this->url_.c_str()))) {
tmpfile_ = new char[strlen(s)+1];
strcpy(tmpfile_, s);
free(const_cast<char *>(s)); // assumes tempnam or equiv...
s = tmpfile_;
}
}
// Unrecognized protocol (need ftp here...)
else {
s = 0;
}
if (s) {
strncpy( fn, s, nfn-1 );
fn[nfn-1] = '\0';
}
return s && *s;
}
示例12: explode_by_first_of
void explode_by_first_of(const std::string& text, const std::string& separator, std::vector<std::string>& results) {
std::string::size_type found;
std::string copy(text);
do {
found = copy.find_first_of(separator);
if(found > 0){
results.push_back(copy.substr(0, found));
}
copy = text.substr(found + 1);
}
while(found != std::string::npos);
if(results.empty()) {
results.push_back(text);
}
return;
}
示例13: main
int main(int argc, const char * argv[]) {
ifstream in(argv[1]);
vector<string> lines;
copy(istream_iterator<string>(in),
istream_iterator<string>(),
back_inserter(lines));
in.close();
for(int i = 0; i < lines.size(); ++i){
cout << sumOfDigits(strToInt(lines[i])) << "\n";
}
return 0;
}
示例14: explode
void explode(const string& text, const string& separator, vector<string>& results) {
string::size_type found;
string copy(text);
const string::size_type separator_size = separator.length();
do {
found = copy.find(separator);
if(found > 0){
results.push_back(copy.substr(0, found));
}
copy = copy.substr(found + separator_size);
}
while(found != string::npos);
if(results.empty()) {
results.push_back(text);
}
return;
}
示例15: handleRequest
void Server::handleRequest(shared_ptr<tcp::socket> socket, Logger log) {
// ProfilerStart("/home/sowa/local_workspace/pje/log/server.perf");
Server* server = this;
vector<char> buffer(1024*1024);
error_code error;
socket->read_some(boost::asio::buffer(buffer), error);
string request(buffer.size(), 0);
copy(buffer.begin(), buffer.end(), request.begin());
string remoteIp = socket->remote_endpoint().address().to_string();
log.info("received request from " + remoteIp);
string query = server->retrieveQuery(request);
log.debug("query: \"" + query + "\"");
string command = server->retrieveCommand(query);
StrStrMap args = server->retrieveArgs(query, server->workDir());
string argsString = "{";
for (StrStrMap::const_iterator i = args.begin();
i != args.end();
++i) {
argsString += i->first + ": " + i->second + ", ";
}
argsString = argsString.substr(0, argsString.size() - 2);
argsString += "}";
log.info("executing command <" + command + "> with args " + argsString);
int tries = 10;
while (tries) {
try {
Command::execute(*server, socket, command, args, log);
tries = 0;
} catch(const std::bad_alloc&) {
--tries;
if (tries) {
_log.error("not enough memory to complete task: retrying");
boost::this_thread::sleep(boost::posix_time::seconds(3));
} else {
_log.error("not enough memory to complete task: giving up");
}
}
}
socket->close();
// ProfilerStop();
}