stl

any stl/boost functors to call operator()

template <typename T> struct Foo { void operator()(T& t) { t(); } }; Is there any standart or boost functor with the similar implementation? I need it to iterate over container of functors: std::for_each(beginIter, endIter, Foo<Bar>()); Or maybe there are other way to do it? ...

How to iterate a list of vector

Hi, If I have a vector of object vector, how can I check if A* myA is inside that vector? ...

Initialization of a vector of vectors?

Is there a way to initialize a vector of vectors in the same ,quick, manner as you initialize a matrix? typedef int type; type matrix[2][2]= { {1,0},{0,1} }; vector<vector<type> > vectorMatrix; //??? ...

Why does string::find return size_type and not an iterator?

In C++, why does string::find return size_type and not an iterator? It would make sense because functions like string::replace or string::insert take iterators as input, so you could find some character and immediately pass the returned iterator to replace, etc. Also, std::find returns an iterator -- why is std::string::find different...

need help with C++ using maps to keep track of words in a INPUT file

Let say i have a text file with today is today but tomorrow is today tomorrow then using maps how can i keep track of the words that are repeated? and on which line it repeats? so far i have each string in the file read in as a temp and it is stored in the following way: map<string,int> storage; int count = 1 // for the firs...

C++ Segmentation fault in binary_function

I'm using Visual Studio 2010 Beta 2 (also tried with NetBeans), and I'm having a segmentation fault in the following code: // One of the @link s20_3_3_comparisons comparison functors@endlink. template <class _Tp> struct less : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return _...

Unexpected termination when pushing a shared_ptr into a list

I have some function: void addNormalLine(int id, LineNumber number, Rate smsRate, Rate callRate) { list<Account>::iterator iAccounts; findAccount(iAccounts, id); if(iAccounts == listOfAccounts.end()){ throw "AccountDoesNotExist"; } if(lineExists(number)){ throw "LineExists"; } else...

C++ map to track when the end of map is reached

Currently I have a map that prints out the following map<string, map<int,int> > mapper; map<int,int>::iterator inner; map<string, map<int,int> >::iterator outer; for(outer = mapper.begin(); outer != mapper.end(); outer++){ cout<<outer->first<<": "; for(inner = outer->second.begin(); inner != outer->second.end(); inner++){ ...

Collision detection in STL's hash_map

I have to create a lookup table for C function names (as keys) to function pointers (as values). I am thinking of using STL's hash_map container, as the access time of a hash table is O(1). Is there any good hash function for this? Currently I am using (31*H + c) as my hash function. Also, does STL's hash_map takes care of collisions, o...

STL Priority Queue - deleting an item

Hello, I want to implement a timer queuing system using the C++ STL priority_queue container adapter. My problem is that I want to occasionally cancel a timer, however there are no interfaces that enable me to easily delete an item in the priority_queue that is not the top item. Any suggestions?. Thank you for your help. ...

Type requirements for std::list

I've got a type that can't be moved or copied (by making the necessary constructors and operators private). But when I tried to compile a std::list of them, the operation failed with a very strange error (class name snipped for brevity). 1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xmemory(202) : error C2248: 'T::T' ...

error when compiling c++ code with g++

i get error of this type: "in function ... multiple definition of ..." "... first defined here" "warning: size of symbol ... changed from to in " *the code is compiled with the flags: -ansi -Wall -pedantic-errors -Werror *STL is used is there any explanation for that? thank you in advance ...

is std::vector same as array[number]?

Possible Duplicate: Are std::vector elements guaranteed to be contiguous? does std::vector always contain the data in sequential memory addresses as array[number]? ...

Implementing custom STL-like data structures

I have already implemented and tested the data structure and would now like to make it compatible with the collection of STL algorithms. Guidelines for implementing a custom iterator and the like. Specifically: What is the minimum set of operations that must be supported? (e.g. ++, +=, ==, !=?) Are there any properties of these operati...

Trying to use STL without smart pointers - trying to avoid temporary object creation

I particularly like the simplicity of using STL containers in the straightforward way. I have never really figured out how to get the Boost library working on my dev platforms, in fact I don't think I've even tried. I guess you could say I am just trying to delay the inevitable since Boost is clearly a helpful library that I should be ...

Troubles with STL list iterators

After a thousand of attempts to Google/bypass that using pointers, I decided myself to post this question to you guys. Here's the problem: I'm trying to create a minimum spanning tree from a graph that I previously made. I'm using Kruscal's Algorithm for that, which is about checking every arc from the shorter to the longest and taking ...

Flexible mutation of sequence containers in C++

I'm pondering a current limitation of STL iterators and wondering if there's an elegant way around it. Here's my situation: I have a class that encapsulates a sequence container and a generic method to mutate the contents of the container, for example: class Container { typedef std::vector<int> Data; Data data_; public: template ...

Custom iterator: how do I keep track of it?

I have this situation: I have a class which keeps track of an array of pointers. I built a custom iterator which loops through this array. My problem is on how to make it threadsafe, especially while incrementing/decrementing? Here is a draft of the relevant parts of what I have: typedef fruit * iterator; class fruits { private: ...

How to use for_each with the function as the overloaded operator()

I have a std::vector of function objects. Each object can take an int, so I can say obj(4) and get an int result. How can I use the algorithm for_each to work on each element of the vector? ...

Instantiating C++ template functions

Hi, I am facing a few problems with "undefined reference to " errors. I may not be able to post the code, but the declarations and the way I am calling the functions are as follows: Declarations: template <typename T> int pitch_detect(deque<T>& x, int offset, int len); template <typename T> int is_voiced( deque<T>& x, int offset, i...