c++

JIT compiler vs offline compilers

Are there scenarios where JIT compiler is faster than other compilers like C++? Do you think in the future JIT compiler will just see minor optimizations, features but follow a similar performance, or will there be breakthroughs that will make it infinitely superior to other compilers? It looks like the multi core paradigm has some pro...

check what number a string ends with in C++

In a C++ MD2 file loader, I have a lot of frames, each with a name that ends with a number, such as stand0 stand1 stand2 stand3 stand4 ... stand10 stand11 run0 run1 run2 etc. How do I get what the string is without the number behind? e.g. a function that changed "stand10" to just "stand" ...

Change tab stop size in rendered HTML using Qt's QLabel class

I'm rendering some HTML in a QT QLabel. The HTML looks like this: <pre>foo\tbar</pre> (note that I've put "\t" where there is a tab chracter in the code). This renders fine, but the tab character appears to be rendered as eight spaces, whereas I want it to be redered as 4. How can I change this without having to change the source HT...

Getting first byte in a char* buffer

I have a char* buffer and I am interested in looking at the first byte in the char* buffer, what is the most optimal way to go about this. EDIT: Based on the negative votes I might want to explain why this question, I am aware of methods but in the code base that I have been looking for getting first byte people do all kinds of crazy t...

High resolution timer with C++ and Linux?

Hi! Under Windows there are some handy functions like QueryPerformanceCounter from mmsystem.h to create a high resolution timer. Is there something similar for Linux? ...

How portable is an STL typedef?

Is the following code portable? template<typename In> struct input_sequence_range : public pair<In,In> { input_sequence_range(In first, In last) : pair<In,In>(first, last) { } }; template<typename Arr> input_sequence_range<Arr*> iseq(Arr* a, typename iterator_traits<Arr*>::difference_type n) { re...

How do I delete the closest "Point" object in a STD::List to some x,y?

I have a point class like: class Point { public: int x, y; Point(int x1, int y1) { x = x1; y = y1; } }; and a list of points: std::list <Point> pointList; std::list <Point>::iterator iter; I'm pushing points on to my pointList (although the list might contain no Points yet if none have been pushed ye...

Looking for a Hash Function /Ordered Int/ to /Shuffled Int/

I am looking for constant time algorithm can change an ordered integer index value into a random hash index. It would nice if it is reversible. I need that hash key is unique for each index. I know that this could be done with a table look up in a large file. I.E. create an ordered set of all ints and then shuffle them randomly and write...

How do I get the current mouse position in C++ / OpenGL?

I know that I can use a Mouse callback function for when a user clicks the mouse, but what if I want to know the current x/y position without the user clicking? Will I have to use a different callback that gets called on any mouse movement and keep track of the x/y myself or is there a function I can call within GLUT/OpenGL to get it? ...

Itereting hierarchy of nodes - Visitor and Composite ?

Let's imagine I have a collection of nodes that I use for my Renderer class later on. Then I have a Visitor class that can visit node or whole collection. It's simple because my collection of nodes it's simply a wrapper to the std::list with few extra methods. The problem is I'd like to have a tree like structure for nodes(instead of si...

How do I have an icon displayed when a setup CD is autoplayed in Windows.

I have a setup CD to install a visual studio C++ application I made. It has three files: setup.exe, AUTORUN.INF, and app.msi. When I insert the CD the Windows AutoPlay popup shows a generic icon. How do I have my own icon displayed for setup.exe. I also want this for the drive icon after I insert the CD, I think they're related. ...

How do I specify a publisher for the setup.exe when a setup CD is autoplayed in Windows.

I have a setup CD to install a visual studio C++ application I made. The AutoPlay popup shows "Publisher not specified" for running setup.exe. How do I specify a publisher? ...

Getting the size of an indiviual field from a c++ struct field

The short version is: How do I learn the size (in bits) of an individual field of a c++ field? To clarify, an example of the field I am talking about: struct Test { unsigned field1 : 4; // takes up 4 bits unsigned field2 : 8; // 8 bits unsigned field3 : 1; // 1 bit unsigned field4 : 3; // 3 bits unsigned field5 ...

Calling functions in a DLL from C++

I have a solution in VS 2008 with 2 projects in it. One is a DLL written in C++. The other is a simple c++ console application created from a blank project. I would like know how to call the functions in the DLL from the application. Assume I am starting with a blank C++ project and that i want to call a function called "int IsolatedFun...

Encapsulate a simple type using C++ templates

I'm looking to add functionality to all the simple types in C++. I want to write a single templated class that takes as a template parameter the type to be encapsulated and then has all the operators defined so that the encapsulated class works exactly as the simple type it encapsulates. Something like this: template <typename _Simpl...

Disambiguate operator[] binding

I'm trying to compile code from an open source project, and I'm running into a problem where gcc claims that a particular line of code has an ambiguous interpretation. The problem involves a templated class and these two methods: template <class X> class A { public: X& operator[] (int i) { ... } operator const X* () { ... } }; ...

memory buffer as FILE*

Is there any way to create a memory buffer as a FILE*. In TiXml it can print the xml to a FILE* but i cant seem to make it print to a memory buffer. ...

Namespace Specification In Absence of Ambuguity

Why do some languages, like C++ and Python, require the namespace of an object be specified even when no ambiguity exists? I understand that there are backdoors to this, like using namespace x in C++, or from x import * in Python. However, I can't understand the rationale behind not wanting the language to just "do the right thing" whe...

Why doesn't this C++ STL allocator allocate?

I'm trying to write a custom STL allocator that is derived from std::allocator, but somehow all calls to allocate() go to the base class. I have narrowed it down to this code: template <typename T> class a : public std::allocator<T> { public: T* allocate(size_t n, const void* hint = 0) const { cout << "yo!"; return 0...

Problem with thread-safe queue?

I'm trying to write a thread-safe queue using pthreads in c++. My program works 93% of the time. The other 7% of the time it other spits out garbage, OR seems to fall asleep. I'm wondering if there is some flaw in my queue where a context-switch would break it? // thread-safe queue // inspired by http://msmvps.com/blogs/vandooren/archiv...