filinep
filinep

Reputation: 549

What libraries use design patterns implemented with compile-time metaprogramming techniques?

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.

Upvotes: 4

Views: 1067

Answers (5)

LopLop
LopLop

Reputation: 1

Doen almal GPG hier?

Any case 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?

Upvotes: 0

Lance Diduck
Lance Diduck

Reputation: 1561

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.

Upvotes: 2

Anycorn
Anycorn

Reputation: 51545

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.

Upvotes: 1

Vicente Botet Escriba
Vicente Botet Escriba

Reputation: 4355

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.

Upvotes: 0

Dean Harding
Dean Harding

Reputation: 72668

Boost.Spirit is a pretty big one.

Upvotes: 6

Related Questions