The Pass-through idiom

This is a programming idiom that I've made a lot of use of. It originates from C programming style that emulated the use of object. Coplien 1992 mentions it and describes it as the handler idiom.

I call it the pass-through idiom. You pass the object you want the result stored in to the function.

double x;
if (!as(&x, o)) {
}

The idea is that you can:

You can do something advanced like this.

std::vector<double> * px;
std::auto_ptr<std::vector<double> *> apx = new std::vector<double>(10);
int fails=0;
if ( (px = !render(apx.get(), l, (null0<double>())() ), &fails) && fails == 0) {
  return; // failed: couldn't convert all, so auto_ptr will clean up
}

// Use the vector.

Generated on Thu Feb 18 21:30:12 2010 for eleve by  doxygen 1.5.6