Duncan Mac-Vicar P.


GPLv3 draft. C++ CRTP

with one comment

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
using namespace std;

templateT> class TimeStamped : public T {
  
long timeStamp;
public:
  
TimeStamped() { timeStamp = time(0); }
  
long getStamp() { return timeStamp; }
};

templateT> class SerialNumbered : public T {
  
long serialNumber;
  static
long counter;
public:
  
SerialNumbered() { serialNumber = counter++; }
  
long getSerialNumber() { return serialNumber; }
};

// Define and initialize the static storage:
templateT> long SerialNumbered<T>::counter = 1;

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.

Written by duncan

March 29th, 2007 at 9:47 am

Posted in uncategorized

Tagged with , , ,

One Response to 'GPLv3 draft. C++ CRTP'

Subscribe to comments with RSS or TrackBack to 'GPLv3 draft. C++ CRTP'.

  1. Duncan, your blog eats C++ markup as html formatting. Not good. (Replace all less signs with &lt; maybe?)

    berkus

    1 Apr 07 at 8:41 am

Leave a Reply