LCOV - code coverage report
Current view: top level - src/base - iterator.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2017-04-26 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2014 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_BASE_ITERATOR_H_
       6             : #define V8_BASE_ITERATOR_H_
       7             : 
       8             : #include <iterator>
       9             : 
      10             : namespace v8 {
      11             : namespace base {
      12             : 
      13             : // The intention of the base::iterator_range class is to encapsulate two
      14             : // iterators so that the range defined by the iterators can be used like
      15             : // a regular STL container (actually only a subset of the full container
      16             : // functionality is available usually).
      17             : template <typename ForwardIterator>
      18             : class iterator_range {
      19             :  public:
      20             :   typedef ForwardIterator iterator;
      21             :   typedef ForwardIterator const_iterator;
      22             :   typedef typename std::iterator_traits<iterator>::pointer pointer;
      23             :   typedef typename std::iterator_traits<iterator>::reference reference;
      24             :   typedef typename std::iterator_traits<iterator>::value_type value_type;
      25             :   typedef
      26             :       typename std::iterator_traits<iterator>::difference_type difference_type;
      27             : 
      28             :   iterator_range() : begin_(), end_() {}
      29             :   template <typename ForwardIterator1, typename ForwardIterator2>
      30             :   iterator_range(ForwardIterator1&& begin, ForwardIterator2&& end)
      31             :       : begin_(std::forward<ForwardIterator1>(begin)),
      32         106 :         end_(std::forward<ForwardIterator2>(end)) {}
      33             : 
      34         106 :   iterator begin() { return begin_; }
      35         106 :   iterator end() { return end_; }
      36             :   const_iterator begin() const { return begin_; }
      37             :   const_iterator end() const { return end_; }
      38             :   const_iterator cbegin() const { return begin_; }
      39             :   const_iterator cend() const { return end_; }
      40             : 
      41             :   bool empty() const { return cbegin() == cend(); }
      42             : 
      43             :   // Random Access iterators only.
      44             :   reference operator[](difference_type n) { return begin()[n]; }
      45             :   difference_type size() const { return cend() - cbegin(); }
      46             : 
      47             :  private:
      48             :   const_iterator const begin_;
      49             :   const_iterator const end_;
      50             : };
      51             : 
      52             : }  // namespace base
      53             : }  // namespace v8
      54             : 
      55             : #endif  // V8_BASE_ITERATOR_H_

Generated by: LCOV version 1.10