2
3
4
5
6
7
8
9
10
11
12
13
14
15
17#ifndef IPADDRESS_IP_ANY_ITERATOR_HPP
18#define IPADDRESS_IP_ANY_ITERATOR_HPP
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
47 using iterator_category = std::random_access_iterator_tag;
49 using difference_type = int64_t;
50 using pointer =
const value_type*;
51 using reference =
const value_type&;
56
57
61
62
63
64
69
70
71
72
77
78
79
80
81
82
83
85 if (_version != other._version) {
88 return _version ==
ip_version::V4 ?
uint128_t(_iter.iter4.uint_diff(other._iter.iter4)) : _iter.iter6.uint_diff(other._iter.iter6);
92
93
94
95
101
102
103
104
110
111
112
113
114
116 const auto& it = *
this;
121
122
123
124
125
127 return _version ==
ip_version::V4 ? value_type(_iter.iter4[uint32_t(n)]) : value_type(_iter.iter6[n]);
131
132
133
134
141
142
143
144
152
153
154
155
162
163
164
165
173
174
175
176
177
178
179
186
187
188
189
190
191
192
199
200
201
202
203
204
205
212
213
214
215
216
217
218
225
226
227
228
229
230
231
239
240
241
242
243
244
245
253
254
255
256
257
258
259
260
266
267
268
269
270
271
272
273
279
280
281
282
283
284
285
293
294
295
296
297
298
299
307
308
309
310
311
312
313
315 if (_version != other._version) {
318 return _version ==
ip_version::V4 ? _iter.iter4 - other._iter.iter4 : _iter.iter6 - other._iter.iter6;
322
323
324
325
326
327
328
330 if (_version != other._version) {
333 return _version ==
ip_version::V4 ? _iter.iter4 == other._iter.iter4 : _iter.iter6 == other._iter.iter6;
337
338
339
340
341
342
343
345 return !(*
this == other);
348#ifdef IPADDRESS_HAS_SPACESHIP_OPERATOR
351
352
353
354
355
356
357
369
370
371
372
373
374
375
377 if (_version != other._version) {
380 return _version ==
ip_version::V4 ? _iter.iter4 < other._iter.iter4 : _iter.iter6 < other._iter.iter6;
384
385
386
387
388
389
390
392 return !(other < *
this);
396
397
398
399
400
401
402
404 return other < *
this;
408
409
410
411
412
413
414
416 return !(*
this < other);
432 _iter.iter4 += uint32_t(n);
433 _current = *_iter.iter4;
436 _current = *_iter.iter6;
442 _iter.iter4 -= uint32_t(n);
443 _current = *_iter.iter4;
446 _current = *_iter.iter6;
467 value_type _current {};
471
472
473
474
475
476
477
478
482 using iterator_category = std::forward_iterator_tag;
483 using value_type = T;
485 using pointer =
const value_type*;
486 using reference =
const value_type&;
488 using ip_address_type =
typename value_type::ip_address_type;
491
492
496
497
498
499
500
502 : _version(current.version()) {
503 assert(current.version() == last.version());
505 _itv4 = { current.v4().value(), last.v4().value() };
508 _itv6 = { current.v6().value(), last.v6().value() };
514
515
516
517
523
524
525
526
532
533
534
535
536
537
550
551
552
553
554
555
563
564
565
566
567
568
569
571 return _version == other._version && _version == ip_version::V4 ? _itv4 == other._itv4 : _itv6 == other._itv6;
575
576
577
578
579
580
581
583 return !(*
this == other);
594
595
596
597
598
599
600
601
602
608 using pointer = value_type*;
609 using const_pointer =
const value_type*;
610 using reference = value_type&;
611 using const_reference =
const value_type&;
613 using iterator =
ip_any_iterator<value_type, ip_address_iterator<ipv4_address>, ip_address_iterator<ipv6_address>>;
614 using const_iterator = iterator;
620
621
622
623
624
629
630
631
632
633
638
639
640
641
647
648
649
650
656
657
658
659
661 return const_reverse_iterator(end());
665
666
667
668
670 return const_reverse_iterator(begin());
674
675
676
677
683
684
685
686
692
693
694
695
697 return const_reverse_iterator(cend());
701
702
703
704
706 return const_reverse_iterator(cbegin());
710
711
712
713
715 return _begin == _end;
719
720
721
722
724 return _end.uint_diff(_begin);
728
729
730
731
732
738
739
740
741
742
744 return *(_begin + n);
748
749
750
751
757
758
759
760
766 const_iterator _begin{};
767 const_iterator _end{};
771
772
773
774
775
776
777
778
779
780
784 using value_type = T;
787 using pointer = value_type*;
788 using const_pointer =
const value_type*;
789 using reference = value_type&;
790 using const_reference =
const value_type&;
793 using const_iterator = iterator;
799
800
801
802
803
808
809
810
811
812
817
818
819
820
826
827
828
829
835
836
837
838
840 return const_reverse_iterator(
end());
844
845
846
847
849 return const_reverse_iterator(
begin());
853
854
855
856
862
863
864
865
871
872
873
874
876 return const_reverse_iterator(
cend());
880
881
882
883
885 return const_reverse_iterator(
cbegin());
889
890
891
892
894 return _begin == _end;
898
899
900
901
903 return _end.uint_diff(_begin);
907
908
909
910
911
917
918
919
920
921
923 return *(_begin + n);
927
928
929
930
936
937
938
939
945 const_iterator _begin{};
946 const_iterator _end{};
A sequence of host IP addresses.
Definition ip-any-iterator.hpp:603
constexpr inline const_reverse_iterator crbegin() const noexcept
Gets the beginning const reverse iterator of the sequence.
Definition ip-any-iterator.hpp:696
constexpr inline value_type operator[](difference_type n) const noexcept
Accesses an element by index.
Definition ip-any-iterator.hpp:733
constexpr inline const_iterator begin() const noexcept
Gets the beginning iterator of the sequence.
Definition ip-any-iterator.hpp:642
constexpr inline bool empty() const noexcept
Checks if the sequence is empty.
Definition ip-any-iterator.hpp:714
constexpr inline value_type back() const noexcept
Accesses the last element in the sequence.
Definition ip-any-iterator.hpp:761
constexpr inline const_reverse_iterator crend() const noexcept
Gets the end const reverse iterator of the sequence.
Definition ip-any-iterator.hpp:705
constexpr inline value_type front() const noexcept
Accesses the first element in the sequence.
Definition ip-any-iterator.hpp:752
constexpr inline difference_type size() const noexcept
Gets the size of the sequence.
Definition ip-any-iterator.hpp:723
constexpr inline hosts_any_sequence(ip_address_iterator< ipv6_address > begin, ip_address_iterator< ipv6_address > end) noexcept
Constructs a hosts_any_sequence with specified network parameters.
Definition ip-any-iterator.hpp:634
constexpr inline const_reverse_iterator rend() const noexcept
Gets the end reverse iterator of the sequence.
Definition ip-any-iterator.hpp:669
constexpr inline const_iterator cend() const noexcept
Gets the end const iterator of the sequence.
Definition ip-any-iterator.hpp:687
constexpr inline const_iterator cbegin() const noexcept
Gets the beginning const iterator of the sequence.
Definition ip-any-iterator.hpp:678
constexpr inline const_iterator end() const noexcept
Gets the end iterator of the sequence.
Definition ip-any-iterator.hpp:651
constexpr inline value_type at(difference_type n) const noexcept
Accesses an element by index with bounds checking.
Definition ip-any-iterator.hpp:743
constexpr inline const_reverse_iterator rbegin() const noexcept
Gets the beginning reverse iterator of the sequence.
Definition ip-any-iterator.hpp:660
constexpr inline hosts_any_sequence(ip_address_iterator< ipv4_address > begin, ip_address_iterator< ipv4_address > end) noexcept
Constructs a hosts_any_sequence with specified network parameters.
Definition ip-any-iterator.hpp:625
A class that represents an IP address, supporting both IPv4 and IPv6 formats.
Definition ip-any-address.hpp:73
An iterator for unified traversal over IPv4 and IPv6 address spaces.
Definition ip-any-iterator.hpp:45
constexpr inline ip_any_iterator(Ipv6Iter iter) noexcept
Constructs an ip_any_iterator from an Ipv6Iter iterator.
Definition ip-any-iterator.hpp:73
constexpr inline ip_any_iterator() noexcept=default
Default constructor.
friend constexpr inline ip_any_iterator operator+(const uint128_t &n, const ip_any_iterator &it) noexcept
Addition operator.
Definition ip-any-iterator.hpp:274
constexpr inline bool operator<(const ip_any_iterator &other) const noexcept
Less-than operator.
Definition ip-any-iterator.hpp:376
constexpr inline value_type operator[](difference_type n) const noexcept
Accesses an element by index.
Definition ip-any-iterator.hpp:115
constexpr inline difference_type operator-(const ip_any_iterator &other) const noexcept
Subtraction operator.
Definition ip-any-iterator.hpp:314
constexpr inline ip_any_iterator & operator+=(const uint128_t &n) noexcept
Addition assignment operator.
Definition ip-any-iterator.hpp:193
constexpr inline ip_any_iterator operator+(difference_type n) const noexcept
Addition operator.
Definition ip-any-iterator.hpp:232
constexpr inline bool operator<=(const ip_any_iterator &other) const noexcept
Less-than-or-equal-to operator.
Definition ip-any-iterator.hpp:391
constexpr inline bool operator!=(const ip_any_iterator &other) const noexcept
Inequality operator.
Definition ip-any-iterator.hpp:344
constexpr inline ip_any_iterator & operator-=(const uint128_t &n) noexcept
Subtraction assignment operator.
Definition ip-any-iterator.hpp:219
constexpr inline ip_any_iterator operator-(difference_type n) const noexcept
Subtraction operator.
Definition ip-any-iterator.hpp:286
constexpr inline value_type operator[](const uint128_t &n) const noexcept
Accesses an element by index.
Definition ip-any-iterator.hpp:126
constexpr inline ip_any_iterator operator-(const uint128_t &n) const noexcept
Subtraction operator.
Definition ip-any-iterator.hpp:300
constexpr inline uint128_t uint_diff(const ip_any_iterator &other) const noexcept
Calculates the difference in the number of elements between this and another ip_any_iterator.
Definition ip-any-iterator.hpp:84
constexpr inline ip_any_iterator(Ipv4Iter iter) noexcept
Constructs an ip_any_iterator from an Ipv4Iter iterator.
Definition ip-any-iterator.hpp:65
constexpr inline bool operator>(const ip_any_iterator &other) const noexcept
Greater-than operator.
Definition ip-any-iterator.hpp:403
constexpr inline ip_any_iterator operator++(int) noexcept
Post-increment operator.
Definition ip-any-iterator.hpp:145
constexpr inline bool operator==(const ip_any_iterator &other) const noexcept
Equality operator.
Definition ip-any-iterator.hpp:329
constexpr inline bool operator>=(const ip_any_iterator &other) const noexcept
Greater-than-or-equal-to operator.
Definition ip-any-iterator.hpp:415
constexpr inline ip_any_iterator & operator--() noexcept
Pre-decrement operator.
Definition ip-any-iterator.hpp:156
friend constexpr inline ip_any_iterator operator+(difference_type n, const ip_any_iterator &it) noexcept
Addition operator.
Definition ip-any-iterator.hpp:261
constexpr inline pointer operator->() const noexcept
Returns a pointer to the current element.
Definition ip-any-iterator.hpp:105
constexpr inline ip_any_iterator operator+(const uint128_t &n) const noexcept
Addition operator.
Definition ip-any-iterator.hpp:246
constexpr inline ip_any_iterator & operator+=(difference_type n) noexcept
Addition assignment operator.
Definition ip-any-iterator.hpp:180
constexpr inline ip_any_iterator & operator++() noexcept
Pre-increment operator.
Definition ip-any-iterator.hpp:135
constexpr inline reference operator*() const noexcept
Returns a reference to the current element.
Definition ip-any-iterator.hpp:96
constexpr inline ip_any_iterator & operator-=(difference_type n) noexcept
Subtraction assignment operator.
Definition ip-any-iterator.hpp:206
constexpr inline ip_any_iterator operator--(int) noexcept
Post-decrement operator.
Definition ip-any-iterator.hpp:166
Forward iterator for summarizing an IP address range.
Definition ip-any-iterator.hpp:480
constexpr inline ip_any_summarize_iterator & operator++() noexcept
Pre-increment operator.
Definition ip-any-iterator.hpp:538
constexpr inline bool operator!=(const ip_any_summarize_iterator &other) const noexcept
Inequality operator.
Definition ip-any-iterator.hpp:582
constexpr inline bool operator==(const ip_any_summarize_iterator &other) const noexcept
Equality operator.
Definition ip-any-iterator.hpp:570
constexpr inline ip_any_summarize_iterator operator++(int) noexcept
Post-increment operator.
Definition ip-any-iterator.hpp:556
constexpr inline ip_any_summarize_iterator(const ip_address_type ¤t, const ip_address_type &last) noexcept
Constructs a ip_any_summarize_iterator for an address range.
Definition ip-any-iterator.hpp:501
constexpr inline pointer operator->() const noexcept
Returns a pointer to the current element.
Definition ip-any-iterator.hpp:527
constexpr inline ip_any_summarize_iterator() noexcept=default
Default constructor.
constexpr inline reference operator*() const noexcept
Returns a reference to the current element.
Definition ip-any-iterator.hpp:518
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
Forward iterator for summarizing an IP address range.
Definition ip-network-iterator.hpp:676
A sequence container for subnet ranges within a network.
Definition ip-any-iterator.hpp:782
constexpr inline const_reverse_iterator crbegin() const noexcept
Gets the beginning const reverse iterator of the sequence.
Definition ip-any-iterator.hpp:875
constexpr inline value_type operator[](difference_type n) const noexcept
Accesses an element by index.
Definition ip-any-iterator.hpp:912
constexpr inline const_iterator begin() const noexcept
Gets the beginning iterator of the sequence.
Definition ip-any-iterator.hpp:821
constexpr inline bool empty() const noexcept
Checks if the sequence is empty.
Definition ip-any-iterator.hpp:893
constexpr inline value_type back() const noexcept
Accesses the last element in the sequence.
Definition ip-any-iterator.hpp:940
constexpr inline const_reverse_iterator crend() const noexcept
Gets the end const reverse iterator of the sequence.
Definition ip-any-iterator.hpp:884
constexpr inline value_type front() const noexcept
Accesses the first element in the sequence.
Definition ip-any-iterator.hpp:931
constexpr inline difference_type size() const noexcept
Gets the size of the sequence.
Definition ip-any-iterator.hpp:902
constexpr inline subnets_any_sequence(ip_network_iterator< ipv4_network > begin, ip_network_iterator< ipv4_network > end) noexcept
Constructs a subnets_any_sequence with specified network parameters.
Definition ip-any-iterator.hpp:804
constexpr inline const_reverse_iterator rend() const noexcept
Gets the end reverse iterator of the sequence.
Definition ip-any-iterator.hpp:848
constexpr inline const_iterator cend() const noexcept
Gets the end const iterator of the sequence.
Definition ip-any-iterator.hpp:866
constexpr inline const_iterator cbegin() const noexcept
Gets the beginning const iterator of the sequence.
Definition ip-any-iterator.hpp:857
constexpr inline const_iterator end() const noexcept
Gets the end iterator of the sequence.
Definition ip-any-iterator.hpp:830
constexpr inline value_type at(difference_type n) const noexcept
Accesses an element by index with bounds checking.
Definition ip-any-iterator.hpp:922
constexpr inline const_reverse_iterator rbegin() const noexcept
Gets the beginning reverse iterator of the sequence.
Definition ip-any-iterator.hpp:839
constexpr inline subnets_any_sequence(ip_network_iterator< ipv6_network > begin, ip_network_iterator< ipv6_network > end) noexcept
Constructs a subnets_any_sequence with specified network parameters.
Definition ip-any-iterator.hpp:813
constexpr inline uint128_t(long lower) noexcept
Constructs a uint128_t instance from a signed integer.
Definition uint128.hpp:206
inline std::u8string to_u8string(format fmt=format::decimal) const
Converts the uint128_t value to a string representation.
Definition uint128.hpp:403
#define IPADDRESS_EXPORT
Definition config.hpp:45
#define IPADDRESS_NODISCARD
Definition config.hpp:101
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:115
#define IPADDRESS_NAMESPACE
Definition config.hpp:41
#define IPADDRESS_NOEXCEPT
Definition config.hpp:92
ip_version
Enumerates the IP address versions.
Definition ip-address-base.hpp:29
@ V4
IPv4 version identifier.
@ V6
IPv6 version identifier.