1
0
mirror of https://github.com/wqking/eventpp.git synced 2024-12-25 07:19:41 +08:00

Fix compile error when using Heter classes with CounterRemover, #68

This commit is contained in:
wqking 2023-12-17 14:19:34 +08:00
parent 39daab7963
commit 60761df5e3
3 changed files with 21 additions and 7 deletions

View File

@ -15,6 +15,7 @@
#define COUNTERREMOVER_H_211532679833
#include "../eventpolicies.h"
#include "../internal/typeutil_i.h"
namespace eventpp {
@ -41,7 +42,8 @@ private:
};
template <typename ...Args>
void operator() (Args && ...args) const {
auto operator() (Args && ...args) const
-> typename std::enable_if<internal_::CanInvoke<Callback, Args ...>::value, void>::type {
if(--data->triggerCount <= 0) {
data->dispatcher.removeListener(data->event, data->handle);
}
@ -123,7 +125,8 @@ private:
};
template <typename ...Args>
void operator() (Args && ...args) const {
auto operator() (Args && ...args) const
-> typename std::enable_if<internal_::CanInvoke<Callback, Args ...>::value, void>::type {
if(--data->triggerCount <= 0) {
data->callbackList.remove(data->handle);
}

View File

@ -320,6 +320,7 @@ Added CallbackList, EventDispatcher, EventQueue, CounterRemover, ConditionalRemo
<td align="center"><a href="https://github.com/henaiguo/"><img alt="henaiguo" src="https://github.com/henaiguo.png?s=100" width="100px;" /></a><span>henaiguo</span></td>
<td align="center"><a href="https://github.com/sr-tream/"><img alt="sr-tream" src="https://github.com/sr-tream.png?s=100" width="100px;" /></a><span>sr-tream</span></td>
<td align="center"><a href="https://github.com/Drise13/"><img alt="Drise13" src="https://github.com/Drise13.png?s=100" width="100px;" /></a><span>Drise13</span></td>
<td align="center"><a href="https://github.com/iamzone/"><img alt="iamzone" src="https://github.com/iamzone.png?s=100" width="100px;" /></a><span>iamzone</span></td>
</tr>
</table>

View File

@ -162,7 +162,7 @@ TEST_CASE("CounterRemover, CallbackList, has parameters")
TEST_CASE("CounterRemover, HeterEventDispatcher")
{
eventpp::HeterEventDispatcher<int, eventpp::HeterTuple<void ()> > dispatcher;
eventpp::HeterEventDispatcher<int, eventpp::HeterTuple<void (), void (int)> > dispatcher;
constexpr int event = 3;
std::vector<int> dataList(4);
@ -174,7 +174,7 @@ TEST_CASE("CounterRemover, HeterEventDispatcher")
eventpp::counterRemover(dispatcher).prependListener(event, [&dataList]() {
++dataList[1];
});
auto handle = eventpp::counterRemover(dispatcher).appendListener(event, [&dataList]() {
auto handle = eventpp::counterRemover(dispatcher).appendListener(event, [&dataList](int) {
++dataList[2];
}, 2);
eventpp::counterRemover(dispatcher).insertListener(event, [&dataList]() {
@ -183,22 +183,27 @@ TEST_CASE("CounterRemover, HeterEventDispatcher")
REQUIRE(dataList == std::vector<int> { 0, 0, 0, 0 });
dispatcher.dispatch(event);
dispatcher.dispatch(event); // for void()
REQUIRE(dataList == std::vector<int> { 1, 1, 0, 1 });
dispatcher.dispatch(event, 5); // for void(int)
REQUIRE(dataList == std::vector<int> { 1, 1, 1, 1 });
dispatcher.dispatch(event);
dispatcher.dispatch(event, 5);
REQUIRE(dataList == std::vector<int> { 2, 1, 2, 2 });
dispatcher.dispatch(event);
dispatcher.dispatch(event, 5);
REQUIRE(dataList == std::vector<int> { 3, 1, 2, 3 });
dispatcher.dispatch(event);
dispatcher.dispatch(event, 5);
REQUIRE(dataList == std::vector<int> { 4, 1, 2, 3 });
}
TEST_CASE("CounterRemover, HeterCallbackList")
{
eventpp::HeterCallbackList<eventpp::HeterTuple<void ()> > callbackList;
eventpp::HeterCallbackList<eventpp::HeterTuple<void (), void (int)> > callbackList;
std::vector<int> dataList(4);
@ -209,7 +214,7 @@ TEST_CASE("CounterRemover, HeterCallbackList")
eventpp::counterRemover(callbackList).prepend([&dataList]() {
++dataList[1];
});
auto handle = eventpp::counterRemover(callbackList).append([&dataList]() {
auto handle = eventpp::counterRemover(callbackList).append([&dataList](int) {
++dataList[2];
}, 2);
eventpp::counterRemover(callbackList).insert([&dataList]() {
@ -219,15 +224,20 @@ TEST_CASE("CounterRemover, HeterCallbackList")
REQUIRE(dataList == std::vector<int> { 0, 0, 0, 0 });
callbackList();
REQUIRE(dataList == std::vector<int> { 1, 1, 0, 1 });
callbackList(5);
REQUIRE(dataList == std::vector<int> { 1, 1, 1, 1 });
callbackList();
callbackList(5);
REQUIRE(dataList == std::vector<int> { 2, 1, 2, 2 });
callbackList();
callbackList(5);
REQUIRE(dataList == std::vector<int> { 3, 1, 2, 3 });
callbackList();
callbackList(5);
REQUIRE(dataList == std::vector<int> { 4, 1, 2, 3 });
}