$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Stathie Triadis (stathie_at_[hidden])
Date: 2008-02-28 18:04:44
Boost Users/Developers,
I'm writing to gauge interest in an 'abstract factory',
very similar to the recently accepted functional/factory.
I realise there has been interest in this idea in the past
(ctor_fn), but nothing seems to have come of it (that I am
aware of). Does anything similar exist?
Example code:
//
// Given an inheritance hierarchy where the base class
// constructor has a certain signature...
//
struct A
{
A(const string&, int){}
virtual ~A(){}
};
struct B : public A
{
B(const string& s, int i) : A(s, i) {}
virtual ~B(){}
};
//
// typedef some factories...
//
typedef abstract_factory<A*(const string&, int)> AFactory;
typedef concrete_factory<AFactory, B*, MyAllocator> BFactory;
//
// Use them...
//
AFactory* factory = new BFactory;
A* a = (*factory)("a string", 1); // Look ma, temporaries.
assert(dynamic_cast<B*>(a));
vector<string> v1;
vector<A*> v2;
transform(v1.begin(), v1.end(), back_inserter(v2),
bind<A*>(ref(*factory), _1, 1234));
The naming of 'abstract_factory' and 'concrete_factory' is
reminiscent of the Loki AbstractFactory and ConcreteFactory,
as is the idea of passing the abstract_factory as a template
parameter into concrete_factory.
I'm new to this mailing list as well, so I'm not aware of
all previous conversation on this topic.
What do you think?
Stathi