#include <string>
#include <map>
#include <memory>
#include <iostream>
struct Base
{
virtual void print() = 0;
};
struct Derived0 : Base
{
void print() override { std::cout << "d0" << std::endl; }
};
struct Derived1 : Base
{
void print() override { std::cout << "d1" << std::endl; }
};
int main()
{
std::map<std::string, std::unique_ptr<Base>> map;
map["d0"] = std::make_unique<Derived0>();
map["d1"] = std::make_unique<Derived1>();
for(auto& b : map)
{
b.second->print();
}
}
CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxtZW1vcnk+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnN0cnVjdCBCYXNlCnsKICAgIHZpcnR1YWwgdm9pZCBwcmludCgpID0gMDsKfTsKCnN0cnVjdCBEZXJpdmVkMCA6IEJhc2UKewogICAgdm9pZCBwcmludCgpIG92ZXJyaWRlIHsgc3RkOjpjb3V0IDw8ICJkMCIgPDwgc3RkOjplbmRsOyB9Cn07CgpzdHJ1Y3QgRGVyaXZlZDEgOiBCYXNlCnsKICAgIHZvaWQgcHJpbnQoKSBvdmVycmlkZSB7IHN0ZDo6Y291dCA8PCAiZDEiIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKCmludCBtYWluKCkKewogICAgCiAgICBzdGQ6Om1hcDxzdGQ6OnN0cmluZywgc3RkOjp1bmlxdWVfcHRyPEJhc2U+PiBtYXA7CgoKICAgIG1hcFsiZDAiXSA9IHN0ZDo6bWFrZV91bmlxdWU8RGVyaXZlZDA+KCk7CiAgICBtYXBbImQxIl0gPSBzdGQ6Om1ha2VfdW5pcXVlPERlcml2ZWQxPigpOwoKICAgIGZvcihhdXRvJiBiIDogbWFwKQogICAgewogICAgICAgIGIuc2Vjb25kLT5wcmludCgpOwogICAgfQp9