stl

Is there a heap class in C++ that supports changing the priority of elements other than the head?

I have a priority queue of events, but sometimes the event priorities change, so I'd like to maintain iterators from the event requesters into the heap. If the priority changes, I'd like the heap to be adjusted in log(n) time. I will always have exactly one iterator pointing to each element in the heap. ...

msvc9, iostream and 2g/4g plus files

Doing cross platform development with 64bit. Using gcc/linux and msvc9/server 2008. Just recently deployed a customer on windows and during some testing of upgrades I found out that although std::streamoff is 8 bytes, the program crashes when seeking past 4G. I immediately switched to stlport which fixes the problem, however stlport se...

C++: Assigning values to non-continuous indexes in vectors?

If I want to declare a vector of unknown size, then assign values to index 5, index 10, index 1, index 100, in that order. Is it easily doable in a vector? It seems there's no easy way. Cause if I initialize a vector without a size, then I can't access index 5 without first allocating memory for it by doing resize() or five push_back()'...

std::string comparison

I need to check whether an std:string begins with "xyz". How do I do it without searching through the whole string or creating temporary strings with substr(). Thanks. ...

std::sort without functors

I have a question regarding the std::sort algorithm. Here is my test code: struct MyTest { int m_first; int m_second; MyTest(int first = 0, int second = 0) : m_first(first), m_second(second) { } }; int main(int argc,char *argv[]) { std::vector<MyTest> myVec; for(int i = 0; i < 10; ++i) { myVec.pus...

Why does std queue not define a swap method specialisation

I've read that all stl containers provide a specialisation of the swap algorithm so as to avoid calling the copy constructor and two assignment operations that the default method uses. However, when I thought it would be nice to use a queue in some code I was working on I noticed that (unlike vector and deque) queue doesn't provide this ...

What is the point of make_heap?

Can someone please tell me the point of the STL heap functions like make_heap? Why would anyone ever use them? Is there a practical use? ...

mem_fun_ref trouble

I am having trouble figuring out mem_fun_ref. I have to admit, I usually use functors for this kind of thing, since they can be inlined for speed and profit. However, this code is not going to be a bottleneck and so I wanted to try this thing. Here is an example of what I want to do. I know there are other ways to do it. I don't want to...

Standard Template Library using g++

While migrating a program from windows in linux I encountered a problem using the c++ standard template library. I am trying to typedef a template and I am getting the error 'expected initializer before '<' token on this line typedef std::list< std::pair< int,double> > PairList; Any ideas why this would work using mvc++ and not using g...

map.erase( map.end() )?

Consider: #include <map> int main() { std::map< int, int > m; m[ 0 ] = 0; m[ 1 ] = 1; m.erase( 0 ); // ok m.erase( 2 ); // no-op m.erase( m.find( 2 ) ); // boom! } (OK, so the title talks abouting erasing an end() iterator, but find will return end() for a non-existent key.) Why is erasing a non-existent ...

Using shared C++/STL code with Objective-C++

I have a lot of shared C++ code that I'd like to use in my iPhone app. I added the .cpp and .h files to my Xcode project and used the classes in my Objective-C++ code. The project compiles fine with 0 errors or warnings. However, when I run it in the simulator I get the following error when I attempt to access an STL method in my obje...

Would std::basic_string<TCHAR> be preferable to std::wstring on Windows?

As I understand it, Windows #defines TCHAR as the correct character type for your application based on the build - so it is wchar_t in UNICODE builds and char otherwise. Because of this I wondered if std::basic_string<TCHAR> would be preferable to std::wstring, since the first would theoretically match the character type of the applic...

Which sorting algorithm is used in stl and .net base library default search?

I am now working on an imprived version of merge sort. I implemented it with C++ and C#. Then compared them with the stl sort and array.sort() algorithm respectively. In C++ I have got an equal (sometimes better) result. But in C#, I had to use unsafe code for using pointers. Here the performence is not that much comparable with default ...

One question about element inserting in STL list.

CODE: struct Stringdata { // Length of data in buffer. size_t len; // Allocated size of buffer. size_t alc; // Buffer. char data[1]; }; typedef std::list<Stringdata*> Stringdata_list; Stringdata_list strings_; Stringdata *psd = this->strings_.front(); //... if (len > psd->alc - psd->len) alc = sizeof(Stringdata) + buffer_...

Weird "Bus error" in string::string constructor

I've been testing part of my code responsible for filling multimap object, when a weird error started to pop up: int SetPortName(string ID, string Name) cout << "ID: " << ID << " Name: " << Name; ... } works fine under non-root user in FreeBSD 5.4, but crashes with "Bus error" while ran under root. ...

Stuck on C++ template - deriving from std::map

I'm going to extend the existing std::map class and add a new function to it: template<typename key_type, typename value_type> class CleanableMap : public Cleanable, public std::map<key_type, value_type> { CleanableMap(const CleanableMap& in); //not implemented CleanableMap& operator=(const CleanableMap& in); //not implemented ...

instantiate a new stl vector

Hello, I have a situation where i have a pointer to an stl vector so like vector<MyType*>* myvector; I have to set this pointer to NULL in the constructor and then lazy load when property is touched. how can i instantiate this to a new instance of a vector ? thanks -ashish ...

std::list problem for iPhone development

I found some problems for std::list when I'm doing some iPhone development under Xcode. Here is the code: ///////////// interface ////////////// class CObj { public: int value; }; typedef std::list<CObj*> ObjList; @interface testAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; ObjList m_objs; } /////...

C++0x performance improvements

One of the C++0x improvements that will allow to write more efficient C++ code is the unique_ptr smart pointer (too bad, that it will not allow moving through memmove() like operations: the proposal didn't make into the draft). What are other performance improvements in upcoming standard? Take following code for example: vector<char *>...

C++ Boost ptr_map serialization error

I have some code that I want to build. The code uses boost::ptr_map class to serialize certain objects. I have Visual Studio 2008 with boost1.38 and I am getting following error from compiler. I wonder if any one else has seen any thing like this. C2039: 'serialize' : is not a member of 'boost::ptr_map' Looks like some reference is mis...