Skip to content

Commit

Permalink
Merge pull request #2285 from nvmkuruc/sdflistordered
Browse files Browse the repository at this point in the history
Replace `boost::totally_ordered` with explicit operator overloads for `SdfListProxy`

(Internal change: 2282503)
  • Loading branch information
pixar-oss committed Jun 23, 2023
2 parents 68755eb + dac68a9 commit 5c3540f
Showing 1 changed file with 65 additions and 5 deletions.
70 changes: 65 additions & 5 deletions pxr/usd/sdf/listProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "pxr/base/tf/iterator.h"
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/operators.hpp>
#include <boost/optional.hpp>

#include <memory>
Expand All @@ -54,9 +53,7 @@ PXR_NAMESPACE_OPEN_SCOPE
/// insertion sequence).
///
template <class _TypePolicy>
class SdfListProxy :
boost::totally_ordered<SdfListProxy<_TypePolicy>,
std::vector<typename _TypePolicy::value_type> > {
class SdfListProxy {
public:
typedef _TypePolicy TypePolicy;
typedef SdfListProxy<TypePolicy> This;
Expand All @@ -65,7 +62,7 @@ class SdfListProxy :

private:
// Proxies an item in a list editor list.
class _ItemProxy : boost::totally_ordered<_ItemProxy> {
class _ItemProxy {
public:
explicit _ItemProxy(This* owner, size_t index) :
_owner(owner), _index(index)
Expand All @@ -87,14 +84,32 @@ class SdfListProxy :
return _owner->_Get(_index);
}

// Operators rely on implicit conversion to value_type
// for comparing two _ItemProxy instances
bool operator==(const value_type& x) const {
return _owner->_Get(_index) == x;
}

bool operator!=(const value_type& x) const {
return !(*this == x);
}

bool operator<(const value_type& x) const {
return _owner->_Get(_index) < x;
}

bool operator>(const value_type& x) const {
return x < value_type(*this);
}

bool operator>=(const value_type& x) const {
return !(*this < x);
}

bool operator<=(const value_type& x) const {
return !(x < value_type(*this));
}

private:
This* _owner;
size_t _index;
Expand Down Expand Up @@ -414,16 +429,61 @@ class SdfListProxy :
return value_vector_type(*this) == y;
}

/// Equality comparision
friend bool operator==(const value_vector_type& x, const SdfListProxy& y) {
return y == x;
}

/// Inequality comparison.
bool operator!=(const value_vector_type& y) const {
return !(*this == y);
}

/// Inequality comparision
friend bool operator!=(const value_vector_type& x, const SdfListProxy& y) {
return y != x;
}

/// Less-than comparison.
bool operator<(const value_vector_type& y) const {
return value_vector_type(*this) < y;
}

/// Less-than comparison
friend bool operator<(const value_vector_type& x, const SdfListProxy& y) {
return x < value_vector_type(y);
}

/// Greater-than comparison.
bool operator>(const value_vector_type& y) const {
return value_vector_type(*this) > y;
}

/// Greater-than comparison.
friend bool operator>(const value_vector_type& x, const SdfListProxy& y) {
return x > value_vector_type(y);
}

/// Less-than or equal to comparison.
bool operator<=(const value_vector_type& y) const {
return !(*this > y);
}

/// Less-than or equal to comparison.
friend bool operator<=(const value_vector_type& x, const SdfListProxy& y) {
return x <= value_vector_type(y);
}

/// Greater-than or equal to comparison.
bool operator>=(const value_vector_type& y) const {
return !(*this < y);
}

/// Greater-than or equal to comparison.
friend bool operator>=(const value_vector_type& x, const SdfListProxy& y) {
return x >= value_vector_type(y);
}

/// Explicit bool conversion operator. The list proxy object converts to
/// \c true if the list editor is valid, \c false otherwise.
explicit operator bool() const
Expand Down

0 comments on commit 5c3540f

Please sign in to comment.