Skip to content

Commit

Permalink
using compare <=>
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDAlexander77 committed May 26, 2020
1 parent b34bef2 commit e102333
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 150 deletions.
156 changes: 7 additions & 149 deletions cpplib/core.h
Expand Up @@ -27,6 +27,7 @@
#include <chrono>
#include <thread>
#include <future>
#include <compare>

namespace js
{
Expand Down Expand Up @@ -1006,73 +1007,13 @@ struct number
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
friend bool operator!=(const number_t value, N n)
{
return value._value != static_cast<V>(n);
}

template <typename N = void> requires ArithmeticOrEnum<N>
friend bool operator!=(N n, const number_t value)
{
return static_cast<V>(n) != value._value;
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
friend bool operator<(const number_t value, N n)
{
return value._value < static_cast<V>(n);
}

template <typename N = void> requires ArithmeticOrEnum<N>
friend bool operator<(N n, const number_t value)
{
return static_cast<V>(n) < value._value;
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
friend bool operator<=(const number_t value, N n)
{
return value._value <= static_cast<V>(n);
}

template <typename N = void> requires ArithmeticOrEnum<N>
friend bool operator<=(N n, const number_t value)
{
return static_cast<V>(n) <= value._value;
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
friend bool operator>(const number_t value, N n)
{
return value._value > static_cast<V>(n);
}

template <typename N = void> requires ArithmeticOrEnum<N>
friend bool operator>(N n, const number_t value)
{
return static_cast<V>(n) > value._value;
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
friend bool operator>=(const number_t value, N n)
{
return value._value >= static_cast<V>(n);
}

template <typename N = void> requires ArithmeticOrEnum<N>
friend bool operator>=(N n, const number_t value)
{
return static_cast<V>(n) >= value._value;
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
friend int operator<=>(const number_t value, N n)
friend std::partial_ordering operator<=>(const number_t value, N n)
{
return value._value <=> static_cast<V>(n);
}

template <typename N = void> requires ArithmeticOrEnum<N>
friend bool operator<=>(N n, const number_t value)
friend std::strong_ordering operator<=>(N n, const number_t value)
{
return static_cast<V>(n) <=> value._value;
}
Expand Down Expand Up @@ -3083,109 +3024,26 @@ struct any
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
bool operator>(N n)
{
switch (get_type())
{
case anyTypeId::number_type:
return number_ref() > n;
}

throw "not implemented";
}

any operator>(any t)
{
switch (get_type())
{
case anyTypeId::number_type:
switch (t.get_type())
{
case anyTypeId::number_type:
return any(number_ref() > t.number_ref());
}
break;
}

throw "not implemented";
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
bool operator>=(N n)
{
switch (get_type())
{
case anyTypeId::number_type:
return number_ref() >= n;
}

throw "not implemented";
}

any operator>=(any t)
{
switch (get_type())
{
case anyTypeId::number_type:
switch (t.get_type())
{
case anyTypeId::number_type:
return any(number_ref() >= t.number_ref());
}
break;
}

throw "not implemented";
}

template <typename N = void> requires ArithmeticOrEnumOrNumber<N>
bool operator<(N n)
{
switch (get_type())
{
case anyTypeId::number_type:
return number_ref() < n;
}

throw "not implemented";
}

any operator<(any t)
{
switch (get_type())
{
case anyTypeId::number_type:
switch (t.get_type())
{
case anyTypeId::number_type:
return any(number_ref() < t.number_ref());
}
break;
}

throw "not implemented";
}

bool operator<=(js::number n)
std::strong_ordering operator<=>(N n)
{
switch (get_type())
{
case anyTypeId::number_type:
return number_ref() <= n;
return number_ref() <=> n;
}

throw "not implemented";
}

any operator<=(any t)
std::partial_ordering operator<=>(any t)
{
switch (get_type())
{
case anyTypeId::number_type:
switch (t.get_type())
{
case anyTypeId::number_type:
return any(number_ref() <= t.number_ref());
return number_ref() <=> t.number_ref();
}
break;
}
Expand Down
3 changes: 2 additions & 1 deletion typescript2cxx.code-workspace
Expand Up @@ -92,7 +92,8 @@
"mutex": "cpp",
"ratio": "cpp",
"xthread": "cpp",
"cinttypes": "cpp"
"cinttypes": "cpp",
"compare": "cpp"
}
}
}

0 comments on commit e102333

Please sign in to comment.