c++

C++ data structure with lookuptime O(1), like java's hashmap in stl ?

Is there such a structure in c++ standard library? I don't have access to anything else so unordered_map in tr1 cant be used (and boost etc). What I have is a large number of custom class elements 100000+ which I need to store, and access them very fast O(1) on everage. I can't use arrays/vectors as the elements will be stored randomly ...

any way to get some information at least for catch(...)

Is there any way to get at least someinformation inside of here? ... catch(...) { std::cerr<<"Unhandled exception"<<std::endl; } I have this as a last resort around all my code. Would it be better to let it crash, because then I at least could get a crash report? ...

boost exceptions

Do all boost exceptions derive from std::exception? If not do they all derive from some base exception class? ...

C++ Meta Templates: A Good or Bad Design Choice?

I'm curious to find out if and when C++ meta templates are a good design choice for systems small to large. I understand that they increase your build time in order to speed up your execution time. However, I've heard that the meta template code is inherently hard to understand by many developers, which could be a problem for a large gro...

Throw keyword in function's signature (C++)

Hello If function or class method throws an exception it is considered to be a good practice to signify this in function's signature. I.e. bool some_func() throw (myExc) { ... if (shit_happens) { throw myExc("shit happens"); } ... } My should we do this ? What are the advantages (or may be disadvantages) of su...

Differences between Conditional variables, Mutexes and Locks

For example the c++0x interfaces I am having a hard time figuring out when to use which of these things (cv, mutex and lock). Can anyone please explain or point to a resource? thanks in regard ...

Sending a Java UUID to C++ as bytes and back over TCP

I'm trying to send a Java UUID to C++, where it will be used as a GUID, then send it back and see it as a UUID, and I'm hoping to send it across as just 16 bytes. Any suggestions on an easy way to do this? I've got a complicated way of doing it, sending from Java to C++, where I ask the UUID for its least and most significant bits, wri...

C++ Get name of type in template

I'm writing some template classes for parseing some text data files, and as such it is likly the great majority of parse errors will be due to errors in the data file, which are for the most part not written by programmers, and so need a nice message about why the app failed to load e.g. something like: Error parsing example.txt. Val...

Numerical regression testing

I'm working on a scientific computing code (written in C++), and in addition to performing unit tests for the smaller components, I'd like to do regression testing on some of the numerical output by comparing to a "known-good" answer from previous revisions. There are a few features I'd like: Allow comparing numbers to a specified tole...

Non-member non-friend functions vs private functions

Herb Sutter has said that the most object oriented way to write methods in C++ is using non-member non-friend functions. Should that mean that I should take private methods and turn them into non-member non-friend functions? Any member variables that these methods may need can be passed in as parameters. Example (before): class Number ...

Rendering altitude data into a height map with kriging

Hi, I'm looking for an easy way to render altitude data into a heightmap. It could be a little easier to be archived with other techniques than kriging, like triangulation, but in this case speed doesn't cost and kriging was the most realistic way. Lets say I have the altitude points in an array and I want to call a function that calcu...

Strange stdout behavior in C++

I want my program to display the unix windmill while processing. There's a for loop and in every iteration theres a printf function: printf("Fetching articles (%c)\r",q); q is one of the characters in the windmill (-\|/) depending on the iteration number. The problem is - it seems like in 100 iterations there are only two changes in ...

Crash with boost::thread

Hello, I am using wxwidgets together with boost::thread. The Thread is a worker thread which sends some Events to the GUI: Thread creation: thrd = boost::thread(boost::bind(workerFunction,this)); Send Message to the GUI: wxPostEvent(loWindow, event); wxSafeYield(); Under Windows I don't see any problems, but when starting the app...

Bigint (bigbit) library.

I'm looking for a c++ class/library that provides 1024 bit and bigger integers and bit operations like: - bit shifting, - bitwise OR/AND, - position first zero bit speed is crucial, so it would have to be implemented with some SIMD assembly. ...

Using WTL with Codeblocks

I want to try WTL, but problem is i can't use Visual Studio for this. So i've codeblocks on my side. Is there any way i can use WTL with codeblocks ? I mean configuration/settings that i need to do for this ? is it possible to use WTL with codeblocks? Just to clear first, i tried google for this. No satisfactory success. So asking t...

C++ dynamic memory detail

Hi folks, I'm a c and java programmer, so memory allocation and OOP aren't anything new to me. But, I'm not sure about how exactly to avoid memory leaks with C++ implementation of objects. Namely: string s1("0123456789"); string s2 = s1.substr(0,3); s2 now has a new string object, so it must be freed via: delete &s2; Right? Moreo...

std::map and performance, intersecting sets

I'm intersecting some sets of numbers, and doing this by storing a count of each time I see a number in a map. I'm finding the performance be very slow. Details: - One of the sets has 150,000 numbers in it - The intersection of that set and another set takes about 300ms the first time, and about 5000ms the second time - I haven't don...

How to maintain a weak pointer to a parent in C++?

Is there a standard way of maintaining a weak pointer to a parent (which is created using a shared pointer) in a child object in C++? Essentially, I need to implement something on the lines of the following: Class B; Class A { ... private: B m_b; }; Class B { .... public: void SetParentPtr(const boost::shared_ptr<A>& a) { m_parentP...

How to generate a OS independent path in c++

I have a destination path and a file name as strings and I want to concatenate them with c++. Is there a way to do this and let the program/compiler choose between / and \ for windows or unix systems? ...

Fast C++ container like the C# HashSet<T> and Dictionary<K,V>?

I've used HashSet and Dictionary a lot in C#, and found them very fast... I've tried using std::map and std::hash_map and am finding them very slow in comparision. Does this sound like expected behaviour? Is there something I might be doing wrong in my use of std::hash_map? Or, is there a better C++ Hash container out there? I'm has...