Given two strings a
and b
, sometimes I want to determine which one of the three statements: a < b
, a == b
or a > b
is true.
In a language like C or C++, I will get an int value v
after one invoking of the corresponding function or method. Then I can determine which of the above statements is true by examining whether v < 0
, v == 0
or v > 0
.
But in Go I have to do at least two comparisons (e.g. first test a < b
then test a == b
) to find out which one of the three statements is true.
My question is that is there a way in Go so that I can just do a single comparison?
It turns out that this feature is called three way comparison.