quadgrid
0.1
simple cartesian quad grid with particles for c++/octave
Toggle main menu visibility
Loading...
Searching...
No Matches
counter.h
Go to the documentation of this file.
1
#ifndef HAVE_COUNTER_H
2
#define HAVE_COUNTER_H
3
4
#include <iterator>
5
6
template
<
typename
N>
7
struct
range
{
8
9
struct
10
iterator
{
11
friend
class
range
;
12
using
difference_type
=
typename
std::make_signed_t<N>;
13
using
iterator_category
= std::random_access_iterator_tag;
14
using
value_type
= N;
15
using
reference
= N;
16
using
pointer
=
const
N*;
17
iterator
&operator ++() { ++
i_
;
return
*
this
; }
18
iterator
operator ++(
int
) {
iterator
copy(*
this
); ++
i_
;
return
copy; }
19
reference
operator *()
const
{
return
i_
; }
20
bool
operator ==(
const
iterator
&other)
const
{
return
i_
== *other; }
21
bool
operator !=(
const
iterator
&other)
const
{
return
i_
!= *other; }
22
23
bool
operator <(
const
iterator
&other)
const
{
return
i_
< *other; }
24
difference_type
operator -(
const
iterator
&other)
const
{
return
static_cast<
difference_type
>
(
i_
) -
static_cast<
difference_type
>
(*other); }
25
iterator
operator -(
const
difference_type
other)
const
{
return
iterator
(
static_cast<
value_type
>
(
static_cast<
difference_type
>
(
i_
) - other)); }
26
iterator
operator +(
const
difference_type
other)
const
{
return
iterator
(
static_cast<
value_type
>
(
static_cast<
difference_type
>
(
i_
) + other)); }
27
value_type
operator[] (
const
value_type
& idx) {
return
i_
+ idx; }
28
protected
:
explicit
iterator
(
difference_type
start) :
i_
(start) {};
29
private
:
30
N
i_
;
31
};
32
33
iterator
begin
()
const
{
return
begin_
; }
34
iterator
end
()
const
{
return
end_
; }
35
range
(N
begin
, N
end
) :
begin_
(
begin
),
end_
(
end
) {}
36
37
private
:
38
iterator
begin_
,
end_
;
39
};
40
41
#endif
range::iterator
Definition
counter.h:10
range::iterator::iterator
iterator(difference_type start)
Definition
counter.h:28
range::iterator::value_type
N value_type
Definition
counter.h:14
range::iterator::reference
N reference
Definition
counter.h:15
range::iterator::pointer
const N * pointer
Definition
counter.h:16
range::iterator::i_
N i_
Definition
counter.h:30
range::iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition
counter.h:13
range::iterator::range
friend class range
Definition
counter.h:11
range::iterator::difference_type
typename std::make_signed_t< N > difference_type
Definition
counter.h:12
range::begin
iterator begin() const
Definition
counter.h:33
range::range
range(N begin, N end)
Definition
counter.h:35
range::end_
iterator end_
Definition
counter.h:38
range::begin_
iterator begin_
Definition
counter.h:38
range::end
iterator end() const
Definition
counter.h:34
include
counter.h
Generated by
1.18.0