c++

How to programmatically get the CPU cache page size in C++?

I'd like my program to read the cache line size of the CPU it's running on in C++. I know that this can't be done portably, so I will need a solution for Linux and another for Windows (Solutions for other systems could be usefull to others, so post them if you know them). For Linux I could read the content of /proc/cpuinfo and parse th...

Programmatically find the number of cores on a machine

This is more of a curiosity question than something that needs actual solving, but is there a way to determine how many cores a machine has from C++ in a platform-independent way? If no such thing exists, what about determining it per-platform (Windows/*nix/Mac)? ...

C++ having cin read a return character

Hey everyone, I was wondering how to use cin so that if the user does not enter in any value and just pushes ENTER that cin will recognize this as valid input. Thanks in advance, Tomek ...

Side effects of calling RegisterWindow multiple times with same window class?

I'm working on a little test application at the minute and I have multiple window objects floating around and they each call RegisterWindowEx with the same WNDCLASSEX structure (mainly because they are all an instance of the same class). The first one registers ok, then multiple ones fail, saying class already registered - as expected. ...

C++ last loop iteration (STL map iterator)

I'm trying to figure out the best way to determine if I'm in the last iteration of a loop over a map in order to do something like the following: for (iter = someMap.begin(); iter != someMap.end(); ++iter) { bool last_iteration; // do something for all iterations if (!last_iteration) { // do something for all but the...

Which is correct? catch (_com_error e) or catch (_com_error& e)?

Which one should I use? catch (_com_error e) or catch (_com_error& e) ...

Embedding SVN Revision number at compile time in a Windows app

I'd like my .exe to have access to a resource string with my svn version. I can type this in by hand, but I'd prefer an automated way to embed this at compile time. Is there any such capability in Visual Studio 2008? ...

Calling a C++ function pointer on a specific object instance

I have a function pointer defined by: typedef void (*EventFunction)(int nEvent); Is there a way to handle that function with a specific instance of a C++ object? class A { private: EventFunction handler; public: void SetEvent(EventFunction func) { handler = func; } void EventOne() { handler(1); } }; class B { private: ...

Developing for different platforms individually, does anyone recommend it?

I know it is easy to recommend several cross platform libraries. However, are there benefits to treating each platform individually for your product? Yes there will be some base libraries used in all platforms, but UI and some other things would be different on each platform. I have no restriction that the product must be 100% alike...

High-level Compare And Swap (CAS) functions?

I'd like to document what high-level (i.e. C++ not inline assembler ) functions or macros are available for Compare And Swap (CAS) atomic primitives... E.g., WIN32 on x86 has a family of functions _InterlockedCompareExchange in the <_intrin.h> header. ...

When should I use __forceinline instead of inline?

Visual Studio includes support for __forceinline. The Microsoft Visual Studio 2005 documentation states: The __forceinline keyword overrides the cost/benefit analysis and relies on the judgment of the programmer instead. This raises the question: When is the compiler's cost/benefit analysis wrong? And, how am I supposed to ...

C++ blogs that you regularly follow?

What are all the c++ blogs that you follow Please add one url for one posting. ...

How can currying be done in C++?

What is currying? How currying can be done in c++? Please Explain binders in STL container? ...

Detecting CPU architecture compile-time

What is the most reliable way to find out CPU architecture when compiling C or C++ code? As far as I can tell, different compilers have their own set of non-standard preprocessor definitions (_M_X86 in MSVS, __i386__, __arm__ in GCC, etc). Is there a standard way to detect the architecture I'm building for? If not, is there a source for...

How to measure performance in a C++ (MFC) application?

What good profilers do you know? What is a good way to measure and tweak the performance of a C++ MFC application? Is Analysis of algorithms really neccesary? http://en.wikipedia.org/wiki/Algorithm_analysis ...

Fixed point combinators in C++

I'm interested in actual examples of using fixed point combinators (such as the y-combinator in C++. Have you ever used a fixed point combinator with egg or bind in real live code? I found this example in egg a little dense: void egg_example() { using bll::_1; using bll::_2; int r = fix2( bll::ret<int>(...

Logging/monitoring all function calls from an application

Hi, we have a problem with an application we're developing. Very seldom, like once in a hundred, the application crashes at start up. When the crash happens it brings down the whole system, the computer starts to beep and freezes up completely, the only way to recover is to turn off the power (we're using Windows XP). The rarity of the ...

Animation in C++

What are ways to draw animations in C++? GDI+? OpenGL? Would you recommend a class pattern in particular to get the drawing and redrawing done? Do you know of any open source project where animations are made so I can take a peek at the code? Where would you start if you wanted to code geometrical animations? Do you know of any good l...

Setup wxWidget in Netbeans 6.1 C++ On MS Windows?

Hi, Im running Netbeans 6.1 with C++ Plugin and cygwin (gcc compiler) how do I setup wxWidget to work with it? ...

Boost Range Library: Traversing Two Ranges Sequentially

Boost range library (http://www.boost.org/doc/libs/1_35_0/libs/range/index.html) allows us to abstract a pair of iterators into a range. Now I want to combine two ranges into one, viz: given two ranges r1 and r2, define r which traverses [r1.begin(), r1.end()[ and then [r2.begin(), r2.end()[. Is there some way to define r as a range usi...