[英]A std::map like container that maps types to values
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:
代码snippit价值1024字,所以:
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? 是否有一个具有此接口或类似接口的Boost库?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.