New answers tagged callback
0
I think it's quite OK like that. Of course that depends on the use case and your goal.
One thing I would definitely change though is to return only a std::weak_ptr from addListener.
Here a few alternative approaches:
replace the std::vector with
a std::set or std::unordered_set and keep the std::weak_ptr as the "ID", or
a std::list and use the ...
3
I think this makes sense in terms of STL use. Storing a std::shared_ptr<std::function> is not usually necessary since std::function may own heap allocations internally, but since you return the shared_ptr from addListener it could be passed around. If you never use the returned shared_ptr, you could just store a std::vector<std::function> and ...
Top 50 recent answers are included
Related Tags
callback × 169javascript × 72
c++ × 35
node.js × 24
java × 17
asynchronous × 16
c# × 15
event-handling × 15
jquery × 12
c++11 × 10
multithreading × 9
python × 8
object-oriented × 8
ajax × 8
c × 7
error-handling × 7
beginner × 6
android × 6
c++17 × 6
promise × 6
php × 5
thread-safety × 5
timer × 5
performance × 4
json × 4