The following code does not work as per my understanding. When the `Raise`
 method of the handler object is called, random (I assume uninitialised variable) values are printed. My suspicion is that the `map::insert` calls made in `CreateTests` results in some sort of move that results in the invalidation of `this` parameters provides to the `std::function` objects provided to `EventCoordinator::Register`. The intended output of this program would be 2 lines printed in the console, with values `0` & `1` printed. Can somebody advise what the error here is? 

```
#include <map>
#include <functional>
#include <vector>
#include <iostream>

class EventCoordinator
{
    using Handler = std::function<void()>;
    using Handlers = std::vector<Handler>;

    std::map<int, Handlers> HandlerMap;

public:

    void Register(const int id, std::function<void()> handler)
    {
        HandlerMap[id].emplace_back(handler);
    }

    void Raise(const int id)
    {
        try {
            auto handlers = HandlerMap.at(id);
            for (const auto& handler : handlers) {
                handler();
            }
        }
        catch (std::exception& e) {
            std::cout << e.what();
        }

    }
};

class test
{
public:
    test() : mId(-1)
    {
        std::cout << "test default constructor\n";
    }
    test(const int id, EventCoordinator& handler) : mId(id)
    {
        handler.Register(mId, std::bind(&test::func, *this));
    }

    void other()
    {
        std::cout << this << '\n';
    }

    void func() const
    {

        std::cout << this <<'\n';
        std::cout << mId << '\n';
    }
    ~test() = default;
    test(const test& other) = default;
    test(test&& other) noexcept = default;
    test& operator=(const test& other) = default;
    test& operator=(test&& other) noexcept = default;
    int mId;
};

std::map<int, test> CreateTests(EventCoordinator& handler)
{
    auto returnMap = std::map<int, test>();
    returnMap.emplace(std::make_pair(0, test(0, handler)));
    returnMap.emplace(std::make_pair(1, test(1, handler)));
    return returnMap;
}

int main(int argc, char** args)
{
    EventCoordinator handler;
    auto ret = CreateTests(handler);
    handler.Raise(0);
    ret[0].other();
    handler.Raise(1);
    ret[1].other();
    std::cin.get();
}

```