notify_observers() takes universal reference for C++11 and above

This commit is contained in:
John Wellbelove 2021-08-05 16:52:35 +01:00
parent c265e82bbe
commit d40a67776f

View File

@ -57,6 +57,7 @@ SOFTWARE.
#include "vector.h"
#include "exception.h"
#include "error_handler.h"
#include "utility.h"
namespace etl
{
@ -153,7 +154,7 @@ namespace etl
if (i_observer_item == observer_list.end())
{
// Is there enough room?
ETL_ASSERT(!observer_list.full(), ETL_ERROR(etl::observer_list_full));
ETL_ASSERT_AND_RETURN(!observer_list.full(), ETL_ERROR(etl::observer_list_full));
// Add it.
observer_list.push_back(observer_item(observer));
@ -231,6 +232,28 @@ namespace etl
return observer_list.size();
}
#if ETL_CPP11_SUPPORTED && !defined(ETL_OBSERVER_FORCE_CPP03)
//*****************************************************************
/// Notify all of the observers, sending them the notification.
///\tparam TNotification the notification type.
///\param n The notification.
//*****************************************************************
template <typename TNotification>
void notify_observers(TNotification&& n)
{
typename Observer_List::iterator i_observer_item = observer_list.begin();
while (i_observer_item != observer_list.end())
{
if (i_observer_item->enabled)
{
i_observer_item->p_observer->notification(etl::forward<TNotification>(n));
}
++i_observer_item;
}
}
#else
//*****************************************************************
/// Notify all of the observers, sending them the notification.
///\tparam TNotification the notification type.
@ -251,6 +274,7 @@ namespace etl
++i_observer_item;
}
}
#endif
protected: