LCOV - code coverage report
Current view: top level - include/llvm/ADT - iterator_range.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 12 12 100.0 %
Date: 2017-09-14 15:23:50 Functions: 64 71 90.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- iterator_range.h - A range adaptor for iterators ---------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : /// \file
      10             : /// This provides a very simple, boring adaptor for a begin and end iterator
      11             : /// into a range type. This should be used to build range views that work well
      12             : /// with range based for loops and range based constructors.
      13             : ///
      14             : /// Note that code here follows more standards-based coding conventions as it
      15             : /// is mirroring proposed interfaces for standardization.
      16             : ///
      17             : //===----------------------------------------------------------------------===//
      18             : 
      19             : #ifndef LLVM_ADT_ITERATOR_RANGE_H
      20             : #define LLVM_ADT_ITERATOR_RANGE_H
      21             : 
      22             : #include <iterator>
      23             : #include <utility>
      24             : 
      25             : namespace llvm {
      26             : 
      27             : /// \brief A range adaptor for a pair of iterators.
      28             : ///
      29             : /// This just wraps two iterators into a range-compatible interface. Nothing
      30             : /// fancy at all.
      31             : template <typename IteratorT>
      32     6847804 : class iterator_range {
      33             :   IteratorT begin_iterator, end_iterator;
      34             : 
      35             : public:
      36             :   //TODO: Add SFINAE to test that the Container's iterators match the range's
      37             :   //      iterators.
      38             :   template <typename Container>
      39      279186 :   iterator_range(Container &&c)
      40             :   //TODO: Consider ADL/non-member begin/end calls.
      41      346627 :       : begin_iterator(c.begin()), end_iterator(c.end()) {}
      42   861380327 :   iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
      43   884441361 :       : begin_iterator(std::move(begin_iterator)),
      44   916797536 :         end_iterator(std::move(end_iterator)) {}
      45             : 
      46   146012066 :   IteratorT begin() const { return begin_iterator; }
      47   144931009 :   IteratorT end() const { return end_iterator; }
      48             : };
      49             : 
      50             : /// \brief Convenience function for iterating over sub-ranges.
      51             : ///
      52             : /// This provides a bit of syntactic sugar to make using sub-ranges
      53             : /// in for loops a bit easier. Analogous to std::make_pair().
      54     4704306 : template <class T> iterator_range<T> make_range(T x, T y) {
      55  1276010977 :   return iterator_range<T>(std::move(x), std::move(y));
      56             : }
      57             : 
      58             : template <typename T> iterator_range<T> make_range(std::pair<T, T> p) {
      59    11168018 :   return iterator_range<T>(std::move(p.first), std::move(p.second));
      60             : }
      61             : 
      62             : template<typename T>
      63             : iterator_range<decltype(begin(std::declval<T>()))> drop_begin(T &&t, int n) {
      64      154352 :   return make_range(std::next(begin(t), n), end(t));
      65             : }
      66             : }
      67             : 
      68             : #endif

Generated by: LCOV version 1.13