Skip to content

Commit

Permalink
[Warnings] Removed Deprecated STD Iterator From VTR Vector
Browse files Browse the repository at this point in the history
This also remove a strange alias used called "my_iter" which, according
to the comment, was used to avoid potential ambiguity in the Clang
compiler. I am not sure what this means, but I think it should be less
ambiguous when we no longer inheret from std::iterator.
  • Loading branch information
AlexandreSinger committed May 27, 2024
1 parent 5d3ca68 commit 80420b7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions libs/libvtrutil/src/vtr_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,16 @@ class vector : private std::vector<V, Allocator> {
* This allows end-users to call the parent class's keys() member
* to iterate through the keys with a range-based for loop
*/
class key_iterator : public std::iterator<std::bidirectional_iterator_tag, key_type> {
class key_iterator {
public:
///@brief We use the intermediate type my_iter to avoid a potential ambiguity for which clang generates errors and warnings
using my_iter = typename std::iterator<std::bidirectional_iterator_tag, K>;
using typename my_iter::iterator;
using typename my_iter::pointer;
using typename my_iter::reference;
using typename my_iter::value_type;
using iterator_category = std::bidirectional_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = key_type;
using pointer = key_type*;
using reference = key_type&;

///@brief constructor
key_iterator(key_iterator::value_type init)
key_iterator(value_type init)
: value_(init) {}

/*
Expand All @@ -180,12 +179,12 @@ class vector : private std::vector<V, Allocator> {
* we can just increment the underlying Id to build the next key.
*/
///@brief ++ operator
key_iterator operator++() {
key_iterator& operator++() {
value_ = value_type(size_t(value_) + 1);
return *this;
}
///@brief decrement operator
key_iterator operator--() {
key_iterator& operator--() {
value_ = value_type(size_t(value_) - 1);
return *this;
}
Expand All @@ -195,9 +194,9 @@ class vector : private std::vector<V, Allocator> {
pointer operator->() { return &value_; }

///@brief == operator
friend bool operator==(const key_iterator lhs, const key_iterator rhs) { return lhs.value_ == rhs.value_; }
friend bool operator==(const key_iterator& lhs, const key_iterator& rhs) { return lhs.value_ == rhs.value_; }
///@brief != operator
friend bool operator!=(const key_iterator lhs, const key_iterator rhs) { return !(lhs == rhs); }
friend bool operator!=(const key_iterator& lhs, const key_iterator& rhs) { return !(lhs == rhs); }

private:
value_type value_;
Expand Down

0 comments on commit 80420b7

Please sign in to comment.