Boost logo

Boost Users :

Subject: [Boost-users] [fusion][?] a dictionary with compile time (or types as) keys
From: Nick Stokes (randomaccessiterator_at_[hidden])
Date: 2014-02-16 13:30:01


The problem is the following:

class TypeDictionary {
public:
   // implementation be here -- and the question is about this
};

struct Foo;
struct Bar;

void userOfTypeDictionary() {

    TypeDictionary td;

    td.insert( Foo() );
    td.insert( Bar() );
    td,insert( double(3.14) );
    // and other unknown (to TypeDictionary)
    // list of types attached

    // later on, in a different scope perhaps
    Foo& f = td.get<Foo>() ;
    Bar& f = td.get<Bar>();
    double pi = tg.get<double>();
    // ...
}

Now the question so far seems like right up in the alley of Boost.Fusion,
perhaps with a boost::fusion::set, but I am unsure how to manipulate a set
of types unknown ahead of time as in code above, and with a -- rather
obvious -- extension whereby different instances of TypeDictionary would
be used to contain a different set of types, potentially in different
compilation units.

As for a realistic motivating use case, think of a plugin manager. At any
given time of its life an arbitrary heterogeneous set of objects are
attached to it, and the it is the manager's job to manage the life time of
the attached objects and return (a reference) to them when queried in a
type-safe manner.

Any ideas on whether such a thing is possible, and how, would be deeply
appreciated.

Thanks many,
Nick



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