Problem: Chuck language definition uses cap(), when it should use
size().
An example from the Chuck language specficiation:
http://chuck.cs.princeton.edu/doc/language/array.html
// print it
for( 0 => int i; i
< bar.cap(); i++
)
<<< bar[0] >>>;
}
From
chuck_lang.cpp
// array.cap()
CK_DLL_MFUN( array_capacity
)
{
Chuck_Array * array = (Chuck_Array
*)SELF;
RETURN->v_int =
array->capacity();
}
From STL
docs:
std::vector<xx>::capacity()
The
member function returns the storage currently allocated to hold
the
controlled sequence, a value at least as large as size
One of
these is wrong (probably not the STL docs. ;--) ). Either bar.size(),
or
array->size() would do it.
std::vector<>::capacity() is not the
same thing as std::vector<>::size().
It's common practice (if not a
standards requirement) for STL
implementations to grow arrays by doubling
capacity() as the size()
increases, instead of growing capactity() by one
each time, becuase this
provides O(1) performance for push_back instead of
O(2) performance.