[fusion][?] a dictionary with compile time (or types as) keys
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
On 02/16/14 12:30, Nick Stokes wrote:
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
Wouldn't: http://www.boost.org/doc/libs/1_55_0/libs/fusion/doc/html/fusion/container/m... work? -regards, Larry
On Feb 17, 2014, at 8:20 AM, Larry Evans
wrote: On 02/16/14 12:30, Nick Stokes wrote: 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 Wouldn't:
http://www.boost.org/doc/libs/1_55_0/libs/fusion/doc/html/fusion/container/m...
work?
I think the OP is looking for something runtime, i.e. type-erased. I know I have seen such a thing but I don't recall seeing one in Boost. Cheers, Gordon
On Mon, Feb 17, 2014 at 12:20 PM, Gordon Woodhull
Thanks many, Nick
Wouldn't:
http://www.boost.org/doc/libs/1_55_0/libs/fusion/doc/html/fusion/container/m...
work?
I think the OP is looking for something runtime, i.e. type-erased. I know I have seen such a thing but I don't recall seeing one in Boost.
Yes, indeed.
Le 16/02/14 19:30, Nick Stokes a écrit :
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.
Hi, we have added to Boost.Application a class aspect_map [1] that is quite close to your expectations. It could be proposed independently. There is also a Boost.Mixin proposal that could help also. HTH, Vicente https://github.com/retf/Boost.Application/blob/master/include/boost/applicat...
Hi Vicente, On Mon, Feb 17, 2014 at 1:22 PM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
Hi,
we have added to Boost.Application a class aspect_map [1] that is quite close to your expectations. It could be proposed independently.
This looks very interesting. So, afaict, the mapping hinges on a type id csbl::type_index. Is this some kind of a std::type_info?
There is also a Boost.Mixin proposal that could help also.
Thanks, I'll have a look at this. (this: https://github.com/iboB/boost.mixin ?)
participants (4)
-
Gordon Woodhull
-
Larry Evans
-
Nick Stokes
-
Vicente J. Botet Escriba