8000 Add operator<=> and remove operator< operator and compareTo function (issue 155) by FrankYFTang · Pull Request #160 · unicode-org/inflection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add operator<=> and remove operator< operator and compareTo function (issue 155) #160

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions inflection/src/inflection/dialog/DisplayValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ bool DisplayValue::operator==(const DisplayValue& o) const
return displayString == o.displayString && constraintMap == o.constraintMap;
}

bool DisplayValue::operator!=(const DisplayValue& o) const
{
return !operator==(o);
}

std::size_t DisplayValue::operator()(const DisplayValue& displayValue) const noexcept
{
return std::hash<std::u16string>()(displayValue.displayString);
Expand Down
8 changes: 1 addition & 7 deletions inflection/src/inflection/dialog/DisplayValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,10 @@ class INFLECTION_CLASS_API inflection::dialog::DisplayValue
* @return True if the two display value are the same, false otherwise.
*/
bool operator==(const DisplayValue& o) const;
/**
* Equivalent to the inverse of operator==.
* @param o The display value object to be compared with this.
* @return True if the two display value are not the same, false otherwise.
*/
bool operator!=(const DisplayValue& o) const;
/**
* Generates a hash code compatible with std::hash for the displayValue.
* @param displayValue The display value object to generate the hash value.
* @return the hash code compatible with std::hash for the displayValue.
* @return the hash code compatible with std::hash for the displayValue.
*/
std::size_t operator()(const DisplayValue& displayValue) const noexcept;

Expand Down
4 changes: 2 additions & 2 deletions inflection/src/inflection/dialog/NumberConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ std::size_t NumberConcept::operator()(const NumberConcept& o) const noexcept
return o.longValue();
}

bool NumberConcept::operator<(const NumberConcept& o) const
std::partial_ordering NumberConcept::operator<=>(const NumberConcept& o) const
{
return doubleValue() < o.doubleValue();
return doubleValue() <=> o.doubleValue();
}

int64_t NumberConcept::longValue() const
Expand Down
5 changes: 3 additions & 2 deletions inflection/src/inflection/dialog/NumberConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ class INFLECTION_CLASS_API inflection::dialog::NumberConcept
std::size_t operator()(const NumberConcept& o) const noexcept;

/**
* Returns true when this NumberConcept is less than the other NumberConcept being compared.
* String compares the order of the NumberConcept objects.
* Formatting differences are not considered.
* @param o The object to be compared with this.
*/
bool operator<(const NumberConcept& o) const;
std::partial_ordering operator<=>(const NumberConcept& o) const;

/**
* Returns the value of this NumberConcept as a 64-bit number.
Expand Down
5 changes: 0 additions & 5 deletions inflection/src/inflection/dialog/PronounConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,4 @@ bool PronounConcept::operator==(const PronounConcept& other) const
constraints == other.constraints;
}

bool PronounConcept::operator!=(const PronounConcept& other) const
{
return !(*this == other);
}

} // namespace inflection::dialog
5 changes: 0 additions & 5 deletions inflection/src/inflection/dialog/PronounConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ class INFLECTION_CLASS_API inflection::dialog::PronounConcept
*/
bool operator==(const PronounConcept& o) const;

/**
* Equivalent to the inverse of operator==
*/
bool operator!=(const PronounConcept& o) const;

/**
* Constructs a new PronounConcept based on custom pronouns. Any unspecified pronouns will use the language's default pronouns.
* @param model The SemanticFeatureModel for the language
Expand Down
5 changes: 0 additions & 5 deletions inflection/src/inflection/dialog/SemanticConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,4 @@ bool SemanticConcept::operator==(const SemanticConcept& other) const
return getModel() == other.getModel() && semantic == other.semantic && defaultToSemantic == other.defaultToSemantic && getSpeakFeature() == other.getSpeakFeature() && constraints == other.constraints;
}

bool SemanticConcept::operator!=(const SemanticConcept& other) const
{
return !(*this == other);
}

} // namespace inflection::dialog
5 changes: 0 additions & 5 deletions inflection/src/inflection/dialog/SemanticConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ class INFLECTION_CLASS_API inflection::dialog::SemanticConcept
*/
bool operator==(const SemanticConcept& o) const;

/**
* Equivalent to the inverse of operator==
*/
bool operator!=(const SemanticConcept& o) const;

/**
* Constructs a new SemanticConcept. A SemanticFeatureModel is required, as it will enforce the locale and store display data.
*/
Expand Down
6 changes: 3 additions & 3 deletions 10000 inflection/src/inflection/dialog/SemanticFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ bool SemanticFeature::isAliased() const
return aliased;
}

bool SemanticFeature::operator<(const SemanticFeature& other) const
std::weak_ordering SemanticFeature::operator<=>(const SemanticFeature& other) const
{
return name < other.name;
return name <=> other.name;
}

bool SemanticFeature::operator==(const SemanticFeature& other) const
{
return name == other.name;
return (*this <=> other) == 0;
}

} // namespace inflection::dialog
5 changes: 4 additions & 1 deletion inflection/src/inflection/dialog/SemanticFeature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ class INFLECTION_CLASS_API inflection::dialog::SemanticFeature
* aliased without specifying the name.
*/
virtual bool isAliased() const;
bool operator<(const SemanticFeature& other) const;
/**
* Returns true when both objects refer to the same semantic feature, with the same
* name.
* @param other The semantic feature object to be compared with this.
* @return True if the two semantic feature are the same, false otherwise.
*/
bool operator==(const SemanticFeature& other) const;
/**
* @param other The semantic feature object to be compared with this.
*/
std::weak_ordering operator<=>(const SemanticFeature& other) const;

/**
* Construct the SemanticFeature from the name, type, bounded values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ bool SemanticFeatureModel_DisplayData::operator==(const SemanticFeatureModel_Dis
return allValues == o.allValues;
}

bool SemanticFeatureModel_DisplayData::operator!=(const SemanticFeatureModel_DisplayData& o) const
{
return !operator==(o);
}

} // namespace inflection::dialog
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ class INFLECTION_CLASS_API inflection::dialog::SemanticFeatureModel_DisplayData
* @return True if the two display data are the same, false otherwise.
*/
bool operator==(const SemanticFeatureModel_DisplayData& o) const;
/**
* Equivalent to the inverse of operator==.
* @param o The display data object to be compared with this.
* @return True if the two display data are not the same, false otherwise.
*/
bool operator!=(const SemanticFeatureModel_DisplayData& o) const;

/**
* Construct the display data with all of the known display values. Typically the first display value is shown that matches the desired semantic features.
Expand Down
5 changes: 0 additions & 5 deletions inflection/src/inflection/dialog/SpeakableString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ bool SpeakableString::operator==(const SpeakableString& o) const
return this->print == o.print && ((this->speak == nullptr && o.speak == nullptr) || (this->speak != nullptr && o.speak != nullptr && *this->speak == *o.speak));
}

bool SpeakableString::operator!=(const SpeakableString& o) const
{
return !(*this == o);
}

SpeakableString SpeakableString::operator+(const SpeakableString& o) const
{
::std::u16string print(this->print);
Expand Down
6 changes: 0 additions & 6 deletions inflection/src/inflection/dialog/SpeakableString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ class INFLECTION_CLASS_API inflection::dialog::SpeakableString
* @return True if the two speakable string are the same, false otherwise.
*/
bool operator==(const ::inflection::dialog::SpeakableString& o) const;
/**
* Equivalent to the inverse of operator==.
* @param o The speakable string object to be compared with this.
* @return True if the two display value are not the same, false otherwise.
*/
bool operator!=(const ::inflection::dialog::SpeakableString& o) const;
/**
* Create a new speakable string by appened other to this.
* @param o the speakable string to be appened with this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ DictionaryKeyIterator::operator==(const DictionaryKeyIterator& rhs) const {
return *trieIterator == *rhs.trieIterator;
}

bool
DictionaryKeyIterator::operator!=(const DictionaryKeyIterator& rhs) const {
return !(*this == rhs);
}

DictionaryKeyIterator
DictionaryKeyIterator::begin() const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class INFLECTION_CLASS_API inflection::dictionary::DictionaryKeyIterator
* Return true when this is equal to the other iterator.
*/
bool operator==(const DictionaryKeyIterator& rhs) const;
/**
* Return false when this is equal to the other iterator.
*/
bool operator!=(const DictionaryKeyIterator& rhs) const;

/**
* The first word in the dictionary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ int32_t Inflector_InflectionPattern::numInflections() const
return numOfInflections;
}

bool Inflector_InflectionPattern::operator<(const Inflector_InflectionPattern& other) const {
return (getIdentifier() < other.getIdentifier());
std::weak_ordering Inflector_InflectionPattern::operator<=>(const Inflector_InflectionPattern& other) const {
return getIdentifier() <=> other.getIdentifier();
}

int64_t Inflector_InflectionPattern::firstContainingPartOfSpeech(const ::std::vector<int64_t> &partOfSpeechList) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class inflection::dictionary::Inflector_InflectionPattern final
int64_t firstContainingPartOfSpeech(const ::std::vector<int64_t> &partOfSpeech) const;
int64_t getPartsOfSpeech() const;

bool operator<(const Inflector_InflectionPattern& other) const;
std::weak_ordering operator<=>(const Inflector_InflectionPattern& other) const;

private:
Inflector_InflectionPattern() = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class inflection::dictionary::metadata::MarisaTrieIterator
MarisaTrieIterator<T>& operator++();

bool operator==(const MarisaTrieIterator<T>& rhs) const;
bool operator!=(const MarisaTrieIterator<T>& rhs) const;

MarisaTrieIterator<T> begin() const;
MarisaTrieIterator<T> end() const;
Expand Down Expand Up @@ -92,12 +91,6 @@ inflection::dictionary::metadata::MarisaTrieIterator<T>::operator==(const Marisa
return &trie == &rhs.trie && reachedEnd == rhs.reachedEnd && (reachedEnd || agent.key().id() == rhs.agent.key().id());
}

template <typename T>
bool
inflection::dictionary::metadata::MarisaTrieIterator<T>::operator!=(const MarisaTrieIterator& rhs) const {
return !(*this == rhs);
}

template <typename T>
inflection::dictionary::metadata::MarisaTrieIterator<T>
inflection::dictionary::metadata::MarisaTrieIterator<T>::begin() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ std::multimap<std::u16string, std::u16string> LanguageGrammarFeatures_GrammarCat
return {};
}

int32_t LanguageGrammarFeatures_GrammarCategory::compareTo(const LanguageGrammarFeatures_GrammarCategory& o) const
std::weak_ordering LanguageGrammarFeatures_GrammarCategory::operator<=>(const LanguageGrammarFeatures_GrammarCategory& other) const
{
return name.compare(o.name);
}

bool LanguageGrammarFeatures_GrammarCategory::operator<(const LanguageGrammarFeatures_GrammarCategory& other) const
{
return (name.compare(other.name)) < 0;
return name <=> other.name;
}

} // namespace inflection::lang::features
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,10 @@ class INFLECTION_CLASS_API inflection::lang::features::LanguageGrammarFeatures_G
std::multimap<std::u16string, std::u16string> getGrammemeDependenciesForValue(std::u16string_view grammemeValue) const;

/**
* Compares the name of this grammar category with the other..
* @param other The grammar category object to be compared with this.
* @return the value 0 if the name of the argument other is equal to the name of this; a value -1 if the name
* of this is lexicographically less than the name of the argument other; and a value 1 if the name
* of this is lexicographically greater than the name of the argument other.
* String compares the order of the name.
* @param other The object to be compared with this.
*/
virtual int32_t compareTo(const LanguageGrammarFeatures_GrammarCategory& other) const;
bool operator<(const LanguageGrammarFeatures_GrammarCategory& other) const;

std::weak_ordering operator<=>(const LanguageGrammarFeatures_GrammarCategory& other) const;

private: /* package */
LanguageGrammarFeatures_GrammarCategory(const std::u16string& name, const std::set<std::u16string>& values,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ std::vector<LanguageGrammarFeatures_Feature> LanguageGrammarFeatures_GrammarFeat
return values;
}

int32_t LanguageGrammarFeatures_GrammarFeatures::compareTo(const LanguageGrammarFeatures_GrammarFeatures& o) const
std::weak_ordering LanguageGrammarFeatures_GrammarFeatures::operator<=>(const LanguageGrammarFeatures_GrammarFeatures& other) const
{
return name.compare(o.name);
}

bool LanguageGrammarFeatures_GrammarFeatures::operator<(const LanguageGrammarFeatures_GrammarFeatures& other) const
{
return (name.compare(other.name)) < 0;
return name <=> other.name;
}

} // namespace inflection::lang::features
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ class INFLECTION_CLASS_API inflection::lang::features::LanguageGrammarFeatures_G
*/
std::vector<::inflection::lang::features::LanguageGrammarFeatures_Feature> getValues() const;
/**
* Compares the name of this grammar features with the other..
* @param other The grammar features object to be compared with this.
* @return the value 0 if the name of the argument other is equal to the name of this; a value -1 if the name
* of this is lexicographically less than the name of the argument other; and a value 1 if the name
* of this is lexicographically greater than the name of the argument other.
* String compares the order of the name.
* @param other The object to be compared with this.
*/
virtual int32_t compareTo(const LanguageGrammarFeatures_GrammarFeatures& other) const;
bool operator<(const LanguageGrammarFeatures_GrammarFeatures& other) const;
std::weak_ordering operator<=>(const LanguageGrammarFeatures_GrammarFeatures& other) const;

protected: /* package */
/**
Expand Down
5 changes: 0 additions & 5 deletions inflection/src/inflection/tokenizer/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ bool Token::operator==(const Token& rhs) const
return getLength() == rhs.getLength() && isSignificant() == rhs.isSignificant() && isHead() == rhs.isHead() && isTail() == rhs.isTail() && isWhitespace() == rhs.isWhitespace() && getCleanValue() == rhs.getCleanValue() && getValue() == rhs.getValue();
}

bool Token::operator!=(const Token& rhs) const
{
return !(*this == rhs);
}

std::size_t Token::operator()(const Token& token) const noexcept
{
return std::hash<std::u16string>()(token.value);
Expand Down
7 changes: 0 additions & 7 deletions inflection/src/inflection/tokenizer/Token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ class INFLECTION_INTERNAL_API inflection::tokenizer::Token
* @return True if the two are the same, false otherwise.
*/
bool operator==(const ::inflection::tokenizer::Token& rhs) const;
/**
* Checks if the two Tokens are not the same.
*
* @param rhs Other Token being compared to.
* @return True if the two are not the same, false otherwise.
*/
bool operator!=(const ::inflection::tokenizer::Token& rhs) const;
/**
* Generates a unique hash of this Token.
*
Expand Down
6 changes: 0 additions & 6 deletions inflection/src/inflection/tokenizer/TokenChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ bool TokenChain::operator==(const TokenChain& rhs) const
return rightPointer == nullptr;
}

bool
TokenChain::operator!=(const TokenChain& rhs) const
{
return !(*this == rhs);
}

std::size_t TokenChain::operator()(const TokenChain& tokenChain) const noexcept
{
std::size_t hash = 0;
Expand Down
7 changes: 0 additions & 7 deletions inflection/src/inflection/tokenizer/TokenChain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class INFLECTION_INTERNAL_API inflection::tokenizer::TokenChain
* @return true if both TokenChains are equal.
*/
bool operator==(const inflection::tokenizer::TokenChain& rhs) const;
/**
* Returns true if both TokenChains are not equal.
*
* @param rhs The other TokenChain.
* @return true if both TokenChains are not equal.
*/
bool operator!=(const inflection::tokenizer::TokenChain& rhs) const;
/**
* Returns a unique <code>std::size_t</code> hash of the entire TokenChain. This hash is calculated by summing all the
* hashes of each Token in the TokenChain.
Expand Down
5 changes: 0 additions & 5 deletions inflection/src/inflection/tokenizer/TokenIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,4 @@ TokenIterator::operator==(const TokenIterator& rhs) const {
return token == rhs.token;
}

bool
TokenIterator::operator!=(const TokenIterator& rhs) const {
return !(*this == rhs);
}

} // namespace inflection
1 change: 0 additions & 1 deletion inflection/src/inflection/tokenizer/TokenIterator.hpp
56D6
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class INFLECTION_INTERNAL_API inflection::tokenizer::TokenIterator
TokenIterator operator--(int postDecrement);

bool operator==(const TokenIterator& rhs) const;
bool operator!=(const TokenIterator& rhs) const;

private:
const Token* token;
Expand Down
Loading
Loading
0