views:

283

answers:

6

Does anybody know of any libraries that use design patterns that are implemented using compile-time techniques e.g. template metaprogramming? I know that Loki implements a few but I need to find other libraries.

+6  A: 

Boost.Spirit is a pretty big one.

Dean Harding
which patterns can be/are used by it?
feelie
A: 

I think that you are asking for libraries that help to use design pattern more that libraries using design patterns, isn't it?

There are some in Boost but not too much, like Flyweight - Design pattern to manage large quantities of highly redundant objects.

The not yet released but accepted library Boost.Factory and the rejected library Boost.Singleton

There are also some libraries that implements C++ idioms as Boost.Pimpl (on the review schedule), Scope Exit (accepted), Memoizer.

Vicente Botet Escriba
boost::iterator_Facade is another big one (at least for me)
Billy ONeal
I'm doing research on the design patterns so it is more on the implementation of the design patterns but libraries that help you use them or that use them in their own implementation is fine
feelie
Wow, the answer was accepted and no one up voted. Is this possible?
Vicente Botet Escriba
+1  A: 

Some libraries that use expression templates: ublas, blitz, matrix template Library, ftensor, or Google C++ template matrix to find even more.

by the way, ftensor is really slick http://www.gps.caltech.edu/~walter/FTensor/FTensor.pdf.

aaa
+1  A: 

It depends on what design pattern you are interested in. There are some like "Active Object" and Dispose that would have a hard time being implemented at compile time.

"interpreter" pattern -> boost.ublas and blitz++ both use "expression templates"

"bridge" pattern -> Every standard container takes an "allocator" argument (most of Loki is bridge patterns as well)

"strategy" pattern -> STL template functions choose the best implementation based on the argument types

The only difference in all of these is that the evaluation of the pattern happens when the compiler runs, rather then when the executable runs. So all you need is to adjust your thinking slightly: The templates are the program, and the "C++ compiler" runs and interprets this program. The output of this template program is an object file ready for linking. In other words, your template code's runtime is precisley when your compiler is running. C++ templates are a turing complete functional language, just like lisp or XSLT.

In fact the very first template metaprogram in 1993 had as its output not an executable, but a series of compiler errors that printed the fibonacii sequence or something like that.

Lance Diduck
A: 

This looks like my assigment too. :)

walters
A: 

Doen almal GPG hier?

Anycase those implemented in Loki: - Factory Abstract - Factory - Singleton - Visitor - Command

In boost Flyweight

In STL you have iterators, and adapters, although I'm pretty sure they don't count due to being being compile-time?

The original specification is somewhat vague,

< Make sure that you do not confuse generic programming (template-based implementations) with other compile-time techniques. >

Anyone have a clue as to what the above question means?

LopLop