2
3
4
5
6
7
8
9
10
11
12
14#ifndef IPADDRESS_IP_ADDRESS_ITERATOR_HPP
15#define IPADDRESS_IP_ADDRESS_ITERATOR_HPP
24
25
26
27
28
29
30
31
32
33
37 using iterator_category =
typename std::iterator_traits<Iterator>::iterator_category;
38 using iterator_type = Iterator;
39 using value_type =
typename std::iterator_traits<Iterator>::value_type;
40 using difference_type =
typename std::iterator_traits<Iterator>::difference_type;
41 using pointer =
typename std::iterator_traits<Iterator>::pointer;
42 using reference =
typename std::iterator_traits<Iterator>::reference;
44 using uint_type =
typename Iterator::uint_type;
47
48
49
50
54
55
56
57
58
59
65
66
67
68
69
70
71
73 return other._it.uint_diff(_it);
77
78
79
80
86
87
88
89
95
96
97
98
104
105
106
107
108
114
115
116
117
118
124
125
126
127
134
135
136
137
145
146
147
148
155
156
157
158
166
167
168
169
170
171
172
179
180
181
182
183
184
185
192
193
194
195
196
197
198
205
206
207
208
209
210
211
218
219
220
221
222
223
224
232
233
234
235
236
237
238
246
247
248
249
250
251
252
253
259
260
261
262
263
264
265
266
272
273
274
275
276
277
278
286
287
288
289
290
291
292
300
301
302
303
304
305
306
308 return difference_type(other._it - _it);
312
313
314
315
316
317
318
320 return other._it == _it;
324
325
326
327
328
329
330
332 return !(*
this == other);
335#ifdef IPADDRESS_HAS_SPACESHIP_OPERATOR
338
339
340
341
342
343
344
352
353
354
355
356
357
358
360 return other._it < _it;
364
365
366
367
368
369
370
372 return !(other < *
this);
376
377
378
379
380
381
382
384 return other < *
this;
388
389
390
391
392
393
394
396 return !(*
this < other);
406class ip_address_iterator;
409
410
411
412
413
414
415
416
417
421 using iterator_category = std::random_access_iterator_tag;
423 using difference_type = int64_t;
424 using pointer =
const value_type*;
425 using reference =
const value_type&;
427 using uint_type =
typename value_type::uint_type;
430
431
432
433
437
438
439
440
441
442
443
445 : _current(ref), _offset(ref.to_uint()), _carry(carry) {
449
450
451
452
453
454
455
457 return _offset - other._offset;
461
462
463
464
470
471
472
473
479
480
481
482
483
485 const auto& it = *
this;
486 return it[uint_type(n)];
490
491
492
493
494
496 return value_type::from_uint(_offset + n);
500
501
502
503
504
505
512
513
514
515
516
517
525
526
527
528
529
530
537
538
539
540
541
542
550
551
552
553
554
555
556
563
564
565
566
567
568
569
576
577
578
579
580
581
582
589
590
591
592
593
594
595
602
603
604
605
606
607
608
616
617
618
619
620
621
622
630
631
632
633
634
635
636
637
643
644
645
646
647
648
649
650
656
657
658
659
660
661
662
670
671
672
673
674
675
676
684
685
686
687
688
689
690
692 return difference_type(_offset - other._offset);
696
697
698
699
700
701
702
704 return _carry == other._carry && _current == other._current;
708
709
710
711
712
713
714
716 return !(*
this == other);
719#ifdef IPADDRESS_HAS_SPACESHIP_OPERATOR
722
723
724
725
726
727
728
729 IPADDRESS_NODISCARD IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE std::strong_ordering operator<=>(
const ip_address_iterator& other)
const IPADDRESS_NOEXCEPT {
730 if (
const auto result = _carry <=> other._carry; result == std::strong_ordering::equivalent) {
731 return _current <=> other._current;
740
741
742
743
744
745
746
748 return _carry < other._carry || (_carry == other._carry && _current < other._current);
752
753
754
755
756
757
758
760 return !(other < *
this);
764
765
766
767
768
769
770
772 return other < *
this;
776
777
778
779
780
781
782
784 return !(*
this < other);
792 const auto old = result._offset;
794 if (result._offset < old) {
795 result._carry = 1 - result._carry;
797 result._current = value_type::from_uint(result._offset);
803 const auto old = result._offset;
805 if (result._offset > old) {
806 result._carry = 1 - result._carry;
808 result._current = value_type::from_uint(result._offset);
814 const auto old = _offset;
819 _current = value_type::from_uint(_offset);
825 const auto old = _offset;
830 _current = value_type::from_uint(_offset);
840 template <
typename,
typename,
typename>
843 value_type _current{};
852
853
854
855
856
857
858
859
860
865 using size_type = size_t;
866 using difference_type =
typename value_type::uint_type;
867 using pointer = value_type*;
868 using const_pointer =
const value_type*;
869 using reference = value_type&;
870 using const_reference =
const value_type&;
872 using iterator = ip_address_iterator<value_type>;
873 using const_iterator = ip_address_iterator<value_type>;
879
880
881
882
883
884
885
886
887
888
890 if (prefixlen == max_prefixlen - 1) {
891 const auto begin = value_type::from_uint(network_address.to_uint());
892 const auto end = value_type::from_uint(broadcast_address.to_uint() + 1);
893 _begin = const_iterator(begin);
894 _end = const_iterator(end);
895 }
else if (prefixlen == max_prefixlen) {
896 const auto begin = value_type::from_uint(network_address.to_uint());
897 const auto end = value_type::from_uint(network_address.to_uint() + 1);
898 _begin = const_iterator(begin);
899 _end = const_iterator(end, end < begin ? 1 : 0);
901 const auto begin = value_type::from_uint(network_address.to_uint() + 1);
902 const auto end = value_type::from_uint(broadcast_address.to_uint() + (std::is_same<value_type, ipv6_address>::value ? 1 : 0));
903 _begin = const_iterator(begin);
904 _end = const_iterator(end);
909
910
911
912
918
919
920
921
927
928
929
930
932 return const_reverse_iterator(
end());
936
937
938
939
941 return const_reverse_iterator(
begin());
945
946
947
948
954
955
956
957
963
964
965
966
968 return const_reverse_iterator(
cend());
972
973
974
975
977 return const_reverse_iterator(
cbegin());
981
982
983
984
986 return _begin == _end;
990
991
992
993
995 return _end.uint_diff(_begin);
999
1000
1001
1002
1003
1009
1010
1011
1012
1013
1015 return *(_begin + n);
1019
1020
1021
1022
1028
1029
1030
1031
1033 return *(_end - 1U);
1037 const_iterator _begin{};
1038 const_iterator _end{};
constexpr inline const_reverse_iterator crbegin() const noexcept
Gets the beginning const reverse iterator of the sequence.
Definition ip-address-iterator.hpp:967
constexpr inline value_type operator[](difference_type n) const noexcept
Accesses an element by index.
Definition ip-address-iterator.hpp:1004
constexpr inline const_iterator begin() const noexcept
Gets the beginning iterator of the sequence.
Definition ip-address-iterator.hpp:913
constexpr inline bool empty() const noexcept
Checks if the sequence is empty.
Definition ip-address-iterator.hpp:985
constexpr inline value_type back() const noexcept
Accesses the last element in the sequence.
Definition ip-address-iterator.hpp:1032
constexpr inline const_reverse_iterator crend() const noexcept
Gets the end const reverse iterator of the sequence.
Definition ip-address-iterator.hpp:976
constexpr inline value_type front() const noexcept
Accesses the first element in the sequence.
Definition ip-address-iterator.hpp:1023
constexpr inline difference_type size() const noexcept
Gets the size of the sequence.
Definition ip-address-iterator.hpp:994
constexpr inline const_reverse_iterator rend() const noexcept
Gets the end reverse iterator of the sequence.
Definition ip-address-iterator.hpp:940
constexpr inline const_iterator cend() const noexcept
Gets the end const iterator of the sequence.
Definition ip-address-iterator.hpp:958
constexpr inline hosts_sequence(const_reference network_address, const_reference broadcast_address, size_t prefixlen, size_t max_prefixlen) noexcept
Constructs a hosts_sequence with specified network parameters.
Definition ip-address-iterator.hpp:889
constexpr inline const_iterator cbegin() const noexcept
Gets the beginning const iterator of the sequence.
Definition ip-address-iterator.hpp:949
constexpr inline const_iterator end() const noexcept
Gets the end iterator of the sequence.
Definition ip-address-iterator.hpp:922
constexpr inline value_type at(difference_type n) const noexcept
Accesses an element by index with bounds checking.
Definition ip-address-iterator.hpp:1014
constexpr inline const_reverse_iterator rbegin() const noexcept
Gets the beginning reverse iterator of the sequence.
Definition ip-address-iterator.hpp:931
A template base class for IP address representations.
Definition ip-address-base.hpp:56
constexpr inline bool operator>=(const ip_address_iterator &other) const noexcept
Greater-than-or-equal-to operator.
Definition ip-address-iterator.hpp:783
constexpr inline bool operator<=(const ip_address_iterator &other) const noexcept
Less-than-or-equal-to operator.
Definition ip-address-iterator.hpp:759
constexpr inline ip_address_iterator & operator+=(const uint_type &n) noexcept
Addition assignment operator.
Definition ip-address-iterator.hpp:570
constexpr inline value_type operator[](difference_type n) const noexcept
Accesses an element by index.
Definition ip-address-iterator.hpp:484
constexpr inline value_type operator[](const uint_type &n) const noexcept
Accesses an element by index.
Definition ip-address-iterator.hpp:495
constexpr inline difference_type operator-(const ip_address_iterator &other) const noexcept
Subtraction operator.
Definition ip-address-iterator.hpp:691
constexpr inline ip_address_iterator(reference ref, int carry=0) noexcept
Constructs an ip_address_iterator with a specific range and reference point.
Definition ip-address-iterator.hpp:444
constexpr inline ip_address_iterator operator++(int) noexcept
Post-increment operator.
Definition ip-address-iterator.hpp:518
constexpr inline ip_address_iterator operator+(const uint_type &n) const noexcept
Addition operator.
Definition ip-address-iterator.hpp:623
constexpr inline ip_address_iterator & operator++() noexcept
Pre-increment operator.
Definition ip-address-iterator.hpp:506
constexpr inline uint_type uint_diff(const ip_address_iterator &other) const noexcept
Calculates the difference in the number of elements between this and another ip_address_iterator.
Definition ip-address-iterator.hpp:456
constexpr inline ip_address_iterator & operator-=(const uint_type &n) noexcept
Subtraction assignment operator.
Definition ip-address-iterator.hpp:596
constexpr inline bool operator<(const ip_address_iterator &other) const noexcept
Less-than operator.
Definition ip-address-iterator.hpp:747
friend constexpr inline ip_address_iterator operator+(const uint_type &n, const ip_address_iterator &it) noexcept
Addition operator.
Definition ip-address-iterator.hpp:651
constexpr inline ip_address_iterator operator+(difference_type n) const noexcept
Addition operator.
Definition ip-address-iterator.hpp:609
constexpr inline ip_address_iterator & operator-=(difference_type n) noexcept
Subtraction assignment operator.
Definition ip-address-iterator.hpp:583
constexpr inline ip_address_iterator() noexcept=default
Default constructor.
constexpr inline pointer operator->() const noexcept
Returns a pointer to the current element.
Definition ip-address-iterator.hpp:474
constexpr inline bool operator==(const ip_address_iterator &other) const noexcept
Equality operator.
Definition ip-address-iterator.hpp:703
constexpr inline bool operator!=(const ip_address_iterator &other) const noexcept
Inequality operator.
Definition ip-address-iterator.hpp:715
constexpr inline ip_address_iterator operator--(int) noexcept
Post-decrement operator.
Definition ip-address-iterator.hpp:543
constexpr inline reference operator*() const noexcept
Returns a reference to the current element.
Definition ip-address-iterator.hpp:465
constexpr inline bool operator>(const ip_address_iterator &other) const noexcept
Greater-than operator.
Definition ip-address-iterator.hpp:771
constexpr inline ip_address_iterator operator-(difference_type n) const noexcept
Subtraction operator.
Definition ip-address-iterator.hpp:663
friend constexpr inline ip_address_iterator operator+(difference_type n, const ip_address_iterator &it) noexcept
Addition operator.
Definition ip-address-iterator.hpp:638
constexpr inline ip_address_iterator operator-(const uint_type &n) const noexcept
Subtraction operator.
Definition ip-address-iterator.hpp:677
constexpr inline ip_address_iterator & operator--() noexcept
Pre-decrement operator.
Definition ip-address-iterator.hpp:531
constexpr inline ip_address_iterator & operator+=(difference_type n) noexcept
Addition assignment operator.
Definition ip-address-iterator.hpp:557
An iterator for unified traversal over IPv4 and IPv6 address spaces.
Definition ip-any-iterator.hpp:44
An iterator for traversing IP addresses within a network range.
Definition ip-network-iterator.hpp:33
A reverse iterator template class for IP addresses.
Definition ip-address-iterator.hpp:35
constexpr inline bool operator>(const ip_reverse_iterator &other) const noexcept
Greater-than operator.
Definition ip-address-iterator.hpp:383
constexpr inline difference_type operator-(const ip_reverse_iterator &other) const noexcept
Subtraction operator.
Definition ip-address-iterator.hpp:307
constexpr inline value_type operator[](difference_type n) const noexcept
Accesses an element by index.
Definition ip-address-iterator.hpp:109
constexpr inline uint_type uint_diff(const ip_reverse_iterator &other) const noexcept
Calculates the difference in the number of elements between this and another ip_reverse_iterator.
Definition ip-address-iterator.hpp:72
constexpr inline bool operator<(const ip_reverse_iterator &other) const noexcept
Less-than operator.
Definition ip-address-iterator.hpp:359
constexpr inline value_type operator[](const uint_type &n) const noexcept
Accesses an element by index.
Definition ip-address-iterator.hpp:119
constexpr inline ip_reverse_iterator & operator-=(difference_type n) noexcept
Subtraction assignment operator.
Definition ip-address-iterator.hpp:199
constexpr inline ip_reverse_iterator & operator--() noexcept
Pre-decrement operator.
Definition ip-address-iterator.hpp:149
constexpr inline ip_reverse_iterator & operator++() noexcept
Pre-increment operator.
Definition ip-address-iterator.hpp:128
constexpr inline bool operator<=(const ip_reverse_iterator &other) const noexcept
Less-than-or-equal-to operator.
Definition ip-address-iterator.hpp:371
friend constexpr inline ip_reverse_iterator operator+(difference_type n, const ip_reverse_iterator &it) noexcept
Addition operator.
Definition ip-address-iterator.hpp:254
constexpr inline iterator_type base() const noexcept
Returns the underlying base iterator.
Definition ip-address-iterator.hpp:81
friend constexpr inline ip_reverse_iterator operator+(const uint_type &n, const ip_reverse_iterator &it) noexcept
Addition operator.
Definition ip-address-iterator.hpp:267
constexpr inline ip_reverse_iterator operator--(int) noexcept
Post-decrement operator.
Definition ip-address-iterator.hpp:159
constexpr inline ip_reverse_iterator operator-(difference_type n) const noexcept
Subtraction operator.
Definition ip-address-iterator.hpp:279
constexpr inline bool operator==(const ip_reverse_iterator &other) const noexcept
Equality operator.
Definition ip-address-iterator.hpp:319
constexpr inline bool operator>=(const ip_reverse_iterator &other) const noexcept
Greater-than-or-equal-to operator.
Definition ip-address-iterator.hpp:395
constexpr inline ip_reverse_iterator operator+(const uint_type &n) const noexcept
Addition operator.
Definition ip-address-iterator.hpp:239
constexpr inline ip_reverse_iterator operator++(int) noexcept
Post-increment operator.
Definition ip-address-iterator.hpp:138
constexpr inline bool operator!=(const ip_reverse_iterator &other) const noexcept
Inequality operator.
Definition ip-address-iterator.hpp:331
constexpr inline ip_reverse_iterator operator+(difference_type n) const noexcept
Addition operator.
Definition ip-address-iterator.hpp:225
constexpr inline pointer operator->() const noexcept
Returns a pointer to the current element.
Definition ip-address-iterator.hpp:99
constexpr inline ip_reverse_iterator & operator-=(const uint_type &n) noexcept
Subtraction assignment operator.
Definition ip-address-iterator.hpp:212
constexpr inline ip_reverse_iterator & operator+=(const uint_type &n) noexcept
Addition assignment operator.
Definition ip-address-iterator.hpp:186
constexpr inline ip_reverse_iterator() noexcept=default
Default constructor.
constexpr inline ip_reverse_iterator(Iterator it) noexcept
Constructs an ip_reverse_iterator from an underlying iterator.
Definition ip-address-iterator.hpp:60
constexpr inline reference operator*() const noexcept
Returns a reference to the current element.
Definition ip-address-iterator.hpp:90
constexpr inline ip_reverse_iterator & operator+=(difference_type n) noexcept
Addition assignment operator.
Definition ip-address-iterator.hpp:173
constexpr inline ip_reverse_iterator operator-(const uint_type &n) const noexcept
Subtraction operator.
Definition ip-address-iterator.hpp:293
#define IPADDRESS_EXPORT
Definition config.hpp:42
#define IPADDRESS_NODISCARD
Definition config.hpp:98
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:112
#define IPADDRESS_NAMESPACE
Definition config.hpp:38
#define IPADDRESS_NOEXCEPT
Definition config.hpp:89