mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 08:26:04 +08:00
notify_observers() takes universal reference for C++11 and above
This commit is contained in:
parent
a7786e08af
commit
ecff863087
@ -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:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user