push-back Questions
10
Solved
vector<int> v;
v.push_back(1);
v.push_back(v[0]);
If the second push_back causes a reallocation, the reference to the first integer in the vector will no longer be valid. So this isn't safe...
Erbium asked 13/9, 2013 at 14:27
2
Solved
I thought that emplace_back would be the winner, when doing something like this:
v.push_back(myClass(arg1, arg2));
because emplace_back would construct the object immediately in the vector, whil...
Erupt asked 17/5, 2014 at 23:33
8
Solved
Currently when I have to use vector.push_back() multiple times.
The code I'm currently using is
std::vector<int> TestVector;
TestVector.push_back(2);
TestVector.push_back(5);
TestVector.push_...
4
Solved
I'm using GCC 9.2.0 and boost 1.55.
I have 2 vectors:
vector< pair< string, int > > source;
vector< string > dest;
I need to transform the source vector to the dest, such that it...
3
Solved
In generic code I was trying to tell an output iterator (in practice a std::back_inserter_iterator to move a range of elements. To my surprise it looked as if elements were moved in a move-to-back_...
2
Solved
I have found some very weird behaviour (on clang and GCC) in the following situation. I have a vector, nodes, with one element, an instance of class Node.
I then call a function on nodes[0] that ad...
Kepner asked 2/3, 2020 at 19:13
5
Solved
I'm currently studying the book Accelerated C++ (Koening/Moo) and I'm having trouble with one of the exercises. The task is to write a program which takes as an input some sequence of words which i...
Fakery asked 24/1, 2012 at 23:28
1
Solved
This is somewhat related to a previous question I asked regarding using emplace_back on a vector of pairs. emplace_back() vs push_back when inserting a pair into std::vector
Now my question pertai...
2
Solved
I have a class with a deleted move constructor and when I try to call std::vector::push_back() in MSVC (v.15.8.7 Visual C++ 2017) I get an error saying that I am trying to access the deleted move c...
Goldfinch asked 23/10, 2018 at 9:29
2
Solved
the following codes pushed back an std::array to a std::vector N times. Is there a more elegant and shorter way of doing this?
#include <iostream>
#include <vector>
#include <array&...
4
Solved
I am not sure what to make of this - please tell me what's wrong with the code below. I modified my code to reduce it to the simplest terms. There is a std::vector with a bunch of MyNode objects. T...
5
Solved
I want know how I can add values to my vector of structs using the push_back method
struct subject
{
string name;
int marks;
int credits;
};
vector<subject> sub;
So now how can I add ...
6
Solved
I'm designing a multilevel queue process simulator in C++ but I've got a problem when trying to implement several queues (my queues are vectors).So,
"multilevel" is a 4 elements array (not vector)....
Sachsse asked 5/4, 2013 at 16:13
4
Solved
This really is a question just for my own interest I haven't been able to determine through the documentation.
I see on http://www.cplusplus.com/reference/string/string/ that append has complexit...
2
Solved
Efficiency of C++11 push_back() with std::move versus emplace_back() for already constructed objects
In C++11 emplace_back() is generally preferred (in terms of efficiency) to push_back() as it allows in-place construction, but is this still the case when using push_back(std::move()) with an alrea...
Bauhaus asked 11/11, 2014 at 8:41
1
Solved
Just a little confusion I'm hoping someone can clear up - this question asks:
"Our getch and ungetch do not handle a pushed-back EOF correctly. Decide what their properties ought to be if an EOF is...
5
I'm sorry if this is a repeat question but I already tried to search for an answer and came up empty handed. So basically I just want to add strings (single words) to the back of a vector and then ...
3
Solved
I have a data-structure and a processor-class for the data, the data is stacked without pointers for faster SIMD processing:
struct trajectory_data {
float position[3];
float velocity[3];
float...
1
Solved
I came up with the following snipped but it looks quite hacky.
vector<int> collection;
collection.push_back(42);
int *pointer = &(*(collection.end()--));
Is there an easy way to get a ...
2
std::vector<std::vector< std::pair<int, int> > > offset_table;
for (int i = 0; i < (offset.Width()*offset.Width()); ++i)
{
offset_table.push_back( std::vector< std::pair...
3
Solved
I'm currently making an application using vectors with C++.
I know how pre-optimization is the root of all evil.
But I really can't help being curious.
I'm adding parts of other vectors into ano...
0
I've been scratching my head for far too long, I'm finding using MPL very difficult to get around and hoping somebody can get me started. Here is some partial code from a class I am developing whic...
1
Solved
I know the standard specifies that it is for vectors, but what about strings?
Coexecutor asked 15/12, 2012 at 14:18
3
Solved
Possible Duplicate:
What is The Rule of Three?
I have the a problem of the double freeing of memory in the following program.
The debugger shows that the issue is in the push_back() ...
7
Solved
My question is regarding the effect of vector::push_back, I know it adds an element in the end of the vector but what happens underneath the hood?
IIRC memory objects are allocated in a sequential...
1 Next >
© 2022 - 2025 — McMap. All rights reserved.