dynamictracer

This sunday, we developed a really cool dynamic tracer for AspectC++.

#include <iostream>
using namespace std;
 
struct X { X (...) {} };
 
typedef char magically_sized_type[43564367];
magically_sized_type &operator << (ostream &os, X);
 
template <typename T> struct detector {
  enum { RET = (sizeof (cout << T()) == sizeof (magically_sized_type)) };
};
 
template <typename T, int> struct Printer {
  static void print (ostream &out, const T &arg) {
    out << arg << endl;
  }
};
 
template <typename T> struct Printer<T,1> {
  static void print (ostream &out, const T &arg) {
    out << "Unprintable type, addr: " << &arg 
	<< "size: " << sizeof (T) << endl;
  }
};
 
template <typename T> void print (ostream &out, const T &arg) {
  Printer<T, detector<T>::RET>::print (out, arg);
}
 
int main() {
  print(std::cout, "Teststring");
  print(std::cout, 4711);
  print(std::cout, 11.1);
}

The interesting part about this pattern is, that it uses the operatorĀ« for types which have such an operator, and an alternate implementation, which doesn't need it. I need it for implementing a generic tracer.

Please tell me if someone can construct a type or construction, which fails for this tracer.

~~DISCUSSION~~

tech english aop uni