This is an automated email from the ASF dual-hosted git repository. fokko pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push: new 3cf5963 refactor: remove explicit operator!= using C++20 rewrite candidates (#123) 3cf5963 is described below commit 3cf596370d2b82ba82d7875bb5f7618bd339b224 Author: mwish <maplewish...@gmail.com> AuthorDate: Thu Jun 19 22:23:26 2025 +0800 refactor: remove explicit operator!= using C++20 rewrite candidates (#123) C++20 supports rewrite candidates, see https://en.cppreference.com/w/cpp/language/overload_resolution.html#Call_to_an_overloaded_operator > For `x != y`, all member, non-member, and built-in `operator==`s found are added to the set, unless there is a matching `operator!=`. --- src/iceberg/partition_field.h | 4 ---- src/iceberg/partition_spec.h | 4 ---- src/iceberg/schema.h | 2 -- src/iceberg/schema_field.h | 4 ---- src/iceberg/snapshot.h | 16 ---------------- src/iceberg/sort_field.h | 4 ---- src/iceberg/sort_order.h | 4 ---- src/iceberg/statistics_file.h | 16 ---------------- src/iceberg/table_metadata.h | 12 ------------ src/iceberg/transform.h | 9 --------- src/iceberg/type.cc | 3 ++- src/iceberg/type.h | 3 --- 12 files changed, 2 insertions(+), 79 deletions(-) diff --git a/src/iceberg/partition_field.h b/src/iceberg/partition_field.h index daec404..5206cf2 100644 --- a/src/iceberg/partition_field.h +++ b/src/iceberg/partition_field.h @@ -62,10 +62,6 @@ class ICEBERG_EXPORT PartitionField : public util::Formattable { return lhs.Equals(rhs); } - friend bool operator!=(const PartitionField& lhs, const PartitionField& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two fields for equality. [[nodiscard]] bool Equals(const PartitionField& other) const; diff --git a/src/iceberg/partition_spec.h b/src/iceberg/partition_spec.h index a18ba7b..f105a27 100644 --- a/src/iceberg/partition_spec.h +++ b/src/iceberg/partition_spec.h @@ -75,10 +75,6 @@ class ICEBERG_EXPORT PartitionSpec : public util::Formattable { return lhs.Equals(rhs); } - friend bool operator!=(const PartitionSpec& lhs, const PartitionSpec& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two partition specs for equality. [[nodiscard]] bool Equals(const PartitionSpec& other) const; diff --git a/src/iceberg/schema.h b/src/iceberg/schema.h index edc25d6..490acb6 100644 --- a/src/iceberg/schema.h +++ b/src/iceberg/schema.h @@ -56,8 +56,6 @@ class ICEBERG_EXPORT Schema : public StructType { friend bool operator==(const Schema& lhs, const Schema& rhs) { return lhs.Equals(rhs); } - friend bool operator!=(const Schema& lhs, const Schema& rhs) { return !(lhs == rhs); } - private: /// \brief Compare two schemas for equality. [[nodiscard]] bool Equals(const Schema& other) const; diff --git a/src/iceberg/schema_field.h b/src/iceberg/schema_field.h index afef717..e947f20 100644 --- a/src/iceberg/schema_field.h +++ b/src/iceberg/schema_field.h @@ -76,10 +76,6 @@ class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable { return lhs.Equals(rhs); } - friend bool operator!=(const SchemaField& lhs, const SchemaField& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two fields for equality. [[nodiscard]] bool Equals(const SchemaField& other) const; diff --git a/src/iceberg/snapshot.h b/src/iceberg/snapshot.h index 2df6a44..a16522a 100644 --- a/src/iceberg/snapshot.h +++ b/src/iceberg/snapshot.h @@ -80,9 +80,6 @@ struct ICEBERG_EXPORT SnapshotRef { return lhs.Equals(rhs); } - /// \brief Compare two branches for inequality. - friend bool operator!=(const Branch& lhs, const Branch& rhs) { return !(lhs == rhs); } - private: /// \brief Compare two branches for equality. bool Equals(const Branch& other) const; @@ -97,9 +94,6 @@ struct ICEBERG_EXPORT SnapshotRef { /// \brief Compare two tags for equality. friend bool operator==(const Tag& lhs, const Tag& rhs) { return lhs.Equals(rhs); } - /// \brief Compare two tags for inequality. - friend bool operator!=(const Tag& lhs, const Tag& rhs) { return !(lhs == rhs); } - private: /// \brief Compare two tags for equality. bool Equals(const Tag& other) const; @@ -117,11 +111,6 @@ struct ICEBERG_EXPORT SnapshotRef { return lhs.Equals(rhs); } - /// \brief Compare two snapshot refs for inequality. - friend bool operator!=(const SnapshotRef& lhs, const SnapshotRef& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two snapshot refs for equality. bool Equals(const SnapshotRef& other) const; @@ -263,11 +252,6 @@ struct ICEBERG_EXPORT Snapshot { return lhs.Equals(rhs); } - /// \brief Compare two snapshots for inequality. - friend bool operator!=(const Snapshot& lhs, const Snapshot& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two snapshots for equality. bool Equals(const Snapshot& other) const; diff --git a/src/iceberg/sort_field.h b/src/iceberg/sort_field.h index 263bbc6..f255033 100644 --- a/src/iceberg/sort_field.h +++ b/src/iceberg/sort_field.h @@ -113,10 +113,6 @@ class ICEBERG_EXPORT SortField : public util::Formattable { return lhs.Equals(rhs); } - friend bool operator!=(const SortField& lhs, const SortField& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two fields for equality. [[nodiscard]] bool Equals(const SortField& other) const; diff --git a/src/iceberg/sort_order.h b/src/iceberg/sort_order.h index de4abba..6e49153 100644 --- a/src/iceberg/sort_order.h +++ b/src/iceberg/sort_order.h @@ -55,10 +55,6 @@ class ICEBERG_EXPORT SortOrder : public util::Formattable { return lhs.Equals(rhs); } - friend bool operator!=(const SortOrder& lhs, const SortOrder& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two sort orders for equality. bool Equals(const SortOrder& other) const; diff --git a/src/iceberg/statistics_file.h b/src/iceberg/statistics_file.h index 5bdc1c1..7ec01d4 100644 --- a/src/iceberg/statistics_file.h +++ b/src/iceberg/statistics_file.h @@ -50,11 +50,6 @@ struct ICEBERG_EXPORT BlobMetadata { lhs.source_snapshot_sequence_number == rhs.source_snapshot_sequence_number && lhs.fields == rhs.fields && lhs.properties == rhs.properties; } - - /// \brief Compare two BlobMetadatas for inequality. - friend bool operator!=(const BlobMetadata& lhs, const BlobMetadata& rhs) { - return !(lhs == rhs); - } }; /// \brief Represents a statistics file in the Puffin format @@ -77,11 +72,6 @@ struct ICEBERG_EXPORT StatisticsFile { lhs.file_footer_size_in_bytes == rhs.file_footer_size_in_bytes && lhs.blob_metadata == rhs.blob_metadata; } - - /// \brief Compare two StatisticsFiles for inequality. - friend bool operator!=(const StatisticsFile& lhs, const StatisticsFile& rhs) { - return !(lhs == rhs); - } }; /// \brief Represents a partition statistics file @@ -100,12 +90,6 @@ struct ICEBERG_EXPORT PartitionStatisticsFile { return lhs.snapshot_id == rhs.snapshot_id && lhs.path == rhs.path && lhs.file_size_in_bytes == rhs.file_size_in_bytes; } - - /// \brief Compare two PartitionStatisticsFiles for inequality. - friend bool operator!=(const PartitionStatisticsFile& lhs, - const PartitionStatisticsFile& rhs) { - return !(lhs == rhs); - } }; /// \brief Returns a string representation of a BlobMetadata diff --git a/src/iceberg/table_metadata.h b/src/iceberg/table_metadata.h index 9c7f37d..ff81e29 100644 --- a/src/iceberg/table_metadata.h +++ b/src/iceberg/table_metadata.h @@ -44,10 +44,6 @@ struct ICEBERG_EXPORT SnapshotLogEntry { friend bool operator==(const SnapshotLogEntry& lhs, const SnapshotLogEntry& rhs) { return lhs.timestamp_ms == rhs.timestamp_ms && lhs.snapshot_id == rhs.snapshot_id; } - - friend bool operator!=(const SnapshotLogEntry& lhs, const SnapshotLogEntry& rhs) { - return !(lhs == rhs); - } }; /// \brief Represents a metadata log entry @@ -60,10 +56,6 @@ struct ICEBERG_EXPORT MetadataLogEntry { friend bool operator==(const MetadataLogEntry& lhs, const MetadataLogEntry& rhs) { return lhs.timestamp_ms == rhs.timestamp_ms && lhs.metadata_file == rhs.metadata_file; } - - friend bool operator!=(const MetadataLogEntry& lhs, const MetadataLogEntry& rhs) { - return !(lhs == rhs); - } }; /// \brief Represents the metadata for an Iceberg table @@ -137,10 +129,6 @@ struct ICEBERG_EXPORT TableMetadata { Result<std::shared_ptr<SortOrder>> SortOrder() const; friend bool operator==(const TableMetadata& lhs, const TableMetadata& rhs); - - friend bool operator!=(const TableMetadata& lhs, const TableMetadata& rhs) { - return !(lhs == rhs); - } }; /// \brief Returns a string representation of a SnapshotLogEntry diff --git a/src/iceberg/transform.h b/src/iceberg/transform.h index 7ca4abc..f09f15b 100644 --- a/src/iceberg/transform.h +++ b/src/iceberg/transform.h @@ -135,11 +135,6 @@ class ICEBERG_EXPORT Transform : public util::Formattable { return lhs.Equals(rhs); } - /// \brief Inequality comparison. - friend bool operator!=(const Transform& lhs, const Transform& rhs) { - return !(lhs == rhs); - } - private: /// \brief Constructs a Transform of the specified type (for non-parametric types). /// \param transform_type The transform type (e.g., identity, year, day). @@ -188,10 +183,6 @@ class ICEBERG_EXPORT TransformFunction { return lhs.Equals(rhs); } - friend bool operator!=(const TransformFunction& lhs, const TransformFunction& rhs) { - return !(lhs == rhs); - } - private: /// \brief Compare two partition specs for equality. [[nodiscard]] virtual bool Equals(const TransformFunction& other) const; diff --git a/src/iceberg/type.cc b/src/iceberg/type.cc index e58cd0e..5186e9c 100644 --- a/src/iceberg/type.cc +++ b/src/iceberg/type.cc @@ -42,6 +42,7 @@ StructType::StructType(std::vector<SchemaField> fields) : fields_(std::move(fiel } TypeId StructType::type_id() const { return kTypeId; } + std::string StructType::ToString() const { std::string repr = "struct<\n"; for (const auto& field : fields_) { @@ -59,7 +60,7 @@ std::optional<std::reference_wrapper<const SchemaField>> StructType::GetFieldByI } std::optional<std::reference_wrapper<const SchemaField>> StructType::GetFieldByIndex( int32_t index) const { - if (index < 0 || index >= static_cast<int>(fields_.size())) { + if (index < 0 || index >= static_cast<int32_t>(fields_.size())) { return std::nullopt; } return fields_[index]; diff --git a/src/iceberg/type.h b/src/iceberg/type.h index 9bb8623..09e088f 100644 --- a/src/iceberg/type.h +++ b/src/iceberg/type.h @@ -55,9 +55,6 @@ class ICEBERG_EXPORT Type : public iceberg::util::Formattable { /// \brief Compare two types for equality. friend bool operator==(const Type& lhs, const Type& rhs) { return lhs.Equals(rhs); } - /// \brief Compare two types for inequality. - friend bool operator!=(const Type& lhs, const Type& rhs) { return !(lhs == rhs); } - protected: /// \brief Compare two types for equality. [[nodiscard]] virtual bool Equals(const Type& other) const = 0;