def*_*ode 7 c++ templates metaprogramming
我正在寻找一个混合元容器/容器类.我想要一个将编译时类型映射到运行时值的类.代码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
}
Run Code Online (Sandbox Code Playgroud)
这真是无聊的东西.使用可变参数模板的实现会很有趣,但界面非常简单.
使这更难的部分是我想要的最后一个功能.
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.
}
Run Code Online (Sandbox Code Playgroud)
我可以编写这样一个容器,但我想找一个已经编写/调试过的容器.我最大的绊脚石是缺乏搜索的好关键词(异构容器不是我想要的).
是否有一个具有此接口或类似接口的Boost库?
这个东西叫什么,所以我可以更有效地谷歌?
更新:
我不是在寻找:
boost::mpl::mapstd::map<*,boost::any>std::map<*,boost::variadic<*>>std::map<typeid,boost::variadic<*>>