Fixed move parameter in notify_observers

This commit is contained in:
John Wellbelove 2022-03-23 19:59:30 +00:00
parent 5577170fd2
commit fa7f6dc9d7
2 changed files with 38 additions and 57 deletions

View File

@ -232,31 +232,9 @@ namespace etl
return observer_list.size();
}
#if ETL_USING_CPP11 && !defined(ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION)
//*****************************************************************
/// 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.
///\tparam TNotification The notification type.
///\param n The notification.
//*****************************************************************
template <typename TNotification>
@ -274,7 +252,6 @@ namespace etl
++i_observer_item;
}
}
#endif
protected:

View File

@ -30,43 +30,46 @@ SOFTWARE.
#include "etl/observer.h"
//*****************************************************************************
// Notification1
//*****************************************************************************
struct Notification1
namespace
{
};
//*****************************************************************************
// Notification1
//*****************************************************************************
struct Notification1
{
};
//*****************************************************************************
// Notification2
//*****************************************************************************
struct Notification2
{
};
//*****************************************************************************
// Notification2
//*****************************************************************************
struct Notification2
{
};
//*****************************************************************************
// Notification3
//*****************************************************************************
struct Notification3
{
};
//*****************************************************************************
// Notification3
//*****************************************************************************
struct Notification3
{
};
//*****************************************************************************
// Generic notification.
//*****************************************************************************
template <const int ID>
struct Notification
{
};
//*****************************************************************************
// Generic notification.
//*****************************************************************************
template <const int ID>
struct Notification
{
};
//*****************************************************************************
// The observer base type.
// Declare what notifications you want to observe and how they are passed to 'notification'.
// The Notification1 is passed by value.
// The Notification2 is passed by reference.
// The Notification3 is passed by const reference.
//*****************************************************************************
typedef etl::observer<Notification1, Notification2&, const Notification3&> ObserverType;
//*****************************************************************************
// The observer base type.
// Declare what notifications you want to observe and how they are passed to 'notification'.
// The Notification1 is passed by value.
// The Notification2 is passed by reference.
// The Notification3 is passed by const reference.
//*****************************************************************************
typedef etl::observer<Notification1, Notification2&, const Notification3&> ObserverType;
}
//*****************************************************************************
// The concrete observable 1 class.
@ -77,13 +80,14 @@ public:
Notification1 data1;
Notification2 data2;
Notification1& data3 = data1;
//*********************************
// Notify all of the observers.
//*********************************
void send_notifications()
{
notify_observers(data1);
notify_observers(data3);
notify_observers(data2);
}
};