Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[small_map] Use hidden friends for operator==/!= #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions src/base/small_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,18 @@ class small_map {
}
}

inline bool operator==(const iterator& other) const {
if (array_iter_ != NULL) {
return array_iter_ == other.array_iter_;
friend bool operator==(const iterator& a, const iterator& b) {
if (a.array_iter_ != NULL) {
return a.array_iter_ == b.array_iter_;
} else {
return other.array_iter_ == NULL && hash_iter_ == other.hash_iter_;
return b.array_iter_ == NULL && a.hash_iter_ == b.hash_iter_;
}
}

inline bool operator!=(const iterator& other) const {
return !(*this == other);
friend bool operator!=(const iterator& a, const iterator& b) {
return !(a == b);
}

bool operator==(const const_iterator& other) const;
bool operator!=(const const_iterator& other) const;

private:
friend class small_map;
friend class const_iterator;
Expand Down Expand Up @@ -277,16 +274,16 @@ class small_map {
}
}

inline bool operator==(const const_iterator& other) const {
if (array_iter_ != NULL) {
return array_iter_ == other.array_iter_;
friend bool operator==(const const_iterator& a, const const_iterator& b) {
if (a.array_iter_ != NULL) {
return a.array_iter_ == b.array_iter_;
} else {
return other.array_iter_ == NULL && hash_iter_ == other.hash_iter_;
return b.array_iter_ == NULL && a.hash_iter_ == b.hash_iter_;
}
}

inline bool operator!=(const const_iterator& other) const {
return !(*this == other);
friend bool operator!=(const const_iterator& a, const const_iterator& b) {
return !(a == b);
}

private:
Expand Down Expand Up @@ -549,21 +546,6 @@ class small_map {
}
};

template <typename NormalMap, int kArraySize, typename EqualKey,
typename Functor>
inline bool small_map<NormalMap, kArraySize, EqualKey,
Functor>::iterator::operator==(
const const_iterator& other) const {
return other == *this;
}
template <typename NormalMap, int kArraySize, typename EqualKey,
typename Functor>
inline bool small_map<NormalMap, kArraySize, EqualKey,
Functor>::iterator::operator!=(
const const_iterator& other) const {
return other != *this;
}

}

#endif // UTIL_GTL_SMALL_MAP_H_