A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove

debug_count

A utility class designed for debugging purposes. This is used in the ETL containers to check that all placement new'd
items have been destructed. When neither DEBUG or _DEBUG is defined then this class does nothing and will be
optimised away.

If the count is decremented below zero then an assert will be generated.
If the destructor for this class is called and the count is not zero then an assert will be generated.

Supports operators ++, --, +=, -=

class MyContainer
{
public:

  void push(value_type value)
  {
    value_type* p = pool.allocate<value_type>();
    new (p) value_type(value);
    ++instance_count;
    // Store in the buffer.  
  }

  void pop()
  {
    // Get the pointer to the item to pop.
    p->~value_type();
    pool.release(p);
    --instance_count;
  }

private:
  etl::debug_count instance_count;
};
debug_count.h