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

Replace boost::totally_ordered with explicit operator overloads for SdfListProxy #2285

Merged
merged 1 commit into from
Jul 3, 2023
Merged
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
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 <boost/type_traits/is_base_of.hpp>
#include <boost/type_traits/remove_cv.hpp>
Expand All @@ -56,9 +55,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 @@ -67,7 +64,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 @@ -89,14 +86,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 @@ -416,16 +431,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