This is the mail archive of the
mailing list for the GDB project.
Re: [RFA 01/22] Change selttest.c to use use std::vector
- From: Tom Tromey <tom at tromey dot com>
- To: Trevor Saunders <tbsaunde at tbsaunde dot org>
- Cc: Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Tue, 27 Sep 2016 09:55:28 -0600
- Subject: Re: [RFA 01/22] Change selttest.c to use use std::vector
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com> <firstname.lastname@example.org> <20160927084049.naw5nx64smlzpqxg@ball>
>>>>> "Trevor" == Trevor Saunders <email@example.com> writes:
Trevor> I'd agree, hopefully we can throw VEC in the trash some day. Relatedly
Trevor> we should probably move gcc's hash table stuff to include/ sooner rather
Trevor> than later so we can similarly get rid of htab.
That would be nice; though we could probably use std::set and std::map
in gdb as well. One wrinkle with hash tables is that they're sometimes
allocated on obstacks; would gcc's handle this?
>> for (auto f : tests)
Trevor> its debatable, but imho its not necessarily obvious what the type of the
Trevor> local is when you use auto to iterate over vectors especially when they
Trevor> are members or globals like here.
Yeah, that's one drawback.
Often one actually wants "auto &f" in there.
>> +static std::vector<self_test_function *> tests;
Trevor> should we use a pointer to avoid the static initializer?
I was on the fence about this one.
On the one hand, static initializers can be very bad.
On the other hand, this one in particular doesn't seem like it could
>> - for (i = 0; VEC_iterate (self_test_function_ptr, tests, i, func); ++i)
>> + for (std::vector<self_test_function *>::iterator iter = tests.begin ();
>> + iter != tests.end ();
>> + ++iter)
Trevor> I believe you can "cheat" here and just use the function pointer type,
Trevor> because the sane implementation of iterators over vectors is pointers.
Yeah, or just loop using an int and index into the vector.
I'll see if that looks cleaner.