Questions tagged [stdcopy]

17 questions
4
votes
2 answers

Is it possible to use `std::copy` to copy values from a variable-sized array to a container?

Following is a MergeSort implementation. My problem is that the compiler complains that std::begin cannot be applied on a variable-sized array temp in order to further use std:copy. I am using C++17 and gcc 8.3. template
Sherry
  • 253
  • 1
  • 7
3
votes
1 answer

Is there a standard library equivalent of memmove?

The standard library offers std::copy, which can be seen as a generalization/generification of C's memcpy(). It also maintains the requirement of memcpy(), for the range [first, last) to be disjoint from the range [d_first , d_first +…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
2 answers

std::copy, std::copy_backward and overlapping ranges

My references are to std::copy and std::copy_backward. template< class InputIt, class OutputIt > OutputIt copy( InputIt first, InputIt last, OutputIt d_first ); Copies all elements in the range [first, last) starting from first and proceeding…
Vinod
  • 925
  • 8
  • 9
1
vote
2 answers

C++ How to copy a part of vector into array?

I was making a copy from a large dynamic array to a small fixed size array. for (int i = 0; i <= dumpVec.size() - 16; i++) { copy(dumpArr + i, dumpArr + i + 16, temp); // to copy 16 bytes from dynamic array } But I should use a vector instead…
user19465844
1
vote
1 answer

Copying the vector elements into std::array

I have a vector of elements of type uint8 which I am copying into one std::array. After some operations again I need to copy the elements from std::array to a vector.Please find the code…
goodman
  • 424
  • 8
  • 24
0
votes
1 answer

Using boost::counting_iterator with an existing vector?

At the moment I am doing this: const int n = 13; std::vector v(boost::counting_iterator(0), boost::counting_iterator(n + 1)); std::copy(v.begin(), v.end(), back_inserter(m_vecAssignmentIndex)); m_vecAssignmentIndex is defined liek…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
3 answers

Protobuf Partially Copy vector into repeated filed

In this question, it is answered how a vector can be copied into a repeated field by using fMessage.mutable_samples() = {fData.begin(), fData.end()}; ( and the other direction works too ). But how about a partial copy? Would the below…
Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46
0
votes
0 answers

Is copying a range from a container to itself safe or yields runtime error?

Why in C++ primer is said that we cannot insert to a container a range denoted by iterators to the same range (of the container itself)? std::list slist{"hi", "there!"}; slist.insert(slist.cbegin(), slist.cbegin(), slist.cend()); for(auto…
Itachi Uchiwa
  • 3,044
  • 12
  • 26
0
votes
1 answer

Using std::copy with LPTSTR type argument

I'm using Win32 API and I need to copy arguments captured with argv, the problem is, the code has to be compliant with both ASCII and UNICODE and that's a problem with C/C++ in Windows. Beyond that I must use, when possible, C++ instead of C, so I'm…
anastaciu
  • 23,467
  • 7
  • 28
  • 53
0
votes
0 answers

C++ copy multiple vectors using multi-threading

I have an array containing vectors std::vector A[10]; I want to copy all the values from all the vectors from array A to another vector of integers B using multithreading std::vector B; In order to do that in multithreading, I have an…
Nik
  • 113
  • 1
  • 5
0
votes
1 answer

initializing a vector from an initializer_list generates an unclear compilation error

This code compiles if the std::copy is commented out, and the atc initializer is uncommented. class MyClass { MyClass( OtherClass* poc_in, std::initializer_list iltc) : poc( poc_in) //, atc(iltc) { std::copy(…
Swiss Frank
  • 1,985
  • 15
  • 33
0
votes
1 answer

Different results when trying to use std::copy() with std::back_inserter to read from std::cin

When I was writing this answer, I was trying to scan a space-separated input string and store it in a vector. A user suggested the use of std::back_inserter and std::copy() to accept the input, over usage of…
kesarling He-Him
  • 1,944
  • 3
  • 14
  • 39
0
votes
2 answers

Is std::copy implemented to use multiple threads?

I would like to copy one vector into another as fast as possible. One method is using std::copy : std::copy(other_vector().begin(),other_vector().end(),this_vector.begin()); But since the vectors are quite long I was wondering if the std::copy…
Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46
0
votes
2 answers

Using c++ std::copy on an array of structure

I want to use std::copy to copy an existing array of structures to new one. A regular option is fine with '''local_copy()'''. I want to know the procedure to use std::copy for such case described below - I tried the code and get following error at…
dhairya
  • 431
  • 1
  • 4
  • 12
0
votes
0 answers

Is there a lower cost operation than std::copy to copy a uint8_t* data to a vector of type uint8_t?

Recently I wrote a c++ code and I used a function from an external library. the type of one of the arguments of this function is std::vector, but my data is in a variable named payload, which it's type is const uint8_t*. so I copied my payload data…
Saeed
  • 159
  • 3
  • 13
1
2