tagged [stl]
C++ Double Address Operator? (&&)
C++ Double Address Operator? (&&) I'm reading STL source code and I have no idea what `&&` address operator is supposed to do. Here is a code example from `stl_vector.h`: Does "Address of Address" mak...
- Modified
- 19 Apr at 00:0
C++ STL Vectors: Get iterator from index?
C++ STL Vectors: Get iterator from index? So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need to copy just a chunk of the vector. It looks like `vector.inser...
How to update std::map after using the find method?
How to update std::map after using the find method? How to update the value of a key in `std::map` after using the `find` method? I have a map and iterator declaration like this: I'm using the map to ...
- Modified
- 14 Mar at 11:14
What does iterator->second mean?
What does iterator->second mean? In C++, what is the type of a `std::map::iterator`? We know that an object `it` of type `std::map::iterator` has an overloaded `operator ->` which returns a `std::pair...
STL like container typedef shortcut?
STL like container typedef shortcut? A common pattern with STL containers is this: So in order to avoid writing the declaration of the template parameters we can do this somewhere: But if this map is ...
What is the preferred/idiomatic way to insert into a map?
What is the preferred/idiomatic way to insert into a map? I have identified four different ways of inserting elements into a `std::map`: Which of those is the preferred/idiomatic way? (And is there
Best way to extract a subvector from a vector?
Best way to extract a subvector from a vector? Suppose I have a `std::vector` (let's call it `myVec`) of size `N`. What's the simplest way to construct a new vector consisting of a copy of elements X ...
How to find if a given key exists in a C++ std::map
How to find if a given key exists in a C++ std::map I'm trying to check if a given key is in a map and somewhat can't do it: ``` typedef map::iterator mi; map m; m.insert(make_pair("f","++--")); pair ...
- Modified
- 31 Oct at 07:53
c++ exception : throwing std::string
c++ exception : throwing std::string I would like to throw an exception when my C++ methods encounter something weird and can't recover. Is it OK to throw a `std::string` pointer? Here's what I was lo...
How to iterate through a list of objects in C++?
How to iterate through a list of objects in C++? I'm very new to C++ and struggling to figure out how I should iterate through a list of objects and access their members. I've been trying this where `...
Use the auto keyword in C++ STL
Use the auto keyword in C++ STL I have seen code which use vector, ``` vectors; s.push_back(11); s.push_back(22); s.push_back(33); s.push_back(55); for (vector::iterator it = s.begin(); it!=s.end(); i...
Do I need to check capacity before adding an element to a vector in c++?
Do I need to check capacity before adding an element to a vector in c++? I am a newbie to c++ STL vectors so sorry for silly questions in advence. :) In my program, I have a vector which needs to stor...
How to initialize std::vector from C-style array?
How to initialize std::vector from C-style array? What is the cheapest way to initialize a `std::vector` from a C-style array? Example: In the following class, I have a `vector`, but due to outside re...
Why can't I make a vector of references?
Why can't I make a vector of references? When I do this: Everything works great. However, when I make it a vector of references instead: I get horrible errors like > error C2528: 'pointer' : pointer t...
- Modified
- 18 Nov at 20:15
use std::fill to populate vector with increasing numbers
use std::fill to populate vector with increasing numbers I would like to fill a `vector` using `std::fill`, but instead of one value, the vector should contain numbers in increasing order after. I tri...
Is it more efficient to copy a vector by reserving and copying, or by creating and swapping?
Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? I am trying to efficiently make a copy of a vector. I see two possible approaches: ``` std::vector copyVecF...
C++ Erase vector element by value rather than by position?
C++ Erase vector element by value rather than by position? and lets say the values in the vector are this (in this order): If I wanted to erase the element that contains the value of "8", I think I wo...
- Modified
- 25 Apr at 15:40
C++ std::transform() and toupper() ..why does this fail?
C++ std::transform() and toupper() ..why does this fail? I have 2 std::string. I just want to, given the input string: 1. capitalize every letter 2. assign the capitalized letter to the output string....
How do you copy the contents of an array to a std::vector in C++ without looping?
How do you copy the contents of an array to a std::vector in C++ without looping? I have an array of values that is passed to my function from a different part of the program that I need to store for ...
Comparison of C++ STL collections and C# collections?
Comparison of C++ STL collections and C# collections? I'm still learning C# and was surprised to find out that a `List` is much more like a `std::vector` than a `std::list`. Can someone describe all t...
- Modified
- 23 May at 12:9
Find-or-insert with only one lookup in C# Dictionary
Find-or-insert with only one lookup in C# Dictionary I'm a former C++/STL programmer trying to code a fast marching algorithm using C#/.NET technology... I'm searching for an equivalent of STL method ...
- Modified
- 30 Dec at 02:30
Using std::bind2nd with references
Using std::bind2nd with references I have a simple class like this: But when I compile the code I get the following
How can I expose iterators without exposing the container used?
How can I expose iterators without exposing the container used? I have been using C# for a while now, and going back to C++ is a headache. I am trying to get some of my practices from C# with me to C+...
- Modified
- 1 Oct at 10:2
How do I sort a vector of pairs based on the second element of the pair?
How do I sort a vector of pairs based on the second element of the pair? If I have a vector of pairs: Is there and easy way to sort the list in order based on the second element of the pair? I know I ...