Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions thread/SignalSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,25 @@ class Signal<RET(ARGS...)> : boost::noncopyable
{
}

Slot connect(Callback&& func)
template<typename Func>
Slot connect(Func&& func)
{
boost::shared_ptr<SlotImpl> slotImpl(
new SlotImpl(impl_, std::forward<Callback>(func)));
new SlotImpl(impl_, std::forward<Func>(func)));
add(slotImpl);
return slotImpl;
}

Slot connect(Callback&& func, const boost::shared_ptr<void>& tie)
template<typename Func>
Slot connect(Func&& func, const boost::shared_ptr<void>& tie)
{
boost::shared_ptr<SlotImpl> slotImpl(new SlotImpl(impl_, func, tie));
boost::shared_ptr<SlotImpl> slotImpl(new SlotImpl(impl_, std::forward<Func>(func), tie));
add(slotImpl);
return slotImpl;
}

void call(ARGS&&... args)
template<typename... Args>
void call(Args&&... args)
{
SignalImpl& impl(*impl_);
boost::shared_ptr<typename SignalImpl::SlotList> slots;
Expand All @@ -155,12 +158,12 @@ class Signal<RET(ARGS...)> : boost::noncopyable
guard = slotImpl->tie_.lock();
if (guard)
{
slotImpl->cb_(args...);
slotImpl->cb_(std::forward<Args>(args)...);
}
}
else
{
slotImpl->cb_(args...);
slotImpl->cb_(std::forward<Args>(args)...);
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions thread/SignalSlotTrivial.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <memory>
#include <vector>
#include <functional>

template<typename Signature>
class SignalTrivial;
Expand All @@ -13,19 +14,21 @@ class SignalTrivial<RET(ARGS...)>
public:
typedef std::function<void (ARGS...)> Functor;

void connect(Functor&& func)
template<typename Func>
void connect(Func&& func)
{
functors_.push_back(std::forward<Functor>(func));
functors_.push_back(std::forward<Func>(func));
}

void call(ARGS&&... args)
template<typename... Args>
void call(Args&&... args)
{
// gcc 4.6 supports
//for (const Functor& f: functors_)
typename std::vector<Functor>::iterator it = functors_.begin();
for (; it != functors_.end(); ++it)
{
(*it)(args...);
(*it)(std::forward<Args>(args)...);
}
}

Expand Down