Skip to content
Merged
Show file tree
Hide file tree
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
39 changes: 17 additions & 22 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1449,20 +1449,6 @@ namespace cppwinrt
{
++(*this);
}
)");
}
else if (type_name == "Windows.Foundation.Collections.IKeyValuePair`2")
{
w.write(R"(
bool operator==(Windows::Foundation::Collections::IKeyValuePair<K, V> const& other) const
{
return Key() == other.Key() && Value() == other.Value();
}

bool operator!=(Windows::Foundation::Collections::IKeyValuePair<K, V> const& other) const
{
return !(*this == other);
}
)");
}
else if (type_name == "Windows.Foundation.Collections.IMapView`2")
Expand Down Expand Up @@ -2527,6 +2513,18 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
}
}

static void write_interface_equal_operator(writer& w, TypeDef const& type)
{
if (remove_tick(type.TypeName()) == "IKeyValuePair")
{
w.write(R"( bool operator==(IKeyValuePair const& other) const
{
return this->Key() == other.Key() && this->Value() == other.Value();
}
)");
}
}

static void write_class_usings(writer& w, TypeDef const& type)
{
auto type_name = type.TypeName();
Expand Down Expand Up @@ -2595,6 +2593,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
{
%(std::nullptr_t = nullptr) noexcept {}
%(void* ptr, take_ownership_from_abi_t) noexcept : winrt::Windows::Foundation::IInspectable(ptr, take_ownership_from_abi) {}
%
%% };
)";

Expand All @@ -2605,6 +2604,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
type_name,
type_name,
bind<write_interface_usings>(type),
bind<write_interface_equal_operator>(type),
bind<write_interface_extensions>(type));
}
else
Expand All @@ -2618,6 +2618,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
{%
%(std::nullptr_t = nullptr) noexcept {}
%(void* ptr, take_ownership_from_abi_t) noexcept : winrt::Windows::Foundation::IInspectable(ptr, take_ownership_from_abi) {}
%
%% };
)";

Expand All @@ -2630,6 +2631,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
type_name,
type_name,
bind<write_interface_usings>(type),
bind<write_interface_equal_operator>(type),
bind<write_interface_extensions>(type));
}
}
Expand Down Expand Up @@ -2913,10 +2915,6 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
{
return%;
}
inline bool operator!=(% const& left, % const& right)%
{
return !(left == right);
}
)";

if (types.empty())
Expand Down Expand Up @@ -3001,10 +2999,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
name,
name,
is_noexcept,
bind<write_struct_equality>(type.fields),
name,
name,
is_noexcept);
bind<write_struct_equality>(type.fields));

for (auto&& field : type.fields)
{
Expand Down
41 changes: 12 additions & 29 deletions strings/base_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ WINRT_EXPORT namespace winrt
array_view(other.data(), other.size())
{}

template <typename U, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>, int> = 0>
bool operator==(array_view<U> const& right) const noexcept
{
return std::equal(begin(), end(), right.begin(), right.end());
}

template <typename U, std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>, int> = 0>
std::weak_ordering operator<=>(array_view<U> const& right) const noexcept
{
return std::lexicographical_compare_three_way(begin(), end(), right.begin(), right.end());
}

reference operator[](size_type const pos) noexcept
{
WINRT_ASSERT(pos < size());
Expand Down Expand Up @@ -400,35 +412,6 @@ WINRT_EXPORT namespace winrt
template <typename C, std::size_t extent> com_array(std::span<C, extent> const& value) -> com_array<std::decay_t<C>>;


namespace impl
{
template <typename T, typename U>
inline constexpr bool array_comparable = std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>;
}

template <typename T, typename U,
std::enable_if_t<impl::array_comparable<T, U>, int> = 0>
bool operator==(array_view<T> const& left, array_view<U> const& right) noexcept
{
return std::equal(left.begin(), left.end(), right.begin(), right.end());
}

template <typename T, typename U,
std::enable_if_t<impl::array_comparable<T, U>, int> = 0>
bool operator<(array_view<T> const& left, array_view<U> const& right) noexcept
{
return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
}

template <typename T, typename U, std::enable_if_t<impl::array_comparable<T, U>, int> = 0>
bool operator!=(array_view<T> const& left, array_view<U> const& right) noexcept { return !(left == right); }
template <typename T, typename U,std::enable_if_t<impl::array_comparable<T, U>, int> = 0>
bool operator>(array_view<T> const& left, array_view<U> const& right) noexcept { return right < left; }
template <typename T, typename U,std::enable_if_t<impl::array_comparable<T, U>, int> = 0>
bool operator<=(array_view<T> const& left, array_view<U> const& right) noexcept { return !(right < left); }
template <typename T, typename U, std::enable_if_t<impl::array_comparable<T, U>, int> = 0>
bool operator>=(array_view<T> const& left, array_view<U> const& right) noexcept { return !(left < right); }

template <typename T>
auto get_abi(array_view<T> object) noexcept
{
Expand Down
73 changes: 13 additions & 60 deletions strings/base_com_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ WINRT_EXPORT namespace winrt
release_ref();
}

bool operator==(com_ptr const& other) const noexcept = default;
auto operator<=>(com_ptr const& other) const noexcept = default;

bool operator==(std::nullptr_t) const noexcept
{
return m_ptr == nullptr;
}

friend bool operator==(std::nullptr_t, com_ptr const& right) noexcept
{
return right == nullptr;
}

com_ptr& operator=(com_ptr const& other) noexcept
{
copy_ref(other.m_ptr);
Expand Down Expand Up @@ -287,66 +300,6 @@ WINRT_EXPORT namespace winrt
{
return object.detach();
}

template <typename T>
bool operator==(com_ptr<T> const& left, com_ptr<T> const& right) noexcept
{
return get_abi(left) == get_abi(right);
}

template <typename T>
bool operator==(com_ptr<T> const& left, std::nullptr_t) noexcept
{
return get_abi(left) == nullptr;
}

template <typename T>
bool operator==(std::nullptr_t, com_ptr<T> const& right) noexcept
{
return nullptr == get_abi(right);
}

template <typename T>
bool operator!=(com_ptr<T> const& left, com_ptr<T> const& right) noexcept
{
return !(left == right);
}

template <typename T>
bool operator!=(com_ptr<T> const& left, std::nullptr_t) noexcept
{
return !(left == nullptr);
}

template <typename T>
bool operator!=(std::nullptr_t, com_ptr<T> const& right) noexcept
{
return !(nullptr == right);
}

template <typename T>
bool operator<(com_ptr<T> const& left, com_ptr<T> const& right) noexcept
{
return get_abi(left) < get_abi(right);
}

template <typename T>
bool operator>(com_ptr<T> const& left, com_ptr<T> const& right) noexcept
{
return right < left;
}

template <typename T>
bool operator<=(com_ptr<T> const& left, com_ptr<T> const& right) noexcept
{
return !(right < left);
}

template <typename T>
bool operator>=(com_ptr<T> const& left, com_ptr<T> const& right) noexcept
{
return !(left < right);
}
}

WINRT_EXPORT namespace winrt::impl
Expand Down
5 changes: 1 addition & 4 deletions strings/base_fast_forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ WINRT_EXPORT namespace winrt::impl
std::uint16_t Data2;
std::uint16_t Data3;
std::uint8_t Data4[8];
inline bool operator!=(guid const& right) const noexcept
{
return std::memcmp(this, &right, sizeof(guid));
}
constexpr bool operator==(guid const&) const noexcept = default;
};

struct WINRT_IMPL_FF_NOVTABLE WINRT_IMPL_FF_PUBLIC inspectable
Expand Down
36 changes: 6 additions & 30 deletions strings/base_foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
}

#endif
};

constexpr bool operator==(Point const& left, Point const& right) noexcept
{
return left.X == right.X && left.Y == right.Y;
}

constexpr bool operator!=(Point const& left, Point const& right) noexcept
{
return !(left == right);
}
constexpr bool operator==(Point const&) const noexcept = default;
};

struct Size
{
Expand All @@ -59,17 +51,9 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
}

#endif
};

constexpr bool operator==(Size const& left, Size const& right) noexcept
{
return left.Width == right.Width && left.Height == right.Height;
}

constexpr bool operator!=(Size const& left, Size const& right) noexcept
{
return !(left == right);
}
constexpr bool operator==(Size const&) const noexcept = default;
};

struct Rect
{
Expand All @@ -87,17 +71,9 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
constexpr Rect(Point const& point, Size const& size) noexcept :
X(point.X), Y(point.Y), Width(size.Width), Height(size.Height)
{}
};

constexpr bool operator==(Rect const& left, Rect const& right) noexcept
{
return left.X == right.X && left.Y == right.Y && left.Width == right.Width && left.Height == right.Height;
}

constexpr bool operator!=(Rect const& left, Rect const& right) noexcept
{
return !(left == right);
}
constexpr bool operator==(Rect const&) const noexcept = default;
};
}

WINRT_EXPORT namespace winrt::impl
Expand Down
1 change: 1 addition & 0 deletions strings/base_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
// C++ 20 headers

#include <version>
#include <compare>
#include <span>
#include <format>
#include <source_location>
Expand Down
25 changes: 2 additions & 23 deletions strings/base_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,10 @@ WINRT_EXPORT namespace winrt::impl
return m_index == other.m_index;
}

bool operator<(fast_iterator const& other) const noexcept
auto operator<=>(fast_iterator const& other) const noexcept
{
WINRT_ASSERT(m_collection == other.m_collection);
return m_index < other.m_index;
}

bool operator>(fast_iterator const& other) const noexcept
{
WINRT_ASSERT(m_collection == other.m_collection);
return m_index > other.m_index;
}

bool operator!=(fast_iterator const& other) const noexcept
{
return !(*this == other);
}

bool operator<=(fast_iterator const& other) const noexcept
{
return !(*this > other);
}

bool operator>=(fast_iterator const& other) const noexcept
{
return !(*this < other);
return m_index <=> other.m_index;
}

friend fast_iterator operator+(difference_type n, fast_iterator it) noexcept
Expand Down
6 changes: 0 additions & 6 deletions strings/base_reference_produce.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,6 @@ WINRT_EXPORT namespace winrt::Windows::Foundation

return left.Value() == right.Value();
}

template <typename T>
bool operator!=(IReference<T> const& left, IReference<T> const& right)
{
return !(left == right);
}
}

WINRT_EXPORT namespace winrt::impl
Expand Down
3 changes: 0 additions & 3 deletions strings/base_reference_produce_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
{
template <typename T>
bool operator==(IReference<T> const& left, IReference<T> const& right);

template <typename T>
bool operator!=(IReference<T> const& left, IReference<T> const& right);
}
Loading