c++

Using Hash Maps to represent an extremely large data source

I have a very large possible data set that I am trying to visualize at once. The set itself consists of hundreds of thousands of segments, each of which is mapped to an id. I have received a second data source that gives more real-time information for each segment, but the id's do not correspond to the id's I have. I have a 1:1 mappin...

In C++ and C# are multiple condition checks performed in a predetermined or random sequence?

Situation: condition check in C++ or C# with many criteria: if (condition1 && condition2 && condition3) { // Do something } I've always believed the sequence in which these checks are performed is not guaranteed. So it is not necessarily first condition1 then condition2 and only then condition3. I learned it in my times with C++. ...

Why is there no ^^ operator in C/C++?

& has &&. | has ||. Why doesn't ^ have ^^? I understand that it wouldn't be short-circuiting, but it would have different semantics. In C, true is really any non-zero value. Bitwise XOR is not always the same thing as logical XOR: int a=strcmp(str1,str2);// evaluates to 1, which is "true" int b=strcmp(str1,str3);// evaluates to 2, whic...

Safe to store list::iterator for later use?

Suppose I have a list, in which no new nodes are added or deleted. However, the nodes may be shuffled around. Is it safe to save an iterator, pointing to a node in the list, and access it at some arbitrarily later time? Edit (followup question): The documentation for list::splice() says that it removes elements from the argument list....

Packing enums using the MSVC++ compiler

With GCC, I could do packing of enums using attribute((packed)), but it seems the closest thing in MSVC, #pragma pack, does not work on enums. Does anyone know of a way to pack enums into 1 byte instead of the usual integer size? ...

debugging Intel's TBB containers

Recently we have started working with Intel's TBB and found that when debugging containers we cannot really watch the elements and their data. Is there a flag setting, a plugin or a tricky way to enable this? (maybe a script snipit for Visual to work with) ...

How to emulate Edit/Update mechanism of ADO for SQLite in C++?

I have a C++ application that uses ADO to talk to an Oracle database. I'm updating the application to support an offline documents. I've decided to implement SQLite for the local side. I've implemented a wrapper around the ADO classes that will call the appropriate code. However, ADO's way of adding/editing/deleting rows is a bit diffic...

Gettext and locales

...

Looking for a good AI book that uses examples in C++

Hello all. I've searched over the posts I could find on "What's the best AI book" and I found all the responses I expected to see, but I did not find what I was looking for. I'm interested in a book that I can use in a teaching environment that explains AI topics such as Neural Networks, Genetic Algorithms, Decision Tree learning, Indu...

C++ STL's String eqivalent for Binary Data

I am writing a C++ application and I was wondering what the C++ conventional way of storing a byte array in memory. Is there something like a string, except specifically made for binary data. Right now I am using a *unsigned char** array to store the data, but something more STL/C++ like would be better. ...

Compiling Protobuf C++ Code

I have the mytest.cc and mytest.h output from a mytest.proto file, but I can't find any reference on to how to compile a object using g++ for this. (the .proto is fine as I got it working with Python) g++ mytest.cc -l??????? what libraries to include? ...

How do I pass a list of objects from C++ to Lua?

I'm the lead dev for Bitfighter, and am adding user-scripted bots using Lua. I'm working with C++ and Lua using Lunar to glue them together. I'm trying to do something that I think should be pretty simple: I have an C++ object in Lua (bot in the code below), and I call a method on it that (findItems) which causes C++ to search the area...

Update GCC on OSX

So I am a new programmer and I just installed XCode on my Macbook to get the GCC. I think Xcode is the only way for getting GCC on OSX. Now when I run my Hello World application, in C++, g++ comes up saying it is version 4.0.1 but when I look for commands starting with g I also see g++-4.2. Is there any way of making 4.2 default rather t...

CListControl selection (MFC)

Hi, In report view in a CListCtrl in MFC, how do I detect if there is no current highlighted selection? Using GetFirstSelectedItemPosition doesn't work because if an item was previously selected and then clicked somewhere else on the list control, GetFirstSelectedItemPosition still reports the last position selected instead of NULL, h...

how to clone a solidbrush in GDI+ C++

I am using gdi+ and c++. I have a question about SolidBrush. How To clone a SolidBrush? SolidBrush* oldBrush xxx; Brush* newBrush = oldBrush->Clone(); I found newBrush is a Brush Object. Which mean if I use dynamic_cast<SolidBrush>(newBursh), I will always get NULL. I read the .h file of gdi+ SolidBrush seems used Brush's virtual Clo...

Need to store string as id for objects in some fast data structure

I'm implementing a session store for a web-server. Keys are string and stored objects are pointers. I tried using map but need something faster. I will look up an object 5-20 times as frequent than insert. I tried using hash-map but failed. I felt like I got more constraints than more free time. I'm coding c/c++ under Linux. I don't...

How to reduce code duplication on class with data members with same name but different type?

I have trouble when designing classes like this class C1 { public: void foo(); } class C2 { public: void foo(); } C1 and C2 has the same method foo(), class Derived1 : public Base { public: void Update() { member.foo(); } private: C1 member; } class Derived2 : public Base { public: void Update() { member.foo...

Reorder vector using a vector of indices

I'd like to reorder the items in a vector, using another vector to specify the order: char A[] = { 'a', 'b', 'c' }; size_t ORDER[] = { 1, 0, 2 }; vector<char> vA(A, A + sizeof(A) / sizeof(*A)); vector<size_t> vOrder(ORDER, ORDER + sizeof(ORDER) / sizeof(*ORDER)); reorder_naive(vA, vOrder); // A is now { 'b', 'a', 'c' } The fo...

Why don't cycle summaries have any callers in gprof's call-graph output?

I use GNU gprof 2.15.94.0.2.2 to do profiling of my C++ program, which has large call cycles. I expected to see something like below in the call graph output as gprof's documentation indicates: index % time self children called name ---------------------------------------- 1.77 0 1/1 main [2] [...

Java Exception vs C++ Exceptions

Where are exceptions stored ? Stack, Heap. How is memory allocated and deallocated for Exceptions? Now if you have more than one exception which needs to be handled are there objects of all these exceptions created? ...