1
0
mirror of https://github.com/wqking/eventpp.git synced 2024-12-25 23:30:49 +08:00

Added universal reference to args parameter in EventQueue::enqueue, see issue #56. Updated contributor list.

This commit is contained in:
wqking 2023-02-17 08:53:14 +08:00
parent 63497c60ef
commit 6f6ba44479
3 changed files with 46 additions and 3 deletions

View File

@ -155,7 +155,7 @@ public:
}
template <typename ...A>
auto enqueue(A ...args) -> typename std::enable_if<sizeof...(A) == sizeof...(Args), void>::type
auto enqueue(A && ...args) -> typename std::enable_if<sizeof...(A) == sizeof...(Args), void>::type
{
static_assert(super::ArgumentPassingMode::canIncludeEventType, "Enqueuing arguments count doesn't match required (Event type should be included).");
@ -172,7 +172,7 @@ public:
}
template <typename T, typename ...A>
auto enqueue(T && first, A ...args) -> typename std::enable_if<sizeof...(A) == sizeof...(Args), void>::type
auto enqueue(T && first, A && ...args) -> typename std::enable_if<sizeof...(A) == sizeof...(Args), void>::type
{
static_assert(super::ArgumentPassingMode::canExcludeEventType, "Enqueuing arguments count doesn't match required (Event type should NOT be included).");

View File

@ -308,10 +308,11 @@ Added CallbackList, EventDispatcher, EventQueue, CounterRemover, ConditionalRemo
<td align="center"><a href="https://github.com/MH2033/"><img alt="MH2033" src="https://github.com/MH2033.png?s=100" width="100px;" /></a><span>MH2033</span></td>
<td align="center"><a href="https://github.com/zhllxt/"><img alt="zhllxt" src="https://github.com/zhllxt.png?s=100" width="100px;" /></a><span>zhllxt</span></td>
<td align="center"><a href="https://github.com/marsCatXdu/"><img alt="marsCatXdu" src="https://github.com/marsCatXdu.png?s=100" width="100px;" /></a><span>marsCatXdu</span></td>
<td align="center"><a href="https://github.com/Chaojimengnan/"><img alt="Chaojimengnan" src="https://github.com/Chaojimengnan.png?s=100" width="100px;" /></a><span>Chaojimengnan</span></td>
</tr>
</table>
I (wqking) would like to sincerely thank all participants for the contributions. Your contributions makes `eventpp` better and bright future.
I (wqking) would like to sincerely thank all participants for the contributions. Your contributions make `eventpp` better and bright future.
I maintain the contributors list manually, according to the criteria below,
1. Your Pull Request is approved and merged to any branch.

View File

@ -344,6 +344,48 @@ TEST_CASE("EventQueue, non-copyable but movable unique_ptr")
}
}
TEST_CASE("EventQueue, copyable event object")
{
struct MyCopyable {
MyCopyable(int * counter, const int value) : counter(counter), value(value) {
}
MyCopyable(const MyCopyable & other) : counter(other.counter), value(other.value) {
++*counter;
}
MyCopyable(MyCopyable && other) : counter(other.counter), value(other.value) {
}
MyCopyable & operator = (const MyCopyable & other) {
counter = other.counter;
value = other.value;
++*counter;
return *this;
}
int * counter;
int value;
};
using EQ = eventpp::EventQueue<int, void (const MyCopyable &)>;
EQ queue;
// This is to ensure changing EventQueue::enqueue(A ...args) to EventQueue::enqueue(A && ...args) works properly
SECTION("For enqueue by r-value, there should be no copy/assignment") {
int copiedCount = 0;
queue.appendListener(3, [&copiedCount](const MyCopyable & object) {
REQUIRE(*object.counter == 0);
REQUIRE(copiedCount == 0);
REQUIRE(object.value == 5);
});
queue.enqueue(3, MyCopyable(&copiedCount, 5));
queue.process();
REQUIRE(copiedCount == 0);
}
}
TEST_CASE("EventQueue, peekEvent/takeEvent/dispatch")
{
using SP = std::shared_ptr<int>;