summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/IteratorTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ADT] Move drop_begin from iterator_range.h into STLExtras.Lang Hames2019-11-141-13/+0
| | | | | | | | | | | | | | | | | Summary: drop_begin depends on adl_begin/adl_end, which are defined in STLExtras.h, but we can't just #include STLExtras.h in iterator_range.h as that would introduce a circular reference (STLExtras.h already depends on iterator_range.h). The simplest solution is to move drop_begin into STLExtras.h, which is a reasonable home for it anyway. Reviewers: dblaikie Subscribers: dexonsmith, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70189
* [ADT] Remove llvm::make_unique utility.Jonas Devlieghere2019-08-161-1/+1
| | | | | | | | | | All uses of llvm::make_unique should have been replaced with std::make_unique. This patch represents the last part of the migration and removes the utility from LLVM. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 369130
* [llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-151-8/+8
| | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [ADT] Add zip_longest iterators.Michael Kruse2018-12-051-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Like the already existing zip_shortest/zip_first iterators, zip_longest iterates over multiple iterators at once, but has as many iterations as the longest sequence. This means some iterators may reach the end before others do. zip_longest uses llvm::Optional's None value to mark a past-the-end value. zip_longest is not reverse-iteratable because the tuples iterated over would be different for different length sequences (IMHO for the same reason neither zip_shortest nor zip_first should be reverse-iteratable; one can still reverse the ranges individually if that's the expected behavior). In contrast to zip_shortest/zip_first, zip_longest tuples contain rvalues instead of references. This is because llvm::Optional cannot contain reference types and the value-initialized default does not have a memory location a reference could point to. The motivation for these iterators is to use C++ foreach to compare two lists of ordered attributes in D48100 (SemaOverload.cpp and ASTReaderDecl.cpp). Idea by @hfinkel. This re-commits r348301 which was reverted by r348303. The compilation error by gcc 5.4 was resolved using make_tuple in the in the initializer_list. The compileration error by msvc14 was resolved by splitting ZipLongestValueType (which already was a workaround for msvc15) into ZipLongestItemType and ZipLongestTupleType. Differential Revision: https://reviews.llvm.org/D48348 llvm-svn: 348323
* Revert "[ADT] Add zip_longest iterators"Michael Kruse2018-12-041-30/+0
| | | | | | | | This reverts commit r348301. Compilation fails on buildbots with older versions of gcc and msvc. llvm-svn: 348303
* [ADT] Add zip_longest iteratorsMichael Kruse2018-12-041-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Like the already existing zip_shortest/zip_first iterators, zip_longest iterates over multiple iterators at once, but has as many iterations as the longest sequence. This means some iterators may reach the end before others do. zip_longest uses llvm::Optional's None value to mark a past-the-end value. zip_longest is not reverse-iteratable because the tuples iterated over would be different for different length sequences (IMHO for the same reason neither zip_shortest nor zip_first should be reverse-iteratable; one can still reverse the ranges individually if that's the expected behavior). In contrast to zip_shortest/zip_first, zip_longest tuples contain rvalues instead of references. This is because llvm::Optional cannot contain reference types and the value-initialized default does not have a memory location a reference could point to. The motivation for these iterators is to use C++ foreach to compare two lists of ordered attributes in D48100 (SemaOverload.cpp and ASTReaderDecl.cpp). Idea by @hfinkel. Differential Revision: https://reviews.llvm.org/D48348 llvm-svn: 348301
* Correctly instantiate `iterator_adaptor_base` when defining `pointer_iterator`David Blaikie2018-11-141-0/+29
| | | | | | | | | | | | | | | | The definition of `pointer_iterator` omits what should be a `iterator_traits::<>::iterator_category` parameter from `iterator_adaptor_base`. As a result, iterators based on `pointer_iterator` always have defaulted value types and the wrong iterator category. The definition of `pointee_iterator` just a few lines above does this correctly. This resolves [[ https://bugs.llvm.org/show_bug.cgi?id=39617 | bug 39617 ]]. Patch by Dylan MacKenzie! Reviewers: dblaikie Differential Revision: https://reviews.llvm.org/D54377 llvm-svn: 346833
* [ADT] drop_begin: use adl_begin/adl_end. NFC.Michael Kruse2018-06-271-0/+13
| | | | | | | | | | | | | | | | | | | Summary: The instantiation of the drop_begin function template usually fails because the functions begin() and end() do not exist. Only when using on a container from the std namespace (or `llvm::iterator_range`s of something derived from `std::iterator`), they are matched to std::begin() and std::end() due to Koenig-lookup. Explicitly use llvm::adl_begin and llvm::adl_end to make drop_begin applicable to anything iterable (including C-style arrays). A solution for general `llvm::iterator_range`s was already tried in r244620, but got reverted in r244621 due to MSVC not liking it. Reviewers: dblaikie, grosbach, aaron.ballman, ruiu Reviewed By: dblaikie, aaron.ballman Subscribers: aaron.ballman, llvm-commits Differential Revision: https://reviews.llvm.org/D48598 llvm-svn: 335772
* [ADT] Pass DerivedT from pointe{e,r}_iterator to iterator_adaptor_baseJustin Bogner2018-06-271-0/+14
| | | | | | | These were passing the wrong type into iterator_adaptor_base if T was anything but the default. llvm-svn: 335698
* [STLExtras] Add size() for ranges, and remove distance()Vedant Kumar2018-05-161-2/+2
| | | | | | | | | | r332057 introduced distance() for ranges. Based on post-commit feedback, this renames distance() to size(). The new size() is also only enabled when the operation is O(1). Differential Revision: https://reviews.llvm.org/D46976 llvm-svn: 332551
* [STLExtras] Add distance() for ranges, pred_size(), and succ_size()Vedant Kumar2018-05-101-0/+8
| | | | | | | | | | | This commit adds a wrapper for std::distance() which works with ranges. As it would be a common case to write `distance(predecessors(BB))`, this also introduces `pred_size()` and `succ_size()` helpers to make that easier to write. Differential Revision: https://reviews.llvm.org/D46668 llvm-svn: 332057
* [ADT] Make filter_iterator support bidirectional iterationVedant Kumar2018-04-251-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes it possible to reverse a filtered range. For example, here's a way to visit memory accesses in a BasicBlock in reverse order: auto MemInsts = reverse(make_filter_range(BB, [](Instruction &I) { return isa<StoreInst>(&I) || isa<LoadInst>(&I); })); for (auto &MI : MemInsts) ... To implement this functionality, I factored out forward iteration functionality into filter_iterator_base, and added a specialization of filter_iterator_impl which supports bidirectional iteration. Thanks to Tim Shen, Zachary Turner, and others for suggesting this design and providing feedback! This version of the patch supersedes the original (https://reviews.llvm.org/D45792). This was motivated by a problem we encountered in D45657: we'd like to visit the non-debug-info instructions in a BasicBlock in reverse order. Testing: check-llvm, check-clang Differential Revision: https://reviews.llvm.org/D45853 llvm-svn: 330875
* Re-sort #include lines for unittests. This uses a slightly modifiedChandler Carruth2017-06-061-1/+1
| | | | | | | | | | | | | | | clang-format (https://reviews.llvm.org/D33932) to keep primary headers at the top and handle new utility headers like 'gmock' consistently with other utility headers. No other change was made. I did no manual edits, all of this is clang-format. This should allow other changes to have more clear and focused diffs, and is especially motivated by moving some headers into more focused libraries. llvm-svn: 304786
* ADT: Add range helpers for pointer_ and pointee_iteratorJustin Bogner2017-03-271-0/+16
| | | | llvm-svn: 298841
* [ADT] Fix zip iterator interface.Bryant Wong2017-02-231-4/+53
| | | | | | | | | | | | This commit provides `zip_{first,shortest}` with the standard member types and methods expected of iterators (e.g., `difference_type`), in order for zip to be used with other adaptors, such as `make_filter_range`. Support for reverse iteration has also been added. Differential Revision: https://reviews.llvm.org/D30246 llvm-svn: 296036
* [ADT] Zip range adapterMehdi Amini2016-10-191-0/+63
| | | | | | | | | | | | | | | This augments the STLExtras toolset with a zip iterator and range adapter. Zip comes in two varieties: `zip`, which will zip to the shortest of the input ranges, and `zip_first`, which limits its `begin() == end()` checks to just the first range. Recommit r284035 after MSVC2013 support has been dropped. Patch by: Bryant Wong <github.com/bryant> Differential Revision: https://reviews.llvm.org/D23252 llvm-svn: 284623
* Revert "[ADT] Zip range adapter"Mehdi Amini2016-10-121-63/+0
| | | | | | This reverts commit r284035, which breaks with MSVC 2013. llvm-svn: 284037
* [ADT] Zip range adapterMehdi Amini2016-10-121-0/+63
| | | | | | | | | | | | | This augments the STLExtras toolset with a zip iterator and range adapter. Zip comes in two varieties: `zip`, which will zip to the shortest of the input ranges, and `zip_first`, which limits its `begin() == end()` checks to just the first krange. Patch by: Bryant Wong <github.com/bryant> Differential Revision: https://reviews.llvm.org/D23252 llvm-svn: 284035
* [ADT] Don't use make_pointee_iterator in IteratorTest.Justin Lebar2016-10-101-25/+20
| | | | llvm-svn: 283794
* [ADT] Add make_pointe{e,r}_iterator.Justin Lebar2016-10-101-20/+25
| | | | | | | | | | Reviewers: timshen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25418 llvm-svn: 283765
* Move unittests/Support/IteratorTest.cpp to unittests/ADT/Duncan P. N. Exon Smith2016-08-201-0/+212
This testing stuff from ADT, not Support. Fix the file location. llvm-svn: 279372
OpenPOWER on IntegriCloud