GPLv3 draft. C++ CRTP
A new discussion draft of the GNU GPL has been released. Go here to see more. Note the end of the Patents section in the changes guide:
specifically granted to recipients of the covered work under this License[, unless you entered into that arrangement, or that patent license was granted, prior to March 28, 2007].
I heard for first time about the Curiously Recurring Template Pattern when I read the Eigen library webpage. Now I found this example by Bruce Eckel that makes it much clearer:
//: generics/Mixins.cpp
#include
#include
#include
template
long timeStamp;
public:
TimeStamped() { timeStamp = time(0); }
long getStamp() { return timeStamp; }
};
template
long serialNumber;
static long counter;
public:
SerialNumbered() { serialNumber = counter++; }
long getSerialNumber() { return serialNumber; }
};
// Define and initialize the static storage:
template
int main() {
TimeStamped<SerialNumbered<string> > mixin1, mixin2;
mixin1.append(“test string 1″); // A string method
mixin2.append(“test string 2″);
cout << mixin1 << ” ” << mixin1.getStamp() << ” ” <<
mixin1.getSerialNumber() << endl;
cout << mixin2 << ” ” << mixin2.getStamp() << ” ” <<
mixin2.getSerialNumber() << endl;
}
The effect you get is basically what you get with Ruby Mixins.





Spam Poison
Duncan, your blog eats C++ markup as html formatting. Not good. (Replace all less signs with < maybe?)
berkus
1 Apr 07 at 8:41 am