stl

Is there an STL and UTF-8 friendly C++ Wrapper for ICU, or other powerful Unicode library

I need a good Unicode library for C++. I need: Transformations in a Unicode sensitive way. For example sort all strings in a case insensitive way and get their first characters for index. Convert various Unicode strings to upper and to lower case. Split text at a reasonable position -- words that would work for Chinese and Japanese as ...

Do I need to lock STL list with mutex in push_back pop_front scenario?

I have a thread push-backing to STL list and another thread pop-fronting from the list. Do I need to lock the list with mutex in such case? ...

std::map, pointer to map key value, is this possible?

std::map<std::string, std::string> myMap; std::map<std::string, std::string>::iterator i = m_myMap.find(some_key_string); if(i == m_imagesMap.end()) return NULL; string *p = &i->first; Is the last line valid? I want to store this pointer p somewhere else, will it be valid for the whole program life? But what will happen if I ad...

Why can't I put an iterator in map?

I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string named "mHugeString". Then I walk trough the string collecting iterators like this: std::string::iterator It=mHugeString.begin(); std::string::iterator EndIt=mHugeString.end(); for(;It!=EndIt;++It){ ...defining a key element...

C++ function that returns string doesn't work unless there's an endl involved...?

I've got a function inside of a class that returns a string. Inside this function, I can only get it to work when I add cout<<endl to the function before the return statement. Any idea why this is, or how I can fix it? I'm running this in Eclipse on a Mac In "main.cpp": #include <iostream> #include <fstream> #include <string> #includ...

Does std::stack expose iterators?

Does the stack in the C++ STL expose any iterators of the underlying container or should I use that container directly? ...

Opening a file with std::string

Hi, This should be a fairly trivial problem. I'm trying to open an ofstream using a std::string (or std::wstring) and having problems getting this to work without a messy conversion. std::string path = ".../file.txt"; ofstream output; output.open(path); Ideally I don't want to have to convert this by hand or involve c-style char po...

Memory Allocation in std::map

I am doing a report on the various C++ dictionary implementations (map, dictionary, vectors etc). The results for insertions using a std::map illustrate that that the performance is O(log n). There are also consistent spikes in the performance. I am not 100% sure what's causing this; I think they are caused by memory allocation but I ...

Creating a new vector using a transform

I have a vector of integers and I want to convert it to a vector of pairs (pair consists of a bool and a int). My current code is simple like this: std::vector<int> a; std::vector<std::pair<bool,int> > b; a.push_back(1); a.push_back(2); a.push_back(3); for(int i = 0; i < a.size(); ++i) { b.push_back(st...

Optimising Iterator Definitions

Hi all, This is a (hopefully) really simple question - I have been told recently that using C++ style initialisation is better than traditional (and more common) assignment. So this code: std::SomeSTLContainer::const_iterator it = container.begin(); std::SomeSTLContainer::const_iterator itEnd = container.end(); would be 'slower' or ...

Overloading operator<< for primitive types. Is that possible?

Hey. Is it possible to overload operator<< for primitive types? Fx lets say that I want to write a std::endl each time want to write a int. Can I overload operator<< for int, so that it automatic puts a std::endl to the output? I have tried with this, std::ostream& operator<<(std::ostream& strm, int & i) { strm << i << std::endl; ...

Returning the greatest key strictly less than the given key in a C++ Map

Is there a way the C++ STL Maps support this, since lower_bound and upper_bound on maps strictly return the value greater than the passed value. Lower key Use case I have a map with times as keys in a sorted manner so in a MAP time t1 = value1 time t2 = value2 time t2.5 = value3 In this case if I pass to this MAP t2.3 then it s...

In C++ does std::multiset keep a stable sorting order?

Suppose I have two items, a and b, that compare the same. So a < b is false, and b < a is false. If these items are inserted into a std::multiset (or std::multimap) as keys, do I have any guarantees of their final sorted order? I've checked a couple of references, but I couldn't find the answer. I'm tempted to think that there are no gu...

Examples of "modern c++" in action?

For new and completely revised tricks and dark corners of STL go here: Hidden Features and Dark Corners of STL I've been using more "modern" c++ constructs for a while, but kind of superficially and not everywhere. I'm looking for open source projects to study that are good examples of Modern C++ and STL usage. Things like what is sugg...

How portable is an STL typedef?

Is the following code portable? template<typename In> struct input_sequence_range : public pair<In,In> { input_sequence_range(In first, In last) : pair<In,In>(first, last) { } }; template<typename Arr> input_sequence_range<Arr*> iseq(Arr* a, typename iterator_traits<Arr*>::difference_type n) { re...

Why doesn't this C++ STL allocator allocate?

I'm trying to write a custom STL allocator that is derived from std::allocator, but somehow all calls to allocate() go to the base class. I have narrowed it down to this code: template <typename T> class a : public std::allocator<T> { public: T* allocate(size_t n, const void* hint = 0) const { cout << "yo!"; return 0...

Return an array by looking up bits?

I have the following use case , array of integers vector<int> containing elements 123 345 678 890 555 ... pos 0 1 2 3 4 Based on the bits representation I receive for e.g 101 then return 123 678 (Elements of the array with its position bits set) 0011 then return 678 890 00001 then retur...

Please, help with STL stringstream

Why do I fail to extract an integer value into Num variable ? #include <sstream> #include <vector> #include <iostream> using namespace std; int main() { string Digits("1 2 3"); stringstream ss(Digits); string Temp; vector<string>Tokens; while(ss >> Temp) Tokens.push_back(Temp); ss.str(Tokens[0]); ...

google code cache-table at VC 2005

I'm trying to compile google cache-table using Visual Studio 2005 and remains one issue : \mm\cache_table.hpp(734) : error C2780: 'void std::_Destroy(_Ty *)' : expects 1 arguments - 2 provided c:\arquivos de programas\microsoft visual studio 8\vc\include\xmemory(58) : see declaration of 'std::_Destroy' \mm\cache_table.hpp(714) : while c...

Combining Predicates

Is there any way that you can combine predicates? Lets say I have something like this: class MatchBeginning : public binary_function<CStdString, CStdString, bool> { public: bool operator()(const CStdString &inputOne, const CStdString &inputTwo) const { return inputOne.substr(0, inputTwo.length()).compare(inputTwo) == 0; } };...