Commit cb2bf7c9 authored by Rounak Tibrewal's avatar Rounak Tibrewal Committed by Facebook GitHub Bot

Revert D25549986: De-template Range comparison operators

Differential Revision:
D25549986 (https://github.com/facebook/folly/commit/9a83e4242a933f91c9339b4c6d223267a43a89c1)

Original commit changeset: fd323e2e8cbf

fbshipit-source-id: af2bdb9f66d23d144f7e2e96118727d8b158f83f
parent b9f9aeb5
......@@ -1066,30 +1066,6 @@ class Range {
return process(split_step(delimiter), std::forward<Args>(args)...);
}
friend bool operator==(const Range& lhs, const Range& rhs) {
return lhs.size() == rhs.size() && lhs.compare(rhs) == 0;
}
friend bool operator!=(const Range& lhs, const Range& rhs) {
return !(operator==(lhs, rhs));
}
friend bool operator<(const Range& lhs, const Range& rhs) {
return lhs.compare(rhs) < 0;
}
friend bool operator<=(const Range& lhs, const Range& rhs) {
return lhs.compare(rhs) <= 0;
}
friend bool operator>(const Range& lhs, const Range& rhs) {
return lhs.compare(rhs) > 0;
}
friend bool operator>=(const Range& lhs, const Range& rhs) {
return lhs.compare(rhs) >= 0;
}
private:
Iter b_;
Iter e_;
......@@ -1175,6 +1151,118 @@ std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, Range<C*> piece) {
return os;
}
/**
* Templated comparison operators
*/
template <class Iter>
inline bool operator==(const Range<Iter>& lhs, const Range<Iter>& rhs) {
return lhs.size() == rhs.size() && lhs.compare(rhs) == 0;
}
template <class Iter>
inline bool operator!=(const Range<Iter>& lhs, const Range<Iter>& rhs) {
return !(operator==(lhs, rhs));
}
template <class Iter>
inline bool operator<(const Range<Iter>& lhs, const Range<Iter>& rhs) {
return lhs.compare(rhs) < 0;
}
template <class Iter>
inline bool operator<=(const Range<Iter>& lhs, const Range<Iter>& rhs) {
return lhs.compare(rhs) <= 0;
}
template <class Iter>
inline bool operator>(const Range<Iter>& lhs, const Range<Iter>& rhs) {
return lhs.compare(rhs) > 0;
}
template <class Iter>
inline bool operator>=(const Range<Iter>& lhs, const Range<Iter>& rhs) {
return lhs.compare(rhs) >= 0;
}
/**
* Specializations of comparison operators for StringPiece
*/
namespace detail {
template <class A, class B>
struct ComparableAsStringPiece {
enum {
value = (std::is_convertible<A, StringPiece>::value &&
std::is_same<B, StringPiece>::value) ||
(std::is_convertible<B, StringPiece>::value &&
std::is_same<A, StringPiece>::value)
};
};
} // namespace detail
/**
* operator== through conversion for Range<const char*>
*/
template <class T, class U>
std::enable_if_t<detail::ComparableAsStringPiece<T, U>::value, bool> operator==(
const T& lhs,
const U& rhs) {
return StringPiece(lhs) == StringPiece(rhs);
}
/**
* operator!= through conversion for Range<const char*>
*/
template <class T, class U>
std::enable_if_t<detail::ComparableAsStringPiece<T, U>::value, bool> operator!=(
const T& lhs,
const U& rhs) {
return StringPiece(lhs) != StringPiece(rhs);
}
/**
* operator< through conversion for Range<const char*>
*/
template <class T, class U>
std::enable_if_t<detail::ComparableAsStringPiece<T, U>::value, bool> operator<(
const T& lhs,
const U& rhs) {
return StringPiece(lhs) < StringPiece(rhs);
}
/**
* operator> through conversion for Range<const char*>
*/
template <class T, class U>
std::enable_if_t<detail::ComparableAsStringPiece<T, U>::value, bool> operator>(
const T& lhs,
const U& rhs) {
return StringPiece(lhs) > StringPiece(rhs);
}
/**
* operator< through conversion for Range<const char*>
*/
template <class T, class U>
std::enable_if_t<detail::ComparableAsStringPiece<T, U>::value, bool> operator<=(
const T& lhs,
const U& rhs) {
return StringPiece(lhs) <= StringPiece(rhs);
}
/**
* operator> through conversion for Range<const char*>
*/
template <class T, class U>
std::enable_if_t<detail::ComparableAsStringPiece<T, U>::value, bool> operator>=(
const T& lhs,
const U& rhs) {
return StringPiece(lhs) >= StringPiece(rhs);
}
/**
* Finds substrings faster than brute force by borrowing from Boyer-Moore
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment