cppx-core
Forward_iterator_impl_.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 #include <cppx-core/language/syntax/macro-use.hpp> // CPPX_USE_STD
4 #include <cppx-core/language/types/signed-size-types.hpp> // cppx::(Size)
5 #include <cppx-core/language/types/Truth.hpp> // cppx::Truth
6 
7 #include <c/stddef.hpp> // ptrdiff_t
8 #include <iterator> // std::(begin, end, forward_iterator_tag)
9 
10 // Example usage:
11 //
12 // class Iterator:
13 // public Forward_iterator_impl_<Iterator, Integer>
14 // {
15 // Integer m_current;
16 //
17 // public:
18 // void advance() { ++m_current; }
19 //
20 // auto operator*() const
21 // -> Integer
22 // { return m_current; }
23 //
24 // friend auto operator==( const Iterator& a, const Iterator& b )
25 // -> Truth
26 // { return a.m_current == b.m_current; }
27 //
28 // explicit Iterator( const Integer value )
29 // : m_current{ value }
30 // {}
31 // };
32 
33 namespace cppx
34 {
35  CPPX_USE_STD( forward_iterator_tag );
36 
37  template< class Derived, class Value_type_param >
39  {
40  auto derived_self()
41  -> Derived&
42  { return static_cast<Derived&>( *this ); }
43 
44  public:
45  // `std::iterator_traits` types:
47  using value_type = Value_type_param; // decltype( *declval<Derived>() );
49  using reference = const value_type&;
50  using iterator_category = forward_iterator_tag;
51 
52  using Value = Value_type_param;
53 
54  auto operator++()
55  -> const Derived&
56  {
57  derived_self().advance();
58  return derived_self();
59  }
60 
61  auto operator++( int )
62  -> Derived
63  {
64  Derived original = derived_self();
65  derived_self().advance();
66  return original;
67  }
68 
69  friend auto operator!=( const Derived& a, const Derived& b )
70  -> Truth
71  { return not(a == b); }
72  };
73 
74 } // namespace cppx
Some_type * P_
Creates a raw pointer type.
A drop-in replacement for bool without implicit conversion from/to types other than bool.
Definition: Truth.hpp:34
auto operator++() -> const Derived &
friend auto operator!=(const Derived &a, const Derived &b) -> Truth
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
Simple type builders Type_, P_, R_, Raw_array_ and Raw_array_of_.
Signed_< size_t > Size
A Signed_ equivalent of size_t.
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...
Signed Size and Index, plus unsigned equivalents Unsigned_size and Unsigned_index.