Name: Anonymous 2012-06-03 13:58
that feel when your handwritten linked_list in C is 5 seconds faster than the STL
structs inherit the base list_node type. I use templates and lambda functions to generalize a few algorithms where the actual node type needs to be known.
struct log_sink_node : list_node
{
log_handler handler;
void* user_data;
unsigned int min_level;
unsigned int max_level;
char category[196];
};
list_foreach<log_sink_node>(&context->sinks_head, [&](log_sink_node* sink) {
if ( (sink->category[0] == '\0' || !strcmp(sink->category, record.category))
&& (sink->min_level <= record.level) && (record.level <= sink->max_level)
) {
sink->handler(&record, sink->user_data);
}
});
list_clear<log_sink_node>(&context->sinks_head, [](log_sink_node* sink) {
free(sink);
});