c++

Using pThreads, is it possible to write a function that can detect what thread it's being called from?

This is the usage case: Log(char* s); // prints out a log message Now: Log("hello world\n"); // called from Thread1 Desired output: Thread1: hello world Now: Log("hello world\n"); // called from Thread2 Desired output: Thread2: hello world I can have a map that maps thread pids to strings. What I need however, is a functio...

How do I place my app window in a certain position in the desktop window hierarchy on Windows using win32 api?

I want my application window to be in a certain spot in the window hierarchy. That is, say I have 3 windows on my desktop. At the very bottom I have Word, the window on top of word is explorer, and the active foreground window is itunes. I want to place my application window on top of word but beneath explorer. How can I achieve this wit...

Templates specialization

I have the following set of templates: //1 template< typename T > void funcT( T arg ) { std::cout<<"1: template< typename T > void funcT( T arg )"; } //2 template< typename T > void funcT( T * arg ) { std::cout<<"2: template< typename T > void funcT( T * arg )"; } //3 template<> void funcT< int >( int arg ) ...

How can I extend std::basic_streambuf to treat any iterable sequence as a stream?

Note: Edited based on responses to receive more appropriate answers. I have a collection of C++ templates that I've made over the years, which I call Joop. It comprises mainly libraries that don't quite fall into the "general-purpose" category but are just useful enough that I keep slapping them into different projects, so most of them ...

What is api interception? when is it used? how to implement it in C++

What is API interception When is it used How to implement it in C++ ...

std::ostringstream woes

I can do std::ostringstream oss; oss << 1; oss.str(); so why can't I do: ((std::ostringstream()) << 1).str() ? Thanks! ...

How to slice with for-range loop ? C++0x

Using range based for loops in C++0X, I know we'll be able to do : std::vector<int> numbers = generateNumbers(); for( int k : numbers ) { processNumber( k ); } (might be even simpler to write with lambda) But how should i do if I only want to apply processNumber( k ) to a part of numbers? For example, how should I write this for ...

Is there anyway to write the following as a C++ macro?

my_macro << 1 << "hello world" << blah->getValue() << std::endl; should expand into: std::ostringstream oss; oss << 1 << "hello world" << blah->getValue() << std::endl; ThreadSafeLogging(oss.str()); Thanks! EDIT: the accepted answer is awesome. Can we upvote 8 more times and win this responder a badge? (The answer only needs 6 mor...

Composing objects of a class you inherit from?

I have a class Parameter, the purpose of which is to represent the possible values a certain parameter could hold (implements two key methods, GetNumValues() and GetValue(int index)). Often one logical parameter (parameter values are bit flags) is best represented by 2 or more instances of the Parameter class (i.e. a Parameter that can ...

"Automatically indent" in Carbide.c++ 2.4.0

After moving from Carbide.c++ 2.0.2 to Carbide.c++ 2.4.0 (it is 2.3.0 + update) and moving my Code Style profile, "Code style" preferences are not applied while typing in one particular case, and it is related to indent position after conditionals. My code style profile says the conditional should look like this: if (x > 3) { ...

Installing PySide - OSX

Anyone had success installing and using PySide on OSX? I am following the install instructions on the PySide site, though I'm running into issues building the API Extractor. I run cmake on the CMakeLists.txt file inside the api extractor dir and: This error is thrown- CMake Error at /Applications/CMake 2.8-0.app/Contents/share/cmake-2...

C++ destructor & function call order.

Suppose I have the following snipplet: Foo foo; .... return bar(); Now, does the C++ standard guarantees me that bar() will be called before foo::~Foo() ? Or is this the compiler/implementation's choice? Thanks! ...

http/http traffic analyzer

i would like to develop a c++ application that would list all url accessed with its response time within the pc. this probably would be transparent to the user, so it would be a dll. can anyone gve me some sample codes or tutorials on th said matter. or any tips and suggestion?!.. thanks alot:)) ...

Virtual functions with two operands that can take many different types

Let me start with a concrete example. In C++, I have a hierarchy of classes under the abstract base class CollisionVolume. Any collision volume needs to be able to detectCollision with any other volume. This collision code is specialized based on the two subclasses in presence, but it is commutative: detectCollision(a, b) == detectCollis...

C++: Why does VS2005 interpret direct-initialization of local instance as a function, when the class constructor has a polymorphic parameter?

Hi there, I have the following C++ code in Visual Studio 2005... class Base {}; class Derived : public Base {}; class Other { public: Other(const Base& obj) {} void test() {} }; int _tmain(int argc, _TCHAR* argv[]) { Other other(Derived()); other.test(); return 0; } ... Compilation fails and gives: test.cpp(19) : error C2228:...

C++ Ramifications of ignoring exception from constructor

I've searched SO for an answer to this, but haven't found one. When an object throws an exception at the end of the constructor, is the object valid or is this one of those 'depends on the construction technique'? Example: struct Fraction { int m_numerator; int m_denominator; Fraction (double value, ...

Possible to output to .doc format using Qt?

I am writing a program using Qt. I want it to output to .doc to preserve formatting but all that is supported by Qt is plain text, ODF and HTML formats. ODF and HTML will preserve the formatting but then I would have to copy and paste this to a .doc file. I want to be able to save a .doc file and not have to worry about doing this. I hav...

QueueUserWorkItem with COM in unmanaged (c++)

I have a performance issue where clients are creating hundreds of a particular kind of object "Foo" in my unmanaged (not .NET) C++ application's DOM. Each Foo instance has its own asynchronous work queue with its own thread. Obviously, that doesn't scale. I need to share threads amongst work queues, and I don't want to re-invent the...

can I use breakpoints with try catch statements with qt creator?

if an exception is thrown inside a try/catch, can i put a breakpoint there to get into debu mode before the program exits? ...

End of multi-dimensional array using compact pointer notation

For a 4-D array, I'm trying to average the values using compact pointer notation. Using examples from my text, it says I can use something like this: void DisplayAverage(double (*set)[DIM1][DIM2][DIM3]) double *ptr; double subTotal2 = 0; for (ptr = (double *)set; ptr < (double *)set + DIM0 * DIM1 * DIM2 * DIM3; ptr++) { su...