LCOV - code coverage report
Current view: top level - src - reverse_iterator.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 7 7 100.0 %
Date: 2020-09-26 01:30:44 Functions: 35 35 100.0 %

          Line data    Source code
       1             : // Taken from https://gist.github.com/arvidsson/7231973
       2             : 
       3             : #ifndef BITCOIN_REVERSE_ITERATOR_H
       4             : #define BITCOIN_REVERSE_ITERATOR_H
       5             : 
       6             : /**
       7             :  * Template used for reverse iteration in C++11 range-based for loops.
       8             :  *
       9             :  *   std::vector<int> v = {1, 2, 3, 4, 5};
      10             :  *   for (auto x : reverse_iterate(v))
      11             :  *       std::cout << x << " ";
      12             :  */
      13             : 
      14             : template <typename T>
      15             : class reverse_range
      16             : {
      17             :     T &m_x;
      18             : 
      19             : public:
      20     1403232 :     explicit reverse_range(T &x) : m_x(x) {}
      21             : 
      22      701616 :     auto begin() const -> decltype(this->m_x.rbegin())
      23             :     {
      24      701616 :         return m_x.rbegin();
      25             :     }
      26             : 
      27      701616 :     auto end() const -> decltype(this->m_x.rend())
      28             :     {
      29      701616 :         return m_x.rend();
      30             :     }
      31             : };
      32             : 
      33             : template <typename T>
      34      701616 : reverse_range<T> reverse_iterate(T &x)
      35             : {
      36      701616 :     return reverse_range<T>(x);
      37             : }
      38             : 
      39             : #endif // BITCOIN_REVERSE_ITERATOR_H

Generated by: LCOV version 1.15