Skip to content

Commit 905184e

Browse files
committed
removed deprecated in C++17 std::iterator
1 parent fb94dcb commit 905184e

10 files changed

+88
-33
lines changed

include/sdsl/cst_iterators.hpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ namespace sdsl
4444
*/
4545
// TODO: implement operator--
4646
template<class Cst, uint32_t cache_size=128>
47-
class cst_dfs_const_forward_iterator: public std::iterator<std::forward_iterator_tag, typename Cst::node_type>
47+
class cst_dfs_const_forward_iterator
4848
{
4949
public:
50-
typedef typename Cst::node_type value_type;
50+
using iterator_category = std::forward_iterator_tag;
51+
using value_type = typename Cst::node_type;
52+
using difference_type = void;
53+
using pointer = void;
54+
using reference = void;
55+
5156
typedef const value_type const_reference;
5257
typedef typename Cst::size_type size_type;
5358
typedef cst_dfs_const_forward_iterator<Cst> iterator;
@@ -177,10 +182,15 @@ class cst_dfs_const_forward_iterator: public std::iterator<std::forward_iterator
177182

178183
//! A forward iterator for a bottom up traversal of a suffix tree
179184
template<class Cst>
180-
class cst_bottom_up_const_forward_iterator: public std::iterator<std::forward_iterator_tag, typename Cst::node_type>
185+
class cst_bottom_up_const_forward_iterator
181186
{
182187
public:
183-
typedef typename Cst::node_type value_type;
188+
using iterator_category = std::forward_iterator_tag;
189+
using value_type = typename Cst::node_type;
190+
using difference_type = void;
191+
using pointer = void;
192+
using reference = void;
193+
184194
typedef const value_type const_reference;
185195
typedef typename Cst::size_type size_type;
186196
typedef cst_bottom_up_const_forward_iterator<Cst> iterator;
@@ -251,10 +261,15 @@ class cst_bottom_up_const_forward_iterator: public std::iterator<std::forward_it
251261
* you should use an external implementation of a queue.
252262
*/
253263
template<class Cst, class Queue = std::queue<typename Cst::node_type> >
254-
class cst_bfs_iterator: public std::iterator<std::forward_iterator_tag, typename Cst::node_type>
264+
class cst_bfs_iterator
255265
{
256266
public:
257-
typedef typename Cst::node_type value_type;
267+
using iterator_category = std::forward_iterator_tag;
268+
using value_type = typename Cst::node_type;
269+
using difference_type = void;
270+
using pointer = void;
271+
using reference = void;
272+
258273
typedef const value_type const_reference;
259274
typedef typename Cst::size_type size_type;
260275
typedef cst_bfs_iterator<Cst, Queue> iterator;

include/sdsl/int_vector.hpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ inline void swap(int_vector_reference<bit_vector> x,
828828

829829

830830
template<class t_int_vector>
831-
class int_vector_iterator_base: public std::iterator<std::random_access_iterator_tag, typename t_int_vector::value_type, typename t_int_vector::difference_type>
831+
class int_vector_iterator_base
832832
{
833833
public:
834834
typedef uint64_t size_type;
@@ -849,12 +849,14 @@ class int_vector_iterator : public int_vector_iterator_base<t_int_vector>
849849
{
850850
public:
851851

852-
typedef int_vector_reference<t_int_vector> reference;
853-
typedef uint64_t value_type;
852+
using iterator_category = std::random_access_iterator_tag;
853+
using value_type = typename t_int_vector::value_type;
854+
using difference_type = typename t_int_vector::difference_type;
855+
using pointer = typename t_int_vector::value_type*;
856+
using reference = int_vector_reference<t_int_vector>;
857+
854858
typedef int_vector_iterator iterator;
855-
typedef reference* pointer;
856859
typedef typename t_int_vector::size_type size_type;
857-
typedef typename t_int_vector::difference_type difference_type;
858860

859861
friend class int_vector_const_iterator<t_int_vector>;
860862
private:
@@ -1011,11 +1013,14 @@ class int_vector_const_iterator : public int_vector_iterator_base<t_int_vector>
10111013
{
10121014
public:
10131015

1014-
typedef typename t_int_vector::value_type const_reference;
1015-
typedef const typename t_int_vector::value_type* pointer;
1016+
using iterator_category = std::random_access_iterator_tag;
1017+
using value_type = const typename t_int_vector::value_type;
1018+
using difference_type = typename t_int_vector::difference_type;
1019+
using pointer = const typename t_int_vector::value_type*;
1020+
using reference = const typename t_int_vector::value_type;
1021+
10161022
typedef int_vector_const_iterator const_iterator;
10171023
typedef typename t_int_vector::size_type size_type;
1018-
typedef typename t_int_vector::difference_type difference_type;
10191024

10201025
template<class X>
10211026
friend typename int_vector_const_iterator<X>::difference_type
@@ -1045,7 +1050,7 @@ class int_vector_const_iterator : public int_vector_iterator_base<t_int_vector>
10451050
return *this;
10461051
}
10471052

1048-
const_reference operator*() const
1053+
reference operator*() const
10491054
{
10501055
return bits::read_int(m_word, m_offset, m_len);
10511056
}
@@ -1126,7 +1131,7 @@ class int_vector_const_iterator : public int_vector_iterator_base<t_int_vector>
11261131
return it -= i;
11271132
}
11281133

1129-
const_reference operator[](difference_type i) const
1134+
reference operator[](difference_type i) const
11301135
{
11311136
return *(*this + i);
11321137
}

include/sdsl/int_vector_buffer.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,17 @@ class int_vector_buffer
492492
}
493493
};
494494

495-
class iterator: public std::iterator<std::random_access_iterator_tag, value_type, difference_type, value_type*, reference>
495+
class iterator
496496
{
497497
private:
498498
int_vector_buffer<t_width>& m_ivb;
499499
uint64_t m_idx = 0;
500500
public:
501+
using iterator_category = std::random_access_iterator_tag;
502+
using value_type = int_vector_buffer<t_width>::value_type;
503+
using difference_type = int_vector_buffer<t_width>::difference_type;
504+
using pointer = value_type*;
505+
using reference = int_vector_buffer<t_width>::reference;
501506

502507
iterator() = delete;
503508
iterator(int_vector_buffer<t_width>& ivb, uint64_t idx=0) : m_ivb(ivb), m_idx(idx) {}

include/sdsl/iterators.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ namespace sdsl
3030
/*! \tparam t_rac Type of random access container.
3131
*/
3232
template<class t_rac>
33-
class random_access_const_iterator: public std::iterator<std::random_access_iterator_tag, typename t_rac::value_type, typename t_rac::difference_type>
33+
class random_access_const_iterator
3434
{
3535
public:
36+
using iterator_category = std::random_access_iterator_tag;
37+
using value_type = typename t_rac::value_type;
38+
using difference_type = typename t_rac::difference_type;
39+
using pointer = void;
40+
using reference = void;
41+
3642
typedef const typename t_rac::value_type const_reference;
3743
typedef typename t_rac::size_type size_type;
3844
typedef random_access_const_iterator<t_rac> iterator;
39-
typedef typename t_rac::difference_type difference_type;
4045

4146
private:
4247
const t_rac* m_rac;// pointer to the random access container

include/sdsl/lcp_byte.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class lcp_byte
170170
if (m_small_lcp[i]!=255) {
171171
return m_small_lcp[i];
172172
} else {
173-
size_type idx = lower_bound(m_big_lcp_idx.begin(),
174-
m_big_lcp_idx.end(),i)
173+
size_type idx = std::lower_bound(m_big_lcp_idx.begin(),
174+
m_big_lcp_idx.end(),i)
175175
- m_big_lcp_idx.begin();
176176
return m_big_lcp[idx];
177177
}

include/sdsl/sd_vector.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,7 @@ class sd_vector
278278
m_size = builder.m_size;
279279
m_wl = builder.m_wl;
280280
m_low.swap(builder.m_low);
281-
if constexpr(std::is_same<hi_bit_vector_type, bit_vector>::value) {
282-
m_high.swap(builder.m_high);
283-
} else {
284-
util::assign(m_high, builder.m_high);
285-
}
281+
util::assign(m_high, builder.m_high);
286282
util::init_support(m_high_1_select, &m_high);
287283
util::init_support(m_high_0_select, &m_high);
288284

@@ -445,6 +441,9 @@ class sd_vector
445441
}
446442
};
447443

444+
//! Specialized constructor that is a bit more space-efficient than the default.
445+
template<> sd_vector<>::sd_vector(sd_vector_builder& builder);
446+
448447
template<uint8_t t_b>
449448
struct rank_support_sd_trait {
450449
typedef bit_vector::size_type size_type;

include/sdsl/suffix_tree_helper.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ namespace sdsl
1515

1616

1717
template <class t_cst>
18-
class cst_node_child_proxy_iterator : public std::iterator<std::forward_iterator_tag, typename t_cst::node_type>
18+
class cst_node_child_proxy_iterator
1919
{
2020
public:
21+
using iterator_category = std::forward_iterator_tag;
22+
using value_type = typename t_cst::node_type;
23+
using difference_type = void;
24+
using pointer = void;
25+
using reference = void;
26+
2127
using node_type = typename t_cst::node_type;
22-
using value_type = node_type;
2328
using const_reference = const node_type;
2429
using iterator_type = cst_node_child_proxy_iterator<t_cst>;
2530
private:

include/sdsl/wt_gmr.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#ifndef INCLUDED_SDSL_WT_GMR
2323
#define INCLUDED_SDSL_WT_GMR
2424

25+
#include <algorithm> // for lower_bound
26+
2527
#include <sdsl/bit_vectors.hpp>
2628
#include <sdsl/int_vector.hpp>
2729
#include <sdsl/int_vector_buffer.hpp>
@@ -485,7 +487,7 @@ class wt_gmr_rs
485487
++search_begin;
486488
}
487489
} else {
488-
if (binary_search(m_e.begin()+search_begin, m_e.begin()+search_end, val)) {
490+
if (std::binary_search(m_e.begin()+search_begin, m_e.begin()+search_end, val)) {
489491
return (block-1)/m_blocks;
490492
}
491493
}
@@ -520,7 +522,7 @@ class wt_gmr_rs
520522
if (end-begin<50) { // After a short test, this seems to be a good threshold
521523
offset = std::find_if(begin, end, [&val](const decltype(*begin) x) { return x > val; }) - begin;
522524
} else {
523-
offset = lower_bound(begin, end, val+1)-begin;
525+
offset = std::lower_bound(begin, end, val+1)-begin;
524526
}
525527
return (begin-m_e.begin())+offset-ones_before_cblock;
526528
}
@@ -556,7 +558,7 @@ class wt_gmr_rs
556558
++search_begin;
557559
}
558560
} else {
559-
offset = lower_bound(m_e.begin()+search_begin, m_e.begin()+search_end, val)-m_e.begin();
561+
offset = std::lower_bound(m_e.begin()+search_begin, m_e.begin()+search_end, val)-m_e.begin();
560562
if (offset<search_end) {
561563
if (m_e[offset]==val) {
562564
value_type c = (block-1)/m_blocks;
@@ -875,7 +877,7 @@ class wt_gmr
875877
if (end-begin<50) { // After a short test, this seems to be a good threshold
876878
c_ones_in_chunk = std::find_if(begin, end, [&val](const decltype(*begin) x) { return x > val; }) - begin;
877879
} else {
878-
c_ones_in_chunk = lower_bound(begin, end, val+1) - begin;
880+
c_ones_in_chunk = std::lower_bound(begin, end, val+1) - begin;
879881
}
880882
return c_ones_before_chunk+c_ones_in_chunk;
881883
}

lib/sd_vector.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,23 @@ void sd_vector_builder::swap(sd_vector_builder& sdb)
4949
m_high.swap(sdb.m_high);
5050
}
5151

52+
template<>
53+
sd_vector<>::sd_vector(sd_vector_builder& builder)
54+
{
55+
if (builder.items() < builder.capacity()) {
56+
throw std::runtime_error("sd_vector: the builder is not full.");
57+
} else if (builder.items() > builder.capacity()) {
58+
throw std::runtime_error("sd_vector: builder overflow.");
59+
}
60+
61+
m_size = builder.m_size;
62+
m_wl = builder.m_wl;
63+
m_low.swap(builder.m_low);
64+
m_high.swap(builder.m_high);
65+
util::init_support(m_high_1_select, &m_high);
66+
util::init_support(m_high_0_select, &m_high);
67+
68+
builder = sd_vector_builder();
69+
}
70+
5271
} // end namespace

test/inv_perm_support_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class inv_perm_support_test : public ::testing::Test
2828
for (size_t z=0; z < (1ULL<<20); z=(z+1)*2) {
2929
sdsl::int_vector<> iv(z);
3030
sdsl::util::set_to_id(iv);
31-
random_shuffle(iv.begin(), iv.end());
31+
std::random_shuffle(iv.begin(), iv.end());
3232
perms.emplace_back(iv);
3333
}
3434
for (size_t i=0; i<perms.size(); ++i) {

0 commit comments

Comments
 (0)