tenno 0.1.0
Loading...
Searching...
No Matches
ranges.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <cstddef> // for std::ptrdiff_t
9#include <iterator> // for std::forward_iterator_tag
10#include <tenno/types.hpp>
11
12namespace tenno
13{
14
20template <typename T> class range
21{
22public:
25
26 constexpr range(T start, T end) : start_elem(start), end_elem(end)
27 {
28 }
29
30 constexpr explicit range(T end) : start_elem(0), end_elem(end)
31 {
32 }
33
34 constexpr tenno::size size() const noexcept
35 {
37 }
38
39 struct iterator
40 {
41 using iterator_category = std::forward_iterator_tag;
42 using difference_type = std::ptrdiff_t;
43 using value_type = T;
44 using pointer = T *;
45 using reference = T &;
46
48 constexpr explicit iterator(T current_it) : current(current_it)
49 {
50 }
51
52 constexpr T operator*() const noexcept
53 {
54 return current;
55 }
56
57 constexpr iterator &operator++() noexcept
58 {
59 ++current;
60 return *this;
61 }
62
63 constexpr iterator operator++(int) noexcept
64 {
65 iterator _iterator = *this;
66 ++*this;
67 return _iterator;
68 }
69
70 constexpr bool operator!=(const iterator &other) const noexcept
71 {
72 return current != other.current;
73 }
74 };
75
76 constexpr iterator begin() const noexcept
77 {
78 return iterator(start_elem);
79 }
80
81 constexpr iterator end() const noexcept
82 {
83 return iterator(end_elem);
84 }
85
86}; // class range
87
88} // namespace tenno
A range of elements.
Definition ranges.hpp:21
constexpr range(T start, T end)
Definition ranges.hpp:26
constexpr iterator begin() const noexcept
Definition ranges.hpp:76
constexpr tenno::size size() const noexcept
Definition ranges.hpp:34
constexpr range(T end)
Definition ranges.hpp:30
constexpr iterator end() const noexcept
Definition ranges.hpp:81
size_t size
Definition types.hpp:13
std::ptrdiff_t difference_type
Definition ranges.hpp:42
constexpr iterator operator++(int) noexcept
Definition ranges.hpp:63
std::forward_iterator_tag iterator_category
Definition ranges.hpp:41
constexpr bool operator!=(const iterator &other) const noexcept
Definition ranges.hpp:70
constexpr iterator(T current_it)
Definition ranges.hpp:48
constexpr T operator*() const noexcept
Definition ranges.hpp:52
constexpr iterator & operator++() noexcept
Definition ranges.hpp:57