c++

C++ : variable template parameters (for genetic algorithm)

Hello there I'm writing a parallel evolutionary algorithm library using C++, MPI and CUDA. I need to extract the raw data from my object oriented design and stick it into a flat array (or std::vector using stl-mpi) for it to be sent across to nodes or the cuda device. The complete design is quite complex with a lot of inheritance to k...

What does the restrict keyword mean in C++?

I was always unsure, what does the restrict keyword mean in C++? Does it mean the two or more pointer given to the function does not overlap? What else does it mean? ...

In C++ how can I use a template function as the 3rd parameter in std::for_each?

I am trying to use std::for_each to output the contents of vectors, which may contain different types. So I wrote a generic output function like so: template<typename T> void output(const T& val) { cout << val << endl; } which I would like to use with: std::for_each(vec_out.begin(), vec_out.end(), output); but the compiler comp...

TAB control background in ATL App, XP styles

I have an ATL application with a dialog containing a TAB control. The App uses a common controls manifest. Under XP with visual styles, the tab control background is a different color than the dialog and the controls (mostly checkboxes), so it looks quite ugly. Screenshot How can I fix that? ...

Test if a font is installed (Win32)

How can I test if a font is installed? Ultimately, I want to implement a HTML-like font selection, i.e. when specifying e.g. "Verdana,Arial", it should pick the first font that is installed. This Question provides an answer for .NET - it seems the recommended way is to create the font, and then cmpare the font face actually used. Is ...

Circular shift operations in C++

Left and right shift operators (<< and >>) are already available in C++. However, I couldn't find out how I could perform circular shift or rotate operations. How can operations like "Rotate Left" and "Rotate Right" be performed? Rotating right twice here Initial --> 1000 0011 0100 0010 should result in: Final --> 1010 0000 110...

Soundex Algorithm implementation using C++

Put simply a Soundex Algorithm changes a series of characters into a code. Characters that produce the same Soundex code are said to sound the same. The code is 4 characters wide The first character of the code is always the first character of the word Each character in the alphabet belongs in a particular group (at least in this exa...

What's faster, iterating an STL vector with vector::iterator or with at()?

In terms of performance, what would work faster? Is there a difference? Is it platform dependent? //1. Using vector<string>::iterator: vector<string> vs = GetVector(); for(vector<string>::iterator it = vs.begin(); it != vs.end(); ++it) { *it = "Am I faster?"; } //2. Using size_t index: for(size_t i = 0; i < vs.size(); ++i) { //...

Marching Cube Question

i currently writing a program to implement Marching Cube using C++ and Opengl. However, my best reference is only from http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/ in the web, the provided codes are written in C. my problem here is that i don't understand the triTable and edgeTable and how they are related. can anyone h...

What's the best way to implement a operator overload?

Among all things I've learned in C++ (which isn't so much), operator overloading seems the most difficult. In general terms, when is it best to write an operator overload as a friend function? When do I have to explicilty use *this? Is always bad to use a temporary object? ...

Getting different instances to communicate

Suppose I have two instances of the same class. The class has a pointer to some data, and I want the instances to exchange the pointers as part of some private function's algorithm, but without compromising the data to everybody else by giving a direct access to it through a public function. My first idea was to add a static variable o...

How long can template compilation really take?

Template metaprogramming can be used for computing things like factorial at compile time instead of during runtime. I've heard that some programming contests have introduced limitations on compilation time exactly to weed out template metaprogramming abuse. Is there any innocent looking example of using templates that takes some really-...

Avoiding unused variables warnings when using assert() in a Release build

Sometimes a local variable is used for the sole purpose of checking it in an assert(), like so - int Result = Func(); assert( Result == 1 ); When compiling code in a Release build, assert()s are usually disabled, so this code may produce a warning about Result being set but never read. A possible workaround is - int Result = Func();...

ListView_SetBKImage is scrolling the back ground image also. Want a fixed back ground image and the contents should scroll over.

ListView_SetBKImage is scrolling the back ground image also. Want a fixed back ground image and the contents should scroll over. I am setting Backgroung image in LisTView by this code. LVBKIMAGE bki= {0}; bki.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL; /* | LVBKIF_TYPE_WATERMARK | LVBKIF_FLAG_ALPHABLEND*/ bki.pszImage=szBmpP...

What is double(C++) in C#?

What is the double type(C++) in C#? double experience; At first,I thought its UInt32,but its not. How to declare it in C#? ...

C++ Letting a boost thread wait for 1 second

I have created a boost thread using: boost::thread thrd(&connectionThread); where connectionThread is a simple void function. This works fine, however, when I try to make it wait for some seconds, for example using: boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC); xt.sec += 1; boost::thread::sleep(xt); // Sleep for 1 second ...

What modern C++ libraries should be in my toolbox?

I've been out of the C++ game for about 10 years and I want to get back in and start on a commercial app. What libraries are in use these days? User interface (e.g, wxWidgets, Qt) Database General purpose (e.g. Boost, Loki, STL) Threading Testing Network/sockets I looking to be cross-platform compatible (as much as possible out-of-t...

How to name a thread in Linux?

I have a multithreaded Linux application written in C/C++. I have chosen names for my threads. To aid debugging, I would like these names to be visible in GDB, "top", etc. Is this possible, and if so how? (There are plenty of reasons to know the thread name. Right now I want to know which thread is taking up 50% CPU (as reported by ...

How to write bitset data to a file?

I have a std::bitset that I'd like to write to a file, bit for bit, but of course fstream's write function doesn't support this. I can't think of another way besides converting each 8-bit group to a char using string and writing that... Anyone know of a good way? ...

How do I use C++ in flex and bison?

I have a project for school where we need to use flex and bison. I want to use C++ so that I have access to STL and my own classes that I wrote. We were provided with the following Makefile: CC = gcc CFLAGS = -g OBJs = parse.tab.o symtab.o attr.o lex.yy.o default: parser parser: ${OBJs} ${CC} ${CFLAGS} ${OBJs} -o parser -lfl ...