It appears to from my simple testing but I'm wondering if this is guaranteed?
Are there conditions where the ordering will be not be guaranteed?
Edit: The case I'm particularly interested in is if I populate a map with a large number of entries, will the order of the itertator be the same across multiple runs of my executable? What if ...
i have code like this
string xml_path(conf("CONFIG"));
xml_path+=FILE_NAME;
Where,
conf function returns char * and FILE name is const char *
I want to combine it to one line like
xml_path(conf("CONFIG")).append(FILE_NAME)
how do i do it?
any suggestions ??
...
I've setup a std map to map some numbers, at this point I know what numbers I'm mapping from an to, eg:
std::map<int, int> myMap;
map[1] = 2;
map[2] = 4;
map[3] = 6;
Later however, I want to map some numbers to the lowest number possilbe that is not in the map, eg:
map[4] = getLowestFreeNumberToMapTo(map); // I'd like this to return...
In a C++ program I write:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> a;
a.resize(1);
for( int i = 0 ; i < 10 ; i++ ) {
cout << a[i] << " ";
}
return 0;
}
this program prints the correct value of a[0] (because it is allocated) but also prints values at the rest of the 10 lo...
What exactly must I replace ??? with to get the iterator (it) to some element (for example Base(2)) ?
I tried a few shots but nothing, compiler just says that it is wrong.
Here is code
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class Base
{
public:
Base(int a) {ina = a;}
~Base() {}
...
I have a function that reads lines from a log file, converts these lines to a certain class and returns a STL list of instances of this class.
My question is: how should I declare this function so that the whole list is NOT copied when attributing it to the caller? Without loss of generality, assume:
list<Request> requests = log_manipu...
I see this in the standard C++ libraries for my system, as well as some of the headers in a library I'm using.
What are the semantics of these two definitions? Is there a good reference for #defines like this other than the source itself?
...
When is using a std::set more efficient (w.r.t. time) than using a std::vector along with make_heap/push_/pop_ for the priority queue in an A* operation? My guess is that if the vertices in the open list are small, using a vector is a better option. But does anyone have experience with this?
...
I'm having some trouble in declaring a STL Set of pointers to class instances. More specifically, I have this scenario:
class SimulatedDiskFile {
private:
// ...
public:
// ...
struct comparator {
bool operator () (SimulatedDiskFile* const& file_1, SimulatedDiskFile* const& file_2) {
return ((*file_1)->getF...
Hi Guys I want to know what is the difference between thread safe Data and Thread Safe Containers
...
Hi all! I have the following functor:
class ComparatorClass {
public:
bool operator () (SimulatedDiskFile * file_1, SimulatedDiskFile * file_2) {
string file_1_name = file_1->getFileName();
string file_2_name = file_2->getFileName();
cout << file_1_name << " and " << file_2_name << ": ";
if (file_1_name <...
I was wondering why the vector templates perform two allocations, when only one seems to be
necessary.
For example this:
#include <vector>
#include <iostream>
class A {
public:
A(const A &a) {
std::cout << "Calling copy constructor " << this << " " << &a << "\n";
}
A() {
std::cout ...
Let's say I have a CString variable carrying the string "Bob Evans". I want to copy from position 4 until the end of the original CString to a new CString, but I am having trouble finding semantics examples for this:
CString original("Bob Evans");
// Below is what I'm trying to do
// CString newStr = original.copy(4, original.GetLength(...
I have a list iterator that goes through a list and removes all the even numbers. I can use the list iterator to print out the numbers fine but I cannot use the list's remove() and pass in the dereferenced iterator.
I noticed that when the remove() statement is in effect, *itr gets corrupted? Can somebody explain this?
#include <iostre...
I'm writing a little Python extension in C/C++, and I've got a function like this:
void set_parameters(int first_param, std::list<double> param_list)
{
//do stuff
}
I'd like to be able to call it from Python like this:
set_parameters(f_param, [1.0, 0.5, 2.1])
Is there a reasonably easy way to make that conversion? Ideally, I'd ...
If the value of an element in a set changes the ordering may be no longer correct. As illustrated in this little program:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
struct Comp
{
bool operator()(const std::string * lhs, const std::string * rhs)
{
return *lhs < *rhs;
}
};
int main()
{
...
How does STL algorithm work independent of Iterator type?
...
std::string str;
std::stringstream strm(str);
I get this error:
Error 11 error C2248:
'std::basic_ios<_Elem,_Traits>::basic_ios'
: cannot access private member
declared in class
'std::basic_ios<_Elem,_Traits>' c:\program
files\microsoft visual studio
9.0\vc\include\sstream 517
If I use istringstream, same happens...
I am developing a program where I find myself doing this like this a lot:
void Model::SetCollideMode( const std::string &m )
{
Body *body;
std::map<std::string, Body* >::iterator iter;
for (iter=this->bodies.begin(); iter!=this->bodies.end(); iter++)
{
body = iter->second;
body->SetCollideMode( m );
}
}
I have sev...
Lets say I have hierarchy like this (This is just a test program. Please do not point anything related to memory leaks, destructor is not virtual etc):
class I
{
public:
virtual void fun(int n, int n1) = 0;
};
class A : public I
{
public:
void fun(int n, int n1)
{
std::cout<<"A::fun():" <<n<<" and n1:" <<n1<<"\n";
...