3,092 questions
0 votes
0 answers
166 views
Can a segfault occur if you are doing iterator arithmetic ops beyond limits?
it -> a random valid vector iterator const int kLookAheadIndex -> a random number auto it_ahead = std::max(it - kLookAheadIndex, path.cbegin()); // get a look-ahead point to look at I know ...
0 votes
1 answer
103 views
Using tbb::parallel_for with reserve and emplace does not copy all elements between std::vectors
I am trying to populate a std::vector container using another std::vector and tbb::parallel_for method as shown in the following code snippet: #include <tbb/parallel_for.h> #include <eigen3/...
2 votes
2 answers
194 views
How to return a list of selected elements of some underlying container in a typesafe manner?
Im wondering if there is a better, more typesafe, way to return "a selection" than I do at the moment. If we only ever have one selected element at a time, we can just return a reference, ...
3 votes
1 answer
252 views
Copying and Padding a Vectors rows quickly
System is: Ubuntu Linux 20.04.6 LTS g++ version 9.4.0 IDE QTCreator I have two vectors (set and subset), subset needs to be transferred into set, at location (0,0), such that, the rows are padded ...
4 votes
2 answers
185 views
"no matching function for call" in initialiser list for char [] [duplicate]
I have the below code. The first push_back fails, the second, with a constant string, works. #include <vector> #define MAX_LENGTH 10 struct bar { int barInt; char barChar [...
1 vote
0 answers
57 views
What is the category of transform view based on vector? [duplicate]
What is the category of std::views::transform based on a std::vector? What is the category of the view's iterator in the following code? #include <iterator> #include <memory> #include <...
0 votes
1 answer
189 views
Removing an element from a map of vectors
std::map<unsigned long, std::vector<Foo*> > fKeys = myObject->GetFoo(); for (auto it = fKeys.begin(); it != fKeys.end() && !found; ++it) for (auto it1 = 0; it1 < (*it)....
-2 votes
2 answers
260 views
Is there a better way to keep ids in a vector sequential in C++?
I have a simple C++ program that manages as a todo list. The Todo, class contains a vector of Item to track each todo action and their id. The key constraint is that the ids must be kept strictly ...
4 votes
2 answers
220 views
Can the back() iterator of a vector be safely assumed to be the end() iterator after a pop_back()?
My problem is the following : std::vector<struct pollfd> vec = { ... }; // Actually a member variable on a Server object for (auto iter = vec.begin(); iter != vec.end(); ) { if (...
-3 votes
1 answer
238 views
Why can't the compiler deduce the element type of `std::vector`?
I want to use auto more in my code and came up with the following example: #include <vector> int main() { auto v{std::vector{}}; for (auto i{0}; i < 10; i++) { v.push_back(i)...
3 votes
2 answers
111 views
How to instantiate std::vector using decltype?
This is my test code: #include<vector> #include<iostream> #include<type_traits> using std::vector; using std::is_same_v; using std::cout; using std::endl; int func() { struct ...
7 votes
1 answer
250 views
Directly initialize std::array with a fixed count of elements from std::vector [duplicate]
The elements in the array are not default constructible therefore we need to initialize the array directly from elements in std::vector. #include <array> #include <vector> class foo { ...
3 votes
1 answer
174 views
Alignment for vector of vectors in C++ templated type
In C++, what is the shortest way to declare a vector of vectors, where each inner std::vector's metadata fields (importantly size and pointer) have a user-chosen alignment? Ideally I'd be able to ...
12 votes
1 answer
1k views
Unable to std::format std::vector<std::unique_ptr<int>> in C++
I defined a formatter for std::unique_ptr<T> in my code, but when I try to print a std::vector<std::unique_ptr<int>>, I am getting the following compiler error: std::...
0 votes
0 answers
74 views
confusion converting gdiplus code to use <vector> [duplicate]
This is a continuation of a previous discussion here... I'm trying to convert an existing GDI+ practice program to use for the various GDI+ objects... So the existing (working) code is this: ...