<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1476" name=GENERATOR>
<STYLE></STYLE>
</HEAD><FONT face=Arial><FONT size=2>
<BODY>
<DIV>Problem: Chuck language definition uses cap(), when it should use
size().</DIV>
<DIV> </DIV>
<DIV>An example from the Chuck language specficiation:<BR><BR><A
href="http://chuck.cs.princeton.edu/doc/language/array.html">http://chuck.cs.princeton.edu/doc/language/array.html</A><BR><BR>
// print it<BR> for( 0 => int i; i
< bar.cap(); i++
)<BR>
<<< bar[0] >>>;<BR> }<BR><BR>From
chuck_lang.cpp<BR>// array.cap()<BR>CK_DLL_MFUN( array_capacity
)<BR>{<BR> Chuck_Array * array = (Chuck_Array
*)SELF;<BR> RETURN->v_int =
array->capacity();<BR>}<BR><BR>From STL
docs:<BR><BR>std::vector<xx>::capacity()<BR> The
member function returns the storage currently allocated to hold
the<BR>controlled sequence, a value at least as large as size<BR><BR>One of
these is wrong (probably not the STL docs. ;--) ). Either bar.size(),<BR>or
array->size() would do it.<BR><BR>std::vector<>::capacity() is not the
same thing as std::vector<>::size().<BR>It's common practice (if not a
standards requirement) for STL<BR>implementations to grow arrays by doubling
capacity() as the size()<BR>increases, instead of growing capactity() by one
each time, becuase this<BR>provides O(1) performance for push_back instead of
O(2) performance.<BR></DIV>
<DIV><BR>Which brings me to my next feature request.... <grin><BR><BR>I
don't suppose the Array push_back/pop-back/&c methods could
be<BR>re-instituted? It's nice to have dynamic arrays; but, in the
current<BR>implementation, there's no way to grow the integer-indexed portion
of<BR>arrays.<BR><BR>A use case:<BR><BR>I'm writing VoiceManager, a
voice-manager class, that implements polyphonic<BR>playing on classes that
implement IInstrument. One of the parameters to<BR>VoiceManager is how many
instances of the instrument to create. The problem:<BR>how to declar an array to
hold the instruments?<BR><BR> IInstrument
instruments[];<BR>Doesn't create an array.<BR> [] @=>
IInstrument instruments[];<BR>is gramattically illegal.<BR>
IInstrument instruments[0];<BR>isn't growable.<BR> <BR>The
ideal solution:<BR> IInstrument
instruments[];<BR>....<BR>
instruments.push_back(instr);<BR><BR>Tantalizing, because array_push_back is
present in the sources, but doesn't<BR>seem to be implemented in the
language.<BR><BR>Priority of the feature request: nice to have, but not
absolutely required.<BR>static members would be my first choice. I used
IInstrument<BR>instruments[256]; to work around the problem.<BR><BR>Best
Regards,<BR><BR>Robin Davies.<BR></DIV></BODY></HTML></FONT></FONT>