Boost logo

Boost :

From: Reid Sweatman (borderland_at_[hidden])
Date: 2000-07-27 10:09:30


> One of the goals for templates was to eliminate the need for the C
> preprocessor. That goal was met for most traditional uses of CPP.
> But one use of the C preprocessor has always been to create new
> syntatic forms where coding in straight C was too difficult but
> using another language to generate C was not a good option. For
> example, we make heavy use of macros to code our Java object model
> in C. As we push the limits of template metaprogramming we find
> ourselves with a similar mismatch, which eventually will need to
> be resolved with new syntax in C++, and/or new languages better
> suited to the idiom.

That's about the only time I bother to use anything else as a preprocessor,
too. Generally to define a metalanguage that's closer to the problem
domain, so that I don't have to do massive recoding of C/C++ code when
something large changes in the problem domain. One example, a PERL script
that parsed a LISP-like metalanguage into pretty well optimized C (this was
several years ago) for a natural-language front end. Every time I changed
the syntax the parser understood, all I had to change was a line or two of
metacode, rather than a lot of heavily-interdependent code.

Of course, I'll wager, thinking about it, that I could have achieved pretty
much the same thing (recursive-descent parser and code generator) using
templates, had I had them. Still, it would have been much more complex to
write that way. But now that you've put the idea in my head, I might try it
for the interface on my current project. That piece is still a ways down
the pike, so it could work.


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