From: Mikko Rasa Date: Mon, 19 Dec 2022 10:04:20 +0000 (+0200) Subject: Use braced initializer lists in place of constructors when possible X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=39da82b967c70282973025e4b12186625e29fe26;p=libs%2Fcore.git Use braced initializer lists in place of constructors when possible --- diff --git a/source/core/algorithm.h b/source/core/algorithm.h index d295d00..251a81e 100644 --- a/source/core/algorithm.h +++ b/source/core/algorithm.h @@ -108,21 +108,19 @@ struct MemberMatch const T &value; T C::*mem_ptr; - MemberMatch(const T &v, T C::*p): value(v), mem_ptr(p) { } - bool operator()(const C &obj) { return obj.*mem_ptr==value; } }; template inline typename Container::iterator find_member(Container &cont, const T &value, T Container::value_type::*mp) { - return find_if(cont, MemberMatch(value, mp)); + return find_if(cont, MemberMatch{ value, mp }); } template inline typename Container::const_iterator find_member(const Container &cont, const T &value, T Container::value_type::*mp) { - return find_if(cont, MemberMatch(value, mp)); + return find_if(cont, MemberMatch{ value, mp }); } template> @@ -131,8 +129,6 @@ struct MemberCompare T C::*mem_ptr; P pred; - MemberCompare(T C::*p): mem_ptr(p) { } - bool operator()(const C &obj, const T &v) { return pred(obj.*mem_ptr, v); } bool operator()(const T &v, const C &obj) { return pred(v, obj.*mem_ptr); } bool operator()(const C &obj1, const C &obj2) { return pred(obj1.*mem_ptr, obj2.*mem_ptr); } @@ -141,37 +137,37 @@ struct MemberCompare template inline typename Container::iterator lower_bound_member(Container &cont, const T &value, T Container::value_type::*mp) { - return lower_bound(cont, value, MemberCompare(mp)); + return lower_bound(cont, value, MemberCompare{ mp }); } template inline typename Container::const_iterator lower_bound_member(const Container &cont, const T &value, T Container::value_type::*mp) { - return lower_bound(cont, value, MemberCompare(mp)); + return lower_bound(cont, value, MemberCompare{ mp }); } template inline typename Container::iterator upper_bound_member(Container &cont, const T &value, T Container::value_type::*mp) { - return upper_bound(cont, value, MemberCompare(mp)); + return upper_bound(cont, value, MemberCompare{ mp }); } template inline typename Container::const_iterator upper_bound_member(const Container &cont, const T &value, T Container::value_type::*mp) { - return upper_bound(cont, value, MemberCompare(mp)); + return upper_bound(cont, value, MemberCompare{ mp }); } template inline void sort_member(Container &cont, T Container::value_type::*mp) { - sort(cont, MemberCompare(mp)); + sort(cont, MemberCompare{ mp }); } template inline void stable_sort_member(Container &cont, T Container::value_type::*mp) { - stable_sort(cont, MemberCompare(mp)); + stable_sort(cont, MemberCompare{ mp }); } template diff --git a/source/io/eventdispatcher.cpp b/source/io/eventdispatcher.cpp index 9c233ee..035a7f2 100644 --- a/source/io/eventdispatcher.cpp +++ b/source/io/eventdispatcher.cpp @@ -69,11 +69,6 @@ void EventDispatcher::dispatch() } -EventDispatcher::Slot::Slot(EventDispatcher &d, EventObject &o): - disp(d), - obj(o) -{ } - void EventDispatcher::Slot::connect_signals() const { obj.signal_events_changed.connect(sigc::mem_fun(this, &Slot::events_changed)); diff --git a/source/io/eventdispatcher.h b/source/io/eventdispatcher.h index f95f477..d9a7afd 100644 --- a/source/io/eventdispatcher.h +++ b/source/io/eventdispatcher.h @@ -22,7 +22,7 @@ private: EventDispatcher &disp; EventObject &obj; - Slot(EventDispatcher &, EventObject &); + Slot(EventDispatcher &d, EventObject &o): disp(d), obj(o) { } void connect_signals() const; void events_changed(PollEvent) const; diff --git a/source/io/poll.cpp b/source/io/poll.cpp index 683eabe..7aa41e1 100644 --- a/source/io/poll.cpp +++ b/source/io/poll.cpp @@ -47,7 +47,7 @@ void Poller::set_object(EventObject &obj, PollEvent ev) throw invalid_state("too many objects"); #endif - objects.push_back(PolledObject(&obj, ev)); + objects.push_back({ &obj, ev }); objs_changed = true; } diff --git a/source/io/poll.h b/source/io/poll.h index c873923..4466ca3 100644 --- a/source/io/poll.h +++ b/source/io/poll.h @@ -36,10 +36,8 @@ class Poller: private NonCopyable public: struct PolledObject { - EventObject *object = nullptr; - PollEvent events = P_NONE; - - PolledObject(EventObject *o, PollEvent e): object(o), events(e) { } + EventObject *object; + PollEvent events; }; private: diff --git a/source/io/unix/poll.cpp b/source/io/unix/poll.cpp index 28d3aeb..e3db10e 100644 --- a/source/io/unix/poll.cpp +++ b/source/io/unix/poll.cpp @@ -91,7 +91,7 @@ void Poller::platform_poll(int timeout) for(unsigned i=0; (i0); ++i) if(priv->pfd[i].revents) { - poll_result.push_back(PolledObject(objects[i].object, poll_event_from_sys(priv->pfd[i].revents))); + poll_result.push_back({ objects[i].object, poll_event_from_sys(priv->pfd[i].revents) }); --ret; } } diff --git a/source/time/timer.cpp b/source/time/timer.cpp index 04c3074..eda782e 100644 --- a/source/time/timer.cpp +++ b/source/time/timer.cpp @@ -22,7 +22,7 @@ Timer::Slot &Timer::add(const TimeDelta &td) { Slot *s = new Slot(td); MutexLock l(mutex); - slots.push_back(s); + slots.push_back({ s }); push_heap(slots.begin(), slots.end()); if(blocking) sem.signal(); @@ -33,7 +33,7 @@ Timer::Slot &Timer::add(const TimeStamp &ts) { Slot *s = new Slot(ts); MutexLock l(mutex); - slots.push_back(s); + slots.push_back({ s }); push_heap(slots.begin(), slots.end()); if(blocking) sem.signal(); @@ -113,7 +113,7 @@ void Timer::do_tick(const TimeDelta &timeout) if(next->signal_timeout.emit() && next->increment()) { MutexLock l(mutex); - slots.push_back(next); + slots.push_back({ next }); push_heap(slots.begin(), slots.end()); } else @@ -152,10 +152,6 @@ bool Timer::Slot::increment() } -Timer::SlotProxy::SlotProxy(Slot *s): - slot(s) -{ } - bool Timer::SlotProxy::operator<(const SlotProxy &sp) const { return slot->get_timeout()>sp.slot->get_timeout(); diff --git a/source/time/timer.h b/source/time/timer.h index 3325731..04d0be9 100644 --- a/source/time/timer.h +++ b/source/time/timer.h @@ -41,9 +41,8 @@ public: private: struct SlotProxy { - Slot *slot = nullptr; + Slot *slot; - SlotProxy(Slot *); bool operator<(const SlotProxy &) const; };