Delegating constructors is cool.
TL;DR With C++11 you can kiss goodbye to some 'init' method function shared between constructors or copying and pasting between your constructors.
Like inherited constructors I like delegating constructors[1] too - it's intuitive and clear:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
class worker { | |
public: | |
enum states {WAITING, RUNNABLE, STEALING, TERMINATED}; | |
// default runnable start state is C++11 delegated to the general purpose constructor | |
worker(std::vector<T>& queues): worker(queues, RUNNABLE) {} | |
worker(std::vector<T>& queues, states state): this_id(count++), state(state), queues(queues) { | |
//do shared intialization stuff | |
} | |
. | |
. | |
. |
References:
No comments:
Post a Comment