Код: Выделить всё
#include
#include
class FooString {
public:
FooString& operator=(const FooString& src) {
if (this != &src) {
m_data = src.m_data;
}
return *this;
}
FooString& operator=(FooString&& src) {
m_data = std::move(src.m_data);
return *this;
}
FooString& operator=(const char* value) {
m_data = value;
return *this;
}
FooString& operator=(std::string value) {
m_data = std::move(value);
return *this;
}
bool operator==(const FooString& value) const {
return (0 == compare(m_data, value.m_data));
}
bool operator!=(const FooString& value) const{
printf("__%d__\n", __LINE__);
return (compare(m_data, value.m_data));
}
bool operator= compare(m_data, value.m_data));
}
bool operator>=(const FooString& value) const{
printf("__%d__\n", __LINE__);
return (0 (const FooString& value) const {
printf("__%d__\n", __LINE__);
return (0 < compare(m_data, value.m_data));
}
operator const char*() const {
printf("__%d__\n", __LINE__); // this function gets called with c++20
return m_data.c_str();
}
const std::string& str() const {
return m_data;
}
const char* c_str() const {
return m_data.c_str();
}
protected:
virtual int compare(std::string_view str1, std::string_view str2) const {
return str1.compare(str2);
}
private:
std::string m_data;
};
int main()
{
FooString str1;
str1 = "test1";
FooString str2;
str2 = "test1";
std::tuple k1(std::tie(str1));
std::tuple k2(std::tie(str2));
if (k1 < k2) {
printf("k1 < k2\n");
} else {
printf("k1 >= k2\n");
}
return 0;
}
Я немного ищу и узнал, что это связано с C ++ 20 20 навязать полностью упорядочение для ссылки на тупе. Я думал, что мы предоставили операторам полностью заказа! =, == и т. Д. Нет? Или почему перегруженные операторы затенены оператором конверсии Const char*? Теперь спортивный адрес с адресом указателя с C ++ 20 зависит от упорядочения машины ... < /p>
Любые идеи приветствуются. Также это сломанная функция от C ++ 20, no?
Подробнее здесь: https://stackoverflow.com/questions/797 ... -reference
Мобильная версия