stl

Can we split, manipulate and rejoin a string in c++ in one statement?

Hello, This is a bit of a daft question, but out of curiousity would it be possibly to split a string on comma, perform a function on the string and then rejoin it on comma in one statement with C++? This is what I have so far: string dostuff(const string& a) { return string("Foo"); } int main() { string s("a,b,c,d,e,f"); vect...

error C2664 : 'void std::vector<_Ty>::push_back(_Ty&&)': cannot convert parameter 1 from 'Node<T> *' to 'Node<T>&&'

error C2664 : 'void std::vector<_Ty>::push_back(_Ty&&)': cannot convert parameter 1 from 'Node *' to 'Node&&' please I need help... I created node.h & heap.h node.h : #ifndef __NODE_H_ #define __NODE_H_ #include <string> #include <iostream> using namespace std; template <class T> class Node { private: Node<T>* m_brother; int...

How to call a member function on a parameter with std::for_each and boost::bind?

I want to add a series of strings to a combo box using std::for_each. The objects are of type Category and I need to call GetName on them. How can I achieve this with boost::bind? const std::vector<Category> &categories = /**/; std::for_each(categories.begin(), categories.end(), boost::bind(&CComboBox::AddString, &comboBox, _1); The c...

Storing and retrieving multiple keys in C++

I have a few integer keys that is needed to retrieve a value. What is the most efficient way to store and retrieve the value based on the keys? Currently I am converting and combining the three keys into a single string and store the key-value pair in a map. However, I think there should be a more efficient way of doing that based on t...

Does map::iterator yield lvalues ?

In other words, when i is a map<K,V>::iterator, do the following provide the expected semantics (ie. it modifies the map): *i = make_pair(k, v); i->first = k; i->second = v; ? Update: The first two lines are invalid, since the return value of operator* is (convertible to?) a pair<const K, V>. What about the third line ? Assuming a y...

Deleting objects from template list

Hi All, I have a template list say, List<SuperClass*>* mList; for(int i = 0;i < mList->ElementsCount();i++) mList->DeleteElementAtIndex(i); in mList objects of subclasses are added. while on deleting object from the list, should i need to convert the object into corresponding subclasses and call delete method ...

std::map clear() performance in debugger?

The attached, trivial, test program tests the performance of emptying a simple std::map. Using MSVC 2008 and 2010, the debug build will take <30seconds when executed from a command prompt but almost 3 minutes when executed from within the debugger. The call to clear() is entirely responsible for the difference. If I break into the debugg...

std::pair of references

Hello Is it valid to have a std::pair of references ? In particular, are there issues with the assignment operator ? According to this link, there seems to be no special treatment with operator=, so default assignement operator will not be able to be generated. I'd like to have a pair<T&, U&> and be able to assign to it another pair (o...

How to use an unknown (int-like) type as index into std::vector?

I'm using a type Id which is defined in another part of the code I'm using: typedef int Id; Now I am provided many objects, each of which comes with such an Id, and I would like to use the Id as index into a std::vector that stores these objects. It may look something like this: std::vector<SomeObj*> vec(size); std::pair<Id, SomeObj*...

STL Map Value Constructors

I have a class X that I would like to put into an STL map of type std::map. An STL map needs to have X stored in memory somewhere so I'm looking for an efficient (run time and memory) way to create X and store it in the map. I noticed that the following code where x is an object of type X and stlMap is a map of type std::map: stlMap[...

Is this use of nested vector/multimap/map okay?

I am looking for the perfect data structure for the following scenario: I have an index i, and for each one I need to support the following operation 1: Quickly look up its Foo objects (see below), each of which is associated with a double value. So I did this: struct Foo { int a, b, c; }; typedef std::map<Foo, double> VecElem; std...

C++: mixture between vector and list: something like std::rope?

Hi, When storing a bunch of items and I don't need random access to the container, I am using an std::list which is mostly fine. However, sometimes (esp. when I just push back entries to the back and never delete somewhere in the middle), I wish I had some structure with better performance for adding entries. std::vector is bad because...

How to do binary search in a std::multiset without constructing a key_type object?

I have a container like this: // Sort functor struct SortByTime : std::binary_function<const TimeSortableData &, const TimeSortableData &, bool> { bool operator()(const TimeSortableData & a, const TimeSortableData & b) const { return a.GetTime() < b.GetTime(); } }; // Container that sorts by time typedef std::mult...

Intersection of two STL maps

Given that I have two STL maps, say: map<int, double> A; map<int, double> B; I'd like to get the intersection of the two maps, something of the form: map<int, pair<double,double> > C; Where the keys are the values in both A and B and the value is a pair of the values from A and B respectively. Is there a clean STL-like way to go ab...

Using "unique()" on a vector of vectors in C++

I hope this is not a duplicate question, but if it is, feel free to point me in the right direction. I have a vector<vector<int> >. Is it possible to use unique() on this? Something like: vector<vector<int> > myvec; //blah blah do something to myvec vector<vector<int> >::interator it = unique(myvec.begin(), myvec.end()); Would the r...

Assignment of data-member in read-only structure, class in STL set

The minimal example of the problem I'm having is reproduced below: #include <set> using namespace std; class foo { public: int value, x; foo(const int & in_v) { value = in_v; x = 0; } bool operator<(const foo & rhs) const { return value < rhs.value; } }; int main() { foo y(3); set<foo> F; F.insert(y); // No...

GCC Tree STL data containers

Possible Duplicate: remove_if equivalent for std::map Yesterday i wrote a program, which use multiset for storing elements like this: std::multiset < boost::shared_ptr < CEntity > > m_Entities; Then i try to use standard algorithm remove_if like this: std::remove_if(m_Entities.begin, m_Entities.end(), MarkedForDestroy); ...

std::pair expecting a 'type', but I am giving it a type

This is my code: typedef std::hash_multimap<Vertice<VerticeType, WeightType>*, Edge<VerticeType, WeightType>*> ght; std::pair<ght::iterator, ght::iterator> getEdgesFromVertice(Vertice<VerticeType, WeightType>*); When I try to compile it, it gives me an error saying: error: type/value mismatch at argument 1 in template parameter list ...

How do I initialize a std::set comparator?

I need to initialize some comparator of the new data type TType based on std::set with some object o of another class Object: typedef std::set <unsigned int, sortSet(o)> TType This declaration is otside the class (in header file). At the time of the declaration this object does not have to exist, it will be created later. class sortS...

Convert std::vector to array

I have a library which expects a array and fills it. I would like to use a std::vector instead of using an array. So instead of int array[256]; object->getArray(array); I would like to do: std::vector<int> array; object->getArray(array); But I can't find a way to do it. Is there any chance to use std::vector for this? Thanks for r...