LCOV - code coverage report
Current view: top level - src - reverse_iterator.h (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 7 7 100.0 %
Date: 2023-09-26 12:08:55 Functions: 8 24 33.3 %

          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 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        5460 :     explicit reverse_range(T &x) : m_x(x) {}
      21             : 
      22        5460 :     auto begin() const -> decltype(this->m_x.rbegin())
      23             :     {
      24        5460 :         return m_x.rbegin();
      25             :     }
      26             : 
      27        5460 :     auto end() const -> decltype(this->m_x.rend())
      28             :     {
      29        5460 :         return m_x.rend();
      30             :     }
      31             : };
      32             : 
      33             : template <typename T>
      34        5460 : reverse_range<T> reverse_iterate(T &x)
      35             : {
      36        5460 :     return reverse_range<T>(x);
      37             : }
      38             : 
      39             : #endif // BITCOIN_REVERSE_ITERATOR_H

Generated by: LCOV version 1.14