Browse Source

Copy map before looping over it because it might be modified.

cl-refactor
chriseth 10 years ago
parent
commit
d75f8595de
  1. 18
      libdevcore/CommonData.h
  2. 12
      libethcore/Common.h

18
libdevcore/CommonData.h

@ -349,6 +349,24 @@ std::vector<T> keysOf(std::unordered_map<T, U> const& _m)
return ret;
}
template<class T, class U>
std::vector<U> valuesOf(std::map<T, U> const& _m)
{
std::vector<U> ret(_m.size());
for (auto const& i: _m)
ret.push_back(i.second);
return ret;
}
template<class T, class U>
std::vector<U> valuesOf(std::unordered_map<T, U> const& _m)
{
std::vector<U> ret(_m.size());
for (auto const& i: _m)
ret.push_back(i.second);
return ret;
}
template <class T, class V>
bool contains(T const& _t, V const& _v)
{

12
libethcore/Common.h

@ -154,9 +154,9 @@ public:
friend class Signal;
public:
~HandlerAux() { if (m_s) m_s->m_fire.erase(m_i); m_s = nullptr; }
~HandlerAux() { if (m_s) m_s->m_fire.erase(m_i); }
void reset() { m_s = nullptr; }
void fire(Args&&... _args) { m_h(std::forward<Args>(_args)...); }
void fire(Args const&... _args) { m_h(_args...); }
private:
HandlerAux(unsigned _i, Signal* _s, Callback const& _h): m_i(_i), m_s(_s), m_h(_h) {}
@ -181,11 +181,11 @@ public:
return h;
}
void operator()(Args&... _args)
void operator()(Args const&... _args)
{
for (auto const& f: m_fire)
if (auto h = f.second.lock())
h->fire(std::forward<Args>(_args)...);
for (auto const& f: valuesOf(m_fire))
if (auto h = f.lock())
h->fire(_args...);
}
private:

Loading…
Cancel
Save