New answers tagged

1

Code Changes Following the advice given, I have made the following changes. Base Subscriber Template The base callback method has been change to a pure virtual function. virtual void OnEventReceived(const EventType&) = 0; Container Template All the protected methods had the underscore prefix removed from the template function name. void attach(...


2

Answers to your questions Should the default implementation of the event callback function stay or should be a pure virtual? There is no point in using the base class itself, so it's better to make it pure virtual. This way, bugs in the code where a base class is instantiated by accident are then caught by the compiler. Should attach and detach ...


5

In the sort() function its currently hardcoded to merge sort which I assume is not intentional. However, if you do allow the user to give an input you should do some error checking. You'll currently get unexpected behaviour if the user enters anything other than 1 or 2. You should use std::swap rather than implementing your own swap function. Some types can ...


-2

READABILITY Function: int count(T* array) I don't prefer this way of acessing a (T) while(*(array+i)), because of readability reasons. Better way: while(array[i]) PERFORMANCE Function: void swap(T& t1, T& t2) Faster way is to use XOR (^) swap algorithm. it is faster and small amout of memory is used. if (t1 != t2) { *t1 ^= *t2; *t2 ^= ...


3

zip Right now, your zip uses the tuple protocol. It probably makes more sense to use the range protocol instead, to support cases like this: std::vector a{1, 2, 3, 4}; std::vector b{5, 6, 7, 8}; for (auto [x, y] : zip(a, b)) { std::cout << x << ' ' << y << '\n'; } These constructors: zip(T& t, Ts&... ts) : zip<Ts......


2

Arguments of scalar types are better passed by value. It makes sense for iterator types to befriend the range class itself and hide their constructors private. As a rule, it is undefined to compare iterators into different containers. Consequently, you can reduce your iterators comparison to but a single relational iterator (add a debug-time diagnostic for ...


1

Not that it is important, but pop and push both use unbounded loops to wait for other operations to finish. So strictly speaking your queue implementation is not lock-free. This can be a performance problem in case of oversubscription (i.e., when you use more threads than you have cores). However, with regards to performance improvements you should first ...


2

The following are only a few quick notes on the C++ language usage from a first reading. I didn't have enough time to fully get through the whole code (might revisit later) and make suggestions on the overall design. I hope this is still considered an ok answer: TTL_INLINE is pointless. It is used only on declarations of member functions which are defined ...


Top 50 recent answers are included