On Mon, Nov 26, 2012 at 9:57 PM, Lawrence Crowl <cr...@googlers.com> wrote: > 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.
If you view them in isolation, yes. But you can trivially provide the interface of (2) by wrapping over (3). So I'd prefer the implementation to be (3) but (2) be still provided by means of wrapping it (I'd really like to see less C / C++ spaghetti mix in the various passes, not that I like the C++ iterator idiom very much anyway). Btw, my pending loop iterator change attached (no longer applies after the VEC changes). Richard. > -- > Lawrence Crowl
loop-iterator-cxx
Description: Binary data