c++

Polymorphic functors in std::for_each

I'm trying to use stl algorithm for_each without proliferating templates throughout my code. std::for_each wants to instantiate MyFunctor class by value, but it can't since its abstract. I've created a functor adapter class which passes a pointer around and then derefernces it when appropriate. My Question: Does the STL or Boost alrea...

How would you improve this algorithm? (c string reversal)

Working through some programming interview challenges I found online, I had to write an algorithm to reverse a const char * and return a pointer to a new char *. I think I have it, but to make it work properly I had to do some wonky stuff - basically having to account for the null-terminating character myself. Somehow I feel this is wron...

VCL alternative to IStorage

Hello To preface I am using Borland C++ and the VCL. I need some sort of structured storage object which can be saved to disk as a single file and can contain multiple named blobs of binary data which I can programatically enumerate, access and manipulate. The IStorage interface seems to be close what I want but I would prefer a VCL s...

Dealing with C++ "initialized but not referenced" warning for destruction of scope helpers?

In Visual Studio, I often use objects only for RAII purposes. For example: ScopeGuard close_guard = MakeGuard( &close_file, file ); The whole purpose of *close_guard* is to make sure that the file will be close on function exit, it is not used anywhere else. However, Visual Studio gives me a warning that a "local variable is initial...

What use are const pointers (as opposed to pointers to const objects)?

I've often used pointers to const objects, like so... const int *p; That simply means that you can't change the integer that p is pointing at through p. But I've also seen reference to const pointers, declared like this... int* const p; As I understand it, that means that the pointer variable itself is constant -- you can change th...

how to get as much as possible from dbx

I do TDD on a daily basis for my C++ development on Solaris10. It has greatly reduced the time I have to spend using my debugger but sometime this is the only option. DBX is pretty powerful but not that user friendly. Note that I'm talking about console DBX not the SunStudio GUI for DBX). What are the best productivity tips you can giv...

Determine Process Info Programmatically in Darwin/OSX

I have a class with the following member functions: /// caller pid virtual pid_t Pid() const = 0; /// physical memory size in KB virtual uint64_t Size() const = 0; /// resident memory for this process virtual uint64_t Rss() const = 0; /// cpu used by this process virtual double PercentCpu() const = 0; /// memory used by this p...

How do you deal with NUL?

From time to time, I run into communications issue with other programmers, when we talk about NULL. Now NULL could be a NULL pointer the NUL character an empty data element in some sort of database. NUL seems to be the most confusing. It is the ASCII character 0x00. I tend to use '\0' in my code to represent it. Some develop...

C++ IDE for Macs

I teach a C++ course using Visual Studio. One of my students has a Mac, and was looking for an IDE to use on his machine. What would be good to recommend? ...

Using set.insert( key ) as a conditional?

I am trying to use set.insert (key) as a conditional, where if the key is inserted correctly (meaning that the key does NOT already exsist in the set ) then it should go on and perform some kind of code. For example, something like: if (set.insert( key ) { // some kind of code } Is this allowed? Because the compiler is throw...

What is the C++ memory model for concurrency?

What is the C++ memory model for concurrency as defined by current standard? What about upcoming C++0x standard? Will it change the memory model to support concurrency better? ...

C++ bindings for MySQL

I'm running OSX(10.4.11) & I'm trying to get a decent C(preferably C++) binding for MySQL figured out. I have some data in an offsite database I want to analyze. I'm trying to get MySQL++ working, but it's being funky. I'm looking for other bindings, preferably ones with a no-headache install. edit: MySQL has C bindings. Clunky and ...

Easy way to shift specific characters in a string in C++?

As an example, if I have the string: ".....ZZ..ZZ....." or ".Z.1.Z.23Z.4.Z55" is there an easy way that I can shift each Z in that string one space to the right? Thanks in advance, Tomek Some additional test strings: ".Z" "Z." "ZZ." ".ZZ" "Z" "ZZ" "ZZZ" I think a few of the higher voted answers to this question (including the cu...

Should my C++ program support IA64 or only x64?

Should my program support IA64, or should it only support x64? I haven't been able to easily find IA64 computers myself. Is IA64 dead? MS seems to have a wide support for IA64, but it took me a long time to be able to find an IA64, and I had to end up getting it on eBay. ...

In what syntax should a COM SDK reference document be written?

I have a COM SDK written in C++ and I'd like to create documentation for my product. I understand that most people will probably not use C++ for integration with this COM component, but many will. Which method is best to describe the API, without losing details that a C++ developer would need to know. ...

How to run C/C++ in a Unix console/Mac terminal?

I know it, forgets it and relearn it again. Time to write it down. ...

Converting Simplifed Chinese GB 2312 text characters into UTF8

How do I convert text between Simplified Chinese GB 2312 or similar multi-byte text strings into UTF8 using c++ ? ...

What is the arrow operator (->) synonym for in C++?

I know it, forgets it and relearn it again. Time to write it down. ...

Unit testing with C/C++: Lessons, what to remember?

Unit testing with C/C++: What do you teach people who either did not do unit testing before or come from Java/Junit? What is the single most important lesson / thing to remember/ practice from your point of view that saves a lot of time or stress (especially regarding C/C++)? ...

C++: Get MAC address of network adapters on Vista?

We are currently using the NetBios method, and it works ok under XP. Preliminary tests under Vista show that it also works, but there are caveats - NetBIOS has to be present, for instance, and from what I've been reading, the order of the adapters is bound to change. Our alternative method - with SNMPExtensionQuery - seems to be broken u...