Boost logo

Boost Users :

From: Nat Goodspeed (nat_at_[hidden])
Date: 2007-12-21 15:48:29


Peter Dimov wrote:

>> given a string from a file or a script, I need to instantiate a distinct
>> C++ class corresponding to that string.

> Typically you'll have something like
>
> std::map< std::string, boost::function<std::auto_ptr<A>()> > s_factory;
>
> where A is your abstract base, and initialize s_factory with
>
> s_factory[ "X" ] = boost::factory< std::auto_ptr<X> >();

Thanks. That resembles what I built myself. I'd still like to see
something very like this in the documentation examples.

I may still be missing opportunities for compile-time polymorphism, and
perhaps it's true that including machinery like the above as part of an
expanded Boost library would unnecessarily constrain the uses of the
existing library. I'd like to see examples of some of those other uses, too.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net