cppx-core
Count_iterator_.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
4 
5 #include <iterator> // std::iterator_traits
6 
7 namespace cppx
8 {
9  template< class Item >
11  {
12  Size m_count = 0;
13 
14  struct Proxy
15  {
16  operator Item () const { return {}; }
17  void operator=( const Item& ) {}
18  };
19 
20  public:
21  auto count() const noexcept
22  -> Size
23  { return m_count; }
24 
25  // Optimization, to be manually invoked.
26  void operator+=( const int n ) noexcept
27  { m_count += n; }
28 
29  auto operator*() const noexcept
30  -> Proxy
31  { return {}; }
32 
33  auto operator++() noexcept
34  -> Count_iterator_&
35  {
36  ++m_count;
37  return *this;
38  }
39  };
40 } // namespace cppx
41 
42 namespace std
43 {
44  template< class Item >
45  struct iterator_traits< cppx::Count_iterator_< Item > >:
46  iterator_traits<Item*>
47  {};
48 } // namespace std
void operator+=(const int n) noexcept
auto operator++() noexcept -> Count_iterator_ &
auto operator *() const noexcept -> Proxy
Signed_< size_t > Size
A Signed_ equivalent of size_t.
auto count() const noexcept -> Size
Signed Size and Index, plus unsigned equivalents Unsigned_size and Unsigned_index.