c++

Are vectors more rigorous at checking out of bounds than heap arrays?

How rigorous is the bounds checking on vectors compared to heap arrays? How exactly is it checking bounds and how does that compare with how a heap array is checked? ...

Can overloading is possible with two version of function, constant member function and function without const

Hello, I just came across various overloading methods like type of parameter passed, varying number of parameters, return type etc. I just want to know that can I overload a function with following two version //function which can modify member String //constant member function String Please let me know the reason behind it. Than...

is there any faster way to parse than by walk each byte?

is there any faster way to parse a text than by walk each byte of the text? I wonder if there is any special CPU (x86/x64) instruction for string operation that is used by string library, that somehow used to optimize the parsing routine. for example instruction like finding a token in a string that could be run by hardware instead of...

Item in multiple lists

So I have some legacy code which I would love to use more modern techniques. But I fear that given the way that things are designed, it is a non-option. The core issue is that often a node is in more than one list at a time. Something like this: struct T { T *next_1; T *prev_1; T *next_2; T *prev_2; int value; }; t...

Checking for open ports in C/C++

There have been other questions regarding the subject of verifying the accessibility and accessibility of socket ports. How would one go about looking for a port to listen on dynamically in C/C++? The basic process I'm trying to accomplish is this: Client starts Client finds open port XYZ and listens on it. Client transmits a basic...

Callgrind for c++ code coverage

Is Callgrind, which is part of valgrind suite a good candidate for C++ code coverage?? ...

any stl/boost functors to call operator()

template <typename T> struct Foo { void operator()(T& t) { t(); } }; Is there any standart or boost functor with the similar implementation? I need it to iterate over container of functors: std::for_each(beginIter, endIter, Foo<Bar>()); Or maybe there are other way to do it? ...

CURL C API: callback was not called

Hi all, The code below is a test for the CURL C API . The problem is that the callback function write_callback is never called. Why ? /** compilation: g++ source.cpp -lcurl */ #include <assert.h> #include <iostream> #include <cstdlib> #include <cstring> #include <cassert> #include <curl/curl.h> using namespace std; static size_t writ...

Stringified template argument

Is it possible to get a stringified version of a template argument name? Something like this, if only we were running the preprocessor: template <typename T> struct Named{ const char* name(){ return "Named<" #T ">"; } }; Edit Duplicate. See here http://stackoverflow.com/questions/1488186/stringifying-template-arguments ...

Storing objects in the array

Hello, I want to save boost signals objects in the map (association: signal name → signal object). The signals signature is different, so the second type of map should be boost::any. map<string, any> mSignalAssociation; The question is how to store objects without defining type of new signal signature? typedef boost::signals2::signal...

Do I have to bind an UDP socket in my client program, to receive data? (I always get WASEINVAL)...

Hey There, I have the following problem: I am starting WSA, then I am creating a UDP socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) and try to recvfrom on this socket, but it always returns -1 and I get WSAEINVAL (10022)... I don´t know why?... When I bind the port, that does not happen... But it is very lame to bind the clients socket......

C++ function-pointer and inheritance

I have an generic math-method, that operates under a set of functions (with a lot of variables and states, so it can't be static). I've implemented method in parent class and I want to declare a different set of functions in every child-class. I've try to do something like this: class A { public: typedef int (A::*func)(); func *...

Thread raising event gets blocked by handlers?

I am raising an event from managed C++ which is handled by a C# app. Is the C# event handler executed on the same thread it was raised from C++ ?? In other words, Is raising event blocking for C++ until it is completely handled by C#? ...

Is Private Bytes >> Working Set normal?

OK, this may sound weird, but here goes. There are 2 computers, A (Pentium D) and B (Quad Core) with almost the same amount of RAM running Windows XP. If I run the same code on both computers, the allocated private bytes in A never goes down resulting in a crash later on. In B it looks like the private bytes is constantly deallocated a...

Tips for submitting a library to Boost?

Hi everyone, Summer is coming, and a group of friends and I are getting ready for it :) We decided to build a compile-time Arbitrary precision Unsigned Integers. We would like to provide a set of integers algorithms(functions) with the library. We have seen a number of requests for such a library(SoC2010, C++0x Standard Library wishlis...

accessing a vector from the back

Is there a way to access an element on a vector starting from the back? I want to access the second last element.currently I'm using the following to achieve that: myVector[myVector.size() - 2] but this seems slow and clunky, is there a better way? ...

Vertical Rebar (WinAPI)

I was wondering if it was possible to make a Rebar that goes vertically instead of controls horizontally? Thanks ...

boost::threads - how to do graceful shutdown?

I'm trying to improve the portability of a C++ app by using boost:threads instead of our own wrapper over Win32 threads, and the issue of graceful thread termination (again) rears its ugly head. On pure win32, I 'interrupt' threads by using QueueUserAPC to throw a "thread_interrupt" exception which causes all RAII objects to cleanup on ...

Angle between 3 vertices

For example, GetAngle((0,0),(100,0),(100,100)) = 90. How could I find the angle between 3 2D Points. ...

How to find the real problem line in my code with Application Verifier ?

I am now trying to use this Application Verifier debugging tool, but i am stuck, first of all: it breaks the program at a line that is simple variable set line (s = 1; for example) Secondly, now when i run this program under debugger, my program seems to have changed its behaviour: i am drawing image, and now one of the colors has chang...