On 11/23/12, Andrew MacLeod <amacl...@redhat.com> wrote: > On 11/22/2012 01:18 PM, Lawrence Crowl wrote: > > I have found that tree-flow.h implements iteration over htab_t, > > while there is no current facility to do that with hash_table. > > Unfortunately, the specific form does not match the standard C++ > > approach to iterators. We have several choices. > > > > (1) Ignore the problem and leave all such tables as htab_t. > > > > (2) Write new hash_table iteration functions to match the form of > > the existing GCC macro/function approach. > > > > (3) Write new hash_table iteration functions to match the form used > > by the C++ standard. This approach would entail modifying the loops. > > > > Diego and I have a preference for (3). What do you prefer? > > I don't like (1) for sure. > > Before deciding a preference between (2) and (3), what are the > actual differences? ie, is (2) doing something practical that > (3) has to bend over for, or is (3)'s format better but wasn't > practical before? is (2) otherwise useful going forward?
For iterating over a hash table containing elements of type T, (2) The for statement is parameterized by an iterator variable and a variable of type T. The loop copies the element into the T variable, and that variable is used in the body. (3) The for statement is parameterized only by an iterator variable. The loop uses "*iterator_variable" to obtain a reference to the element. With (3), we have well-established practice for writing generic algorithms. With (2), we seem to have just for loops. -- Lawrence Crowl