I'm looking for a hybrid meta-container/container class. I want a class that maps a compile-time type to a runtime value. A code snippit is worth 1024 words so:
struct Foo { /* ... */ };
struct Bar { /* ... */ };
int main()
{
meta_container<Foo,float,int> mc;
mc.get<float>() = 1.0f;
mc.get<Foo>().method(blah);
mc.get<Bar>(); //compiler error
}
This is really boring stuff. An implementation using variadic templates would be interesting enough but the interface is very simple.
The part that makes this more difficult is this last feature I want.
void foo( const meta_constainer<Foo,Bar,Baz>& mc );
//make_mc is sorta like make_pair or make_tuple.
int main()
{
foo( make_mc(Foo(), Bar(), Baz()) ); // not really interesting
foo( make_mc(Bar(), Foo(), Baz()) ); // this is more challenging
foo( make_mc(Foo()) ); // this might be difficult as well.
}
I could write such a container, but I'd like to find one that's already written/debugged. My biggest stumbling block has been lack of good keywords to search for (heterogeneous container is not what I want).
Is there a Boost library that has this or a similar interface?
What is this thing called, so I can google it more effectively?
update:
I am not looking for:
boost::mpl::map
std::map<*,boost::any>
std::map<*,boost::variadic<*>>
std::map<typeid,boost::variadic<*>>
boost::fusion : http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With