Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-07-19 07:28:59


I've uploaded two experimental programs and a copy of the metactrl header
to
http://www.egroups.com/files/boost/TMPX/

The point is to gain some experience with the Czarnecki and Eisenecker
template metaprogramming techniques in the context of a smart pointer
generator.

Using Microsoft VC++ 6.0 SP3 (because it often has trouble with templates),
experiment1.cpp compiled and ran correctly the first try. I made several
stupid syntax errors in experiment2,cpp, but after correcting those it
compiled and ran right away. The first time I tested it, operator T* was
not being selected. I had typedef'ed ptr_type to type2 instead of
type3. Easy to find. C&E used more explicit names for inheritance
hierarchies; that might have prevented the typo.

All-in-all a very pleasant experience. The coding idioms felt natural. No
difficulty moving from the examples in the book to a real world problem.

The only thing missing was an easy-to-use error reporting mechanism. See
the commented out error check in the generator in experiment2.cpp.

One thing I am still a little fuzzy about is when to use inheritance vs
static forwarding functions to vary features.

Naming is going to be challenging; in real code names like "array" need to
be chosen and namespaced in ways to prevent name clashes yet retain coding
ease.

For experiment 2, I didn't give names to the defaults. For example,
"array" is an option; there is not "nonarray" to acknowledge acceptance of
the default. Makes the interface a bit simpler, but...

I guess the next experiment might be to add scoped/shared/etc ownership
choices, together with some of their sub-options.

--Beman

The output of experiment2.cpp was:

assembly via generator

experimental_ptr base class
  adding dereference operators
string a, ptr size=4
DeleteDestruction

experimental_ptr base class
  adding dereference operators
string b, ptr size=4
UserDestruction

experimental_ptr base class
  adding dereference operators
string c, ptr size=4
NoDestruction

experimental_ptr base class
  adding dereference operators
  adding operatorT*
string d, ptr size=4
DeleteDestruction

experimental_ptr base class
  adding operator[]
1,2,3, ptr size=4
ArrayDeleteDestruction

experimental_ptr base class
  adding operatorT*
1,2,3, ptr size=4
ArrayDeleteDestruction


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk