Adrian
Adrian

Reputation: 20068

How to check when a std::vector changes state from empty to non-empty and the other way around?

I want to generate an event when the vector changes state from empty to non-empty or from non-empty to empty.

What is the easiest way to check this ?

Upvotes: 0

Views: 115

Answers (1)

Yakk - Adam Nevraumont
Yakk - Adam Nevraumont

Reputation: 275730

Create a class that wraps a vector. In insert remove operations, add checks for your transition.

Write or find an event framework. Fire said events when you want them to occur. Subscribe where you want to recieve.

vector is a light weight class that solves the problem of a dynamic, resizable array of contiguous elements well. It does not contain event hooks: std does not make you pay for things you do not use (and most use cases do not require event hooks).

Upvotes: 5

Related Questions