Tech

Return two values from a C++ function

Ever wish you could do something like this in C++? Create a function that takes one parameter and returns two values?

        const char * fileBegin;
        const char * fileEnd;
        (fileBegin, fileEnd) = AFunctionThatReturnsAPairOfStrings(fileName);

It is possible, with a slight modification. Returning two items in a struct or class is, of course, not a new idea. But I want the maximum ease for extracting the results and assigning them to variables.

Update: This is exactly what Boost tie does.

        const char * fileBegin;
        const char * fileEnd;
        make_refpair(fileBegin, fileEnd) = mmapFile(fileName);

I've defined a simple class and an accompanying function make_refpair to allow this, which I describe below. It seems like an obvious solution, but I can't quickly find anybody who's done this before. E.g. they miss this on stackoverflow. Of course, there is nothing novel in returning a pair<>, but I want the convenience of assigning both variables to the contents of the returned pair. Anybody seen something similar/better?

Aaron

Shameless plug

My parents run Larkfield Bed and Breakfast and I'm trying to update their site a little. It's hosted on something called 'Little Ireland' and their syntax is a bit strange.

For example, I need to enter something like .head1Larkfield Bed and Breakfast.endhead1 to get a H1. I can't enter HTML in because it htmlencodes it. Any ideas on how I might encode links - maybe something like .link ?

Tech things to hack on

Here's a few things I might work on someday...

  • Get sum to list averages and standard deviations too.
  • Test that the latest Debian installer works on my computer from scratch
  • Find a Free Mathematica clone...

Any ideas?

Debian on a Dell Precision T3400

I recently bought a Dell Precision T3400, but the Debian Etch DVD wouldn't install. Ubuntu worked fine, but after trying a few different kernels I found out about Etch And A Half and it worked for me with an otherwise standard Debian Etch installation. I'm still playing with it and expect to possibly have to change a few things - for example sound didn't work straight away but it's working now.

Syndicate content