I have the following issue related to iterating over an associative array of strings defined using std::map.
-- snip --
class something
{
//...
private:
std::map<std::string, std::string> table;
//...
}
In the constructor I populate table with pairs of string keys associated to string data. Somewhere else I have a method toS...
I have two maps:
map< string, list < string > > map1;
map< string, list < string > > map2;
I have populated map1, now I want to copy the map1 contents into map2. So I simply did:
I have some operation for that the map1 fills with
1. kiran, c:\pf\kiran.mdf, c:\pf\kiran.ldf
2. test, c:\pf\test.mdf, c:\pf\test.mdf
And now I have t...
I need a function which stablishes for my class a policy for displaying items. e.g:
SetDisplayPolicy(BOOLEAN_PRED_T f)
This is assuming BOOLEAN_PRED_T is a function-pointer to some boolean predicate type like:
typedef bool (*BOOLEAN_PRED_T) (int);
I'm interested only on e.g: display something when the passed predicate is TRUE, do n...
I am sure this would have been asked before but couldn't find it. Is there any built in (i.e. either using std::wstring's methods or the algorithms) way to case insensitive comparison the two wstring objects?
...
Hey,
I'm trying to optimize my C++ code. I've searched the internet on using dynamically allocated C++ arrays vs using std::vector and have generally seen a recommendation in favor of std::vector and that the difference in performance between the two is negligible. For instance here - http://stackoverflow.com/questions/381621/using-array...
What parts of STL (no boost or TR1, please) people still commonly use in their professional as well as personal environments, if any?
These days I find myself using the following:
Containers:
vector
set
map
Iterators:
const and not for above containers
Functional objects:
bind1st
bind2nd
Algorithms:
find
find_first_of
f...
The following function operates with two values for T. One is 4 bytes (same as a DWORD). The other is 64 bytes. The Buffer is designed to store objects in its cache, and have them retrieved at a later date.
When using the 64 byte structure, the total amount of time in the function jumps dramatically. The seek time in the vector, the...
I'm just trying to get more into stl semantics, and converting old loops over to algorithms where appropriate. I'm having trouble figuring out the best way to transform this loop into a call to copy. Any ideas?
vector< vector<float> > rvec;
const float * r[Max] = ...;
// ...
for (int ri=0; ri<N; ri++)
for (int ...
Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
I am writing a program where an iterator is used to loop through a std::vector. Somebody told me that doing ++it in the for statement leads to more efficient code. In other words, they are saying that:
for ( vector<string>::iterator it=my_vector.b...
I am considering a factory function to create different classes in the same hierarchy. I understand that normally a factory is normally implemented as follows:
Person* Person::Create(string type, ...)
{
// Student, Secretary and Professor are all derived classes of Person
if ( type == "student" ) return new Student(...);
if ...
I have
class A: public B { ...}
vector<A*> v;
I want to do
for_each(v.begin(), v.end(), mem_fun_deref(B::blah()));
(Actually I have:
vector<unique_ptr<A>>
but it shouldn't matter)
I need to upcast and call the member function.
...
i am using C++
say i want to store 40 records( usrnames) i will simply use array
if i want to store 40000 records ( usrnames) . i will search it sequentially
which data structure should i use?
any thoughts?
...
I have a structure called vertex and I created some pointers to them. What I want to do is add those pointers to a list. My code below, when it tries to insert the pointer into the list, creates a segmentation fault. Can someone please explain what is going on?
#include <iostream>
#include <list>
#define NUM_VERTICES 8
using namesp...
I'm looking for a container that maps from a double to object pointers. However, each key is simply a range of doubles that would correspond to that object.
For example, there could be a key/value pair that's <(0.0 3.0), ptr>, or <(3.5 10.0), ptr2>
container[1.0] should return ptr, container[3.0] should also return ptr, and container[-...
In the code below, why it is that when I take the address of a map index (which contains a list) and I take the address of the list itself, they both have different values.
See the code below for clarification.
#include <iostream>
#include <list>
#include <map>
using namespace std;
int main()
{
list<char> listA; //list of chars...
I was wondering if returning a list, instead of returning a pointer to one, was costly in term of performance because if I recall, a list doesn't have a lot of attributes (isn't it something like 3 pointers? One for the current position, one for the beginning and one for the end?).
...
I want to output my own object to a STL stream but with customized formatting. I came up with something like this but since I never used locale and imbue before I have no idea if this makes sense and how to implement MyFacet and operator<<.
So my questions are: does this make sense and how to implement MyFacet and operator<< ?
The foll...
Is there open source software that uses STL extensively?
...
In VS 2005, I have some code that looks like this:
ifs.open("foo");
while (!ifs.eof())
{
ifs.read(&bar,sizeof(bar));
loc = ifs.tellg();
loc += bar.dwHeaderSize;
// four byte boundary padding
if ((loc % 4) != 0)
loc += 4 - (loc % 4);
ifs.seekg(loc,ios::beg);
}
ifs.close();
The code worked fine in VS 2005...
Hi all! I think the question title is clear enough: is is possible to stable_sort() a std::list in C++? Or do I have to convert it to a std::vector?
I'm asking because I tried a simple example and it seems to require RandomAccessIterators, which a linked list doesn't have. So, how do I stable sort a std::list()?
EDIT: sample code that ...