C++ class template for notification management Recently, I found myself frequently writing notification managing facilities. That is, one can register as a receiver by providing a callback, and another can send a notification to all registrants by invoking their corresponding callbacks. I had been bothered by re-writing this similar code again and again. Finally, I decided to write a generic one once and for all. Following is the version for cases where the maximum number of registrants is known and limited. So I don't bother using advanced data structures for managing the registered callbacks. Comments pertaining to any aspect of the code are welcome :)

#include &lt;array&gt;
#include &lt;functional&gt;
#include &lt;mutex&gt;
#include &lt;stdexcept&gt;
#include &lt;utility&gt;

template &lt;typename Sig, int max_reg = 16, typename Func = std::function&lt;Sig&gt;&gt;
class NotifyRegistry;

template &lt;int max_reg, typename Func, typename R, typename... Args&gt;
class NotifyRegistry&lt;R(Args...), max_reg, Func&gt;
{
  static_assert(max_reg &gt; 0, "");
public:
  template &lt;typename F&gt; 
  int Register(F&amp;&amp; f) {
    std::lock_guard&lt;std::mutex&gt; lock(mut_);
    int i = -1;
    while (++i &lt; max_reg &amp;&amp; reg_[i]);
    if (i == max_reg) throw std::length_error("");
    reg_[i] = std::forward&lt;F&gt;(f);
    return i;
  }
  void Unregister(int id) {
    if (id &lt; 0 || id &gt;= max_reg) throw std::invalid_argument("");
    std::lock_guard&lt;std::mutex&gt; lock(mut_);
    reg_[id] = nullptr;
  }
  void Notify(Args... args) const {
    std::lock_guard&lt;std::mutex&gt; lock(mut_);
    for (auto&amp; f : reg_) {
      if (f) (void)f(std::forward&lt;Args&gt;(args)...);
    }
  }
private:
  std::array&lt;Func, max_reg&gt; reg_;
  mutable std::mutex mut_;
};
Your class seems generally well done and easy to use.  I have only a few suggested improvements.

Add text to throws

It would be useful to have something other than a null string when the object throws an error.  

Add text to the static_assert

The same issue exists for the static_assert in that it would be useful to provide a meaningful error message instead of an empty string.

Provide some comments

Because the class is compact and generally well written, not much explanation is required, but a brief explanation, especially noting which exceptions might be thrown, would be useful.