Stack<T>.sized constructor

Stack<T>.sized(
  1. int sizeMax
)

Constructor in which you can specify maximum number of entries. This maximum is a limit that is enforced as entries are pushed on to the stack to prevent stack growth beyond a maximum size. There is no pre-allocation of slots for entries at any time in this library.

Implementation

Stack.sized(int sizeMax) {
  if(sizeMax < 2) {
    throw IllegalOperationException(
      'Error: stack size must be 2 entries or more '
    );
  }
  else {
    _sizeMax = sizeMax;
  }
}