Is it valid to compare iterators which are got from the container separately?
For example, it this expression valid in semantic? container.begin() == container.begin(); ...
For example, it this expression valid in semantic? container.begin() == container.begin(); ...
Could someone tell me why the following won't compile? #include "a.h" #include <list> #include <algorithm> #include <tr1/functional> using namespace std; class B { public: B() { list< A* > aList; A* a = new A(); lower_bound( aList.begin(), aList.end(), a, tr1::bind( &B::aComp, tr1::placeholders::_1, tr1::placeh...
Possible Duplicate: Which sorting algorithm is used by STLs list::sort()? Which sorting algorithm can be used for sorting std::list ? ...
Hi all do you know if it is any difference in performance when I access a std::map element using find or operator []? One returns an iterator and the other a const ref to the object. Which one might be quicker becuase of all of the behind the scene of the STL? Regards AFG ...
I want to inline a lambda expression since it is very short for performance reason. Is it possible? ...
I have a function A that accepts a predicate function as its argument. I have another function B and it takes a char and returns an int, and a function C that accepts int and returns a bool. My question is how to bind B and C to pass it to function A. Something like: A(bindfunc(B,C)) I know boost::bind works but i am looking for ...
I'm self-learning how to create generic functions using iterators. As the Hello World step, I wrote a function to take the mean in the given range and returns the value: // It is the iterator to access the data, T is the type of the data. template <class It, class T> T mean( It begin, It end ) { if ( begin == end ) { throw...
So according to the link here: http://www.cplusplus.com/reference/algorithm/max_element/ , the max_element function is O(n), apparently for all STL containers. Is this correct? Shouldn't it be O(log n) for a set (implemented as a binary tree)? On a somewhat related note, I've always used cplusplus.com for questions which are easier to a...
We have a function that, when tested using MS VC++ 2008 using omniorb CORBA libraries causes an orphaned iterator error. If we recompile all of our source using the _HAS_ITERATOR_DEBUGGING=0, the error goes away. I cannot paste the exact code, but here is a facsimile: void funtion(CORBA::ANY& blah) { sometype::iterator itr; try...
I have a typedef, a class with a member vector using that type and then a method using std::<vector>::erase(). #typedef DWORD WordNo_t; class CWordList : public CObject { public: WordNo_t* begin() { return m_Words.begin(); } WordNo_t* end() { return m_Words.end(); } void truncate (WordNo_t *Ptr) { if (Ptr == end()) return; AS...
suppose you need to implement container of a T items, which its value could be retrieved by numeric index (which is random access) and by name (as string). which one is better in term of performance of common operation such as retrieval, adding, and removing the items: (in this case retrieval by index need to be implemented by walking...
Goal here is to merge multiple arrays which are already sorted into a resultant array. I've written the following solution and wondering if there is a way to improve the solution /* Goal is to merge all sorted arrays */ void mergeAll(const vector< vector<int> >& listOfIntegers, vector<int>& result) { int totalNumbers = listOf...
Say I have 2 containers storing pointers to the same objects... std::list<Foo*> fooList; std::vector<Foo*> fooVec; Lets say I remove an object from one of these containers via one if its methods, for example... std::vector<Foo*>::iterator itr = std::find( fooVec.begin(), fooVec.end(), pToObj ); fooVec.erase( itr ); CppReference ...
Lets say I have some kind of collection an I obtained an iterator for the beginning of it. Now lets say I modified the collection. Can I still use the iterator safely? (regardless of the type of the collection or the iterator) To avoid confusion , Here is the order of operations I talk about: Get an iterator of the collection. Modify ...
From Effective C++, Item 3 /* case1 */ const std::vector<int>::iterator i // i acts like a T* const /* case2 */ std::vector<int>::const_iterator ci // ci acts like a const T* To remember how const applies, I used to remember the following from this article Basically ‘const’ applies to whatever is on its immediate left (other t...
Suppose I have some data stored in a container of unique_ptrs: struct MyData { int id; // a unique id for this particular instance data some_data; // arbitrary additional data }; // ... std::vector<std::unique_ptr<MyData>> my_data_vec; The ordering of my_data_vec is important. Suppose now I have another vector of IDs of My...
Hallo! I want to specialize std::max for a platform-specific fraction type. The prototype for the system-specific max I want to use looks like this: fract builtin_max(fract a, fract b); My idea for a specialized std::max looks like this: template <> inline const fract& std::max<fract>(const fract& a, const fract& b) { return bui...
This is a follow-up on a previous question I had ( http://stackoverflow.com/questions/3313301/complexity-of-stl-max-element ). I want to basically pop the max element from a set, but I am running into problems. Here is roughly my code: set<Object> objectSet; Object pop_max_element() { Object obj = *objectSet.rbegin(); set<Obj...
Is there any principle to choose one over another between hash_map and map in STL? ...
I don't think I am the first one to think about this ... but would it be possible to write a STL allocator that manages VRAM/Buffer Objects(BO) in OpenGL? As a result of this Question I currently use vectors to write to and read from BOs. Additionally i use some templating to map BOs as almost anything i like. Like this: TypedBufferO...