aboutsummaryrefslogtreecommitdiff
path: root/gcc/iterator-utils.h
AgeCommit message (Collapse)AuthorFilesLines
2021-09-13Merged current trunk to branch.Thomas Koenig1-1/+1
2020-12-17Add more iterator utilitiesRichard Sandiford1-0/+159
This patch adds some more iterator helper classes. They really fall into two groups, but there didn't seem much value in separating them: - A later patch has a class hierarchy of the form: Base +- Derived1 +- Derived2 A class wants to store an array A1 of Derived1 pointers and an array A2 of Derived2 pointers. However, for compactness reasons, it was convenient to have a single array of Base pointers, with A1 and A2 being slices of this array. This reduces the overhead from two pointers and two ints (3 LP64 words) to one pointer and two ints (2 LP64 words). But consumers of the class shouldn't be aware of this: they should see A1 as containing Derived1 pointers rather than Base pointers and A2 as containing Derived2 pointers rather than Base pointers. This patch adds derived_iterator and const_derived_container classes to support this use case. - A later patch also adds various linked lists. This patch adds wrapper_iterator and list_iterator classes to make it easier to create iterators for these linked lists. For example: // Iterators for lists of definitions. using def_iterator = list_iterator<def_info, &def_info::next_def>; using reverse_def_iterator = list_iterator<def_info, &def_info::prev_def>; This in turn makes it possible to use range-based for loops on the lists. The patch just adds the things that the later patches need; it doesn't try to make the classes as functionally complete as possible. I think we should add extra functionality when needed rather than ahead of time. gcc/ * iterator-utils.h (derived_iterator): New class. (const_derived_container, wrapper_iterator): Likewise. (list_iterator): Likewise.
2020-12-13Move iterator_range to a new iterator-utils.h fileRichard Sandiford1-0/+44
A later patch will add more iterator-related utilities. Rather than putting them all directly in coretypes.h, it seemed better to add a new header file, here called "iterator-utils.h". This preliminary patch moves the existing iterator_range class there too. I used the same copyright date range as coretypes.h “just to be sure”. gcc/ * coretypes.h (iterator_range): Move to... * iterator-utils.h: ...this new file.