I'm trying to create a generic collection for events so that it'll be reusable for different kind of event-sets. While playing around with variadic templates, I came across THIS answer, which helped me for my example here:
#include <boost/test/unit_test.hpp>
#include <string>
#include <unordered_map>
namespace
{
struct Event3 {
static const int event_type = 3;
int a;
};
struct Event5 {
static const int event_type = 5;
double d;
};
struct Event7 {
static const int event_type = 7;
std::string s;
};
template <class ...K>
void gun(K...) {}
template <class... Ts>
class EventCollection
{
template <typename T>
void update_map(std::unordered_map<int, size_t> & map, const T &)
{
BOOST_CHECK(map.find(T::event_type) == map.end());
map[T::event_type] = sizeof(T);
}
public:
std::unordered_map<int, size_t> curr_map;
EventCollection(Ts... ts)
{
gun(update_map(curr_map, ts)...); // will expand for each input type
}
};
} // namespace
BOOST_AUTO_TEST_CASE( test_01 )
{
Event3 x{13};
Event5 y{17.0};
Event7 z{"23"};
EventCollection<Event3, Event5, Event7> hoshi(x, y, z);
BOOST_CHECK_EQUAL(hoshi.curr_map.size(), 3);
}
However, the line
gun(update_map(curr_map, ts)...); // will expand for each input type
gives me an 'error: invalid use of void expression'. Can anybody tell me, how to solve this?