spaceship-operator Questions
3
Solved
Consider the following piece of code:
struct B {
friend bool operator< (const B&, const B&);
friend bool operator==(const B&, const B&);
};
struct D : B {
friend std::strong_...
Hangman asked 18/6 at 13:37
1
Solved
C++20 allows users to specify different return types when defining operator <=>: std::partial_ordering, std::weak_ordering and std::strong_ordering. Does specifying them imply that correspond...
Anniceannie asked 17/3, 2023 at 17:10
6
Solved
While I was trying to learn about C++ operators, I stumbled upon the following table that listed a strange comparison operator. What does this <=> operator do?
Since 2017 cppreference.com up...
Zurkow asked 24/11, 2017 at 4:26
3
Solved
c++20 default comparison operator is a very convenient feature. But I find it less useful if the class has an empty base class.
The default operator<=> performs lexicographical comparison by...
Violoncellist asked 25/8, 2022 at 10:29
4
Solved
Why doesn't sort or the spaceship (flying saucer) operator (<=>) work on booleans in Ruby?
In "Is it possible to sort a list of objects depending on if the individual object's response to a method?", I discovered that the flying saucer doesn't work on booleans.
Consider:
Ruby 1.8.7:
...
Urban asked 11/2, 2013 at 16:13
10
Solved
I'm working on code written by a previous developer and in a query it says,
WHERE p.name <=> NULL
What does <=> mean in this query? Is it something equal to =? Or is it a syntax erro...
Sagamore asked 21/2, 2014 at 6:40
3
Ruby has something called a Combined Comparison or "Spaceship" Operator, it looks like this: <=>
It does the following:
a <=> b :=
if a < b then return -1
if a = b then return 0
...
Premonition asked 18/1, 2016 at 10:49
2
Solved
I've been reading a bit about C++20's consistent comparison (i.e. operator<=>) but couldn't understand what's the practical difference between std::strong_ordering and std::weak_ordering (sam...
Kossuth asked 3/7, 2018 at 17:55
1
Solved
None of the compilers I tried accept such code:
template <int ...a> bool foo() { return (a<=> ... <=>0); }
But for any other <=,>=,==,!=,<,> it compiles.
cppreference ...
Booker asked 6/8, 2021 at 14:37
5
Solved
#include <compare>
struct A
{
int n;
auto operator<=>(A const& other) const
{
if (n < other.n)
{
return std::strong_ordering::less;
}
else if (n > other.n)
{
retur...
Notebook asked 2/7, 2021 at 7:12
1
Solved
Does the new C++20 spaceship operator allow a concise way of expressing short-circuited multiple-criteria comparison? Something better than this:
const firstCriteriaComparisonResult = lhs.x <=&g...
Niels asked 18/5, 2021 at 4:29
4
Solved
#include <compare>
#include <iostream>
int main()
{
auto comp1 = 1.1 <=> 2.2;
auto comp2 = -1 <=> 1;
std::cout << typeid(comp1).name()<<"\n"<&l...
Featured asked 27/4, 2021 at 13:49
1
Solved
Consider the following two overload operator<=> for S:
#include <compare>
struct S {};
int operator<=>(S, int) { return 0; } #1
S operator<=>(S, S) { return {}; } #2
If I...
Bellybutton asked 17/3, 2021 at 13:49
2
Solved
Consider the following useless code:
struct S{
constexpr operator int() const { return 0; }
constexpr auto operator<=>(S) const { return *this; }
};
static_assert(S{} <= S{});
Clang an...
Tenpin asked 17/3, 2021 at 4:11
3
To my surprise, I ran into another snag like C++20 behaviour breaking existing code with equality operator?.
Consider a simple case-insensitive key type, to be used with, e.g., std::set or std::map...
Gabriello asked 5/3, 2021 at 17:49
1
Solved
The following code calls operator <=> twice, with arguments reversed. But why?
GCC 10.2 and clang 12 both seem to be using libstdc++-10, whose <tuple> does provide operator <=>, s...
Acinus asked 12/2, 2021 at 16:35
1
Solved
I'm trying to test my project in the latest Visual Studio and Clang versions. One of the errors that pops up is related to an ambiguous operator (with reversed parameter order). This does not seem ...
Bartlett asked 28/1, 2021 at 23:53
1
Solved
I ran into this while debugging this question.
I trimmed it down all the way to just using Boost Operators:
Compiler Explorer C++17 C++20
#include <boost/operators.hpp>
struct F : boost::to...
Mandarin asked 10/1, 2021 at 0:9
3
Solved
Some time ago I defined my first three-way comparison operator. It compared a single type and replaced multiple conventional operators. Great feature. Then I tried to implement a similar operator f...
Lascar asked 18/12, 2020 at 19:48
1
Solved
The valid values of std::strong_ordering are less, equal, equivalent, and greater. However, it appears that strong_ordering::equivalent and strong_ordering::equal are equal (i.e., interchangeable),...
Killer asked 18/12, 2020 at 20:45
1
Consider:
#include <compare>
template<class=void>
constexpr int f() { return 1; }
unsigned int x;
using T = decltype(x <=> f());
GCC and MSVC accept the declaration of T. Clang...
Signification asked 2/11, 2020 at 10:40
1
Solved
I have a finite volume library, strongly influenced by openfoam, which enables the solution to continuum mechanics problems to be written in C++ similarly as one
would in paper. For example, to sol...
Tamatamable asked 31/10, 2020 at 8:20
1
Solved
All the basic comparisons (<, <=, ==, !=, >=, >) have an associated function object (std::less, std::less_equal, std::equal_to, std::not_equal_to, std::greater_equal, std::greater).
Doe...
Geulincx asked 21/9, 2020 at 11:0
1
Solved
Given the example from cppreference on <=>, we can simplify the example code to:
struct person {
std::string name;
std::string surname;
auto operator <=> (const person& p) const...
Toughie asked 15/8, 2020 at 15:44
1
Solved
How does C++ treat floating-point NaN when doing space-ship comparison operations? We know that the usual compares always return false, so how does this change with NaN?
std::numeric_limits<doub...
Emden asked 30/6, 2020 at 0:7
1 Next >
© 2022 - 2024 — McMap. All rights reserved.