Hi,
I have a class (A) which contains 'Listeners' or 'Observers' which need to be informed when certain things happen in class A. This currently involves iterating over all listeners and calling a certain notification method for example:
for(Listener listener : listeners)
{
listener->InformOfSomething(1, 2, 3, 4);
}
I was wondering if there is any convenient way in c++11 to reduce this to a one-liner without having to create additional functions or use lambdas (or even remove the brackets ;)
The approach I'm looking for would be something similar to jQuery where functions act on collections of objects as opposed to single items. For e.g. maybe something as simple as this:
$(listeners).InformOfSomething(1, 2, 3, 4);
(please forgive the shameless copy of jQuery syntax)
Where the $ syntax acts in a similar way to range-based for loops and requires begin() and end() functions on the 'listeners' param which then iterates the collection and substitutes the item in the collection with first parameter of the proceeding function (or more specifically the 'this' pointer when using a class member function).
Anything like this in c++11 or any better way to do it?
Thanks.