Member spaceship operator with an arbitrary argument type - is it supported?

64 views Asked by At

Why does the following code not compile (no match for 'operator==')? Is this syntax allowed? If yes, how to fix the code? If not, where does the standard say that?

#include <vector>

template <typename T>
struct VectorWrapper {
    using ValueType = std::vector<T>;

    constexpr auto operator<=>(const VectorWrapper&) const noexcept = default;
    constexpr auto operator<=>(const ValueType& otherValue) const noexcept {
        return v <=> otherValue;
    }

    ValueType v;
};

bool f() {
    VectorWrapper<int> v;
    return v == std::vector {0};
}

https://godbolt.org/z/1jh9z7G7E

0

There are 0 answers