hash_map<std::string, list<Listener*>> * listeners;
/// и есть такой конструктор
EventManager::EventManager(list<std::string>* eventsType){
typedef pair<std::string, std::list<Listener*>> mapData;
for (auto iter = eventsType->begin(); iter != eventsType->end(); iter++) {
list<Listener*> a;
this->listeners->insert(mapData(*iter,a)); // все фегня все не работает
}
}
#include <iostream>
#include <memory>
#include <unordered_map>
#include <list>
struct Listener
{
std::string _name;
Listener(std::string name) : _name{ name }{}
~Listener() = default;
};
using Listeners = std::unordered_map<std::string, std::list<Listener>>;
class EventManager
{
public:
EventManager(std::list<std::string>& eventTypes);
//...
~EventManager() = default;
void print()
{
for(const auto& v : *m_listeners)
{
std::cout << v.first << " -> ";
for(const auto& s : v.second)
{
std::cout << s._name << ' ';
}
std::cout << std::endl;
}
}
private:
std::unique_ptr<Listeners> m_listeners;
};
EventManager::EventManager(std::list<std::string>& eventTypes)
: m_listeners { std::make_unique<Listeners>() }
{
auto insert_it(std::end( *m_listeners ));
for (const auto &et : eventTypes)
{
insert_it = m_listeners->insert( insert_it, {et, {}} );
}
}
int main()
{
std::list<std::string> events { "Open", "Move", "Close" };
EventManager eManager{ events };
eManager.print();
}