Skip to content

Commit

Permalink
Fix linux compile
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jan 2, 2024
1 parent 0dfbf2d commit d6123da
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
45 changes: 34 additions & 11 deletions src/ripple/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ class Asset
return *this;
}

asset_type const&
asset_type constexpr const&
asset() const
{
return asset_;
}

bool
bool constexpr
isCFT() const
{
return std::holds_alternative<CFT>(asset_);
}
bool
bool constexpr
isCurrency() const
{
return std::holds_alternative<Currency>(asset_);
}
bool
bool constexpr
isXRP() const
{
return isCurrency() && ripple::isXRP(std::get<Currency>(asset_));
Expand Down Expand Up @@ -113,14 +113,20 @@ class Asset
return std::get_if<T>(asset_);
}

template <typename T>
requires(std::is_same_v<T, Currency> || std::is_same_v<T, CFT>) operator T
const &() const
operator Currency const&() const
{
assert(std::holds_alternative<T>(asset_));
if (!std::holds_alternative<T>(asset_))
Throw<std::logic_error>("Invalid Asset cast");
return std::get<T>(asset_);
assert(std::holds_alternative<Currency>(asset_));
if (!std::holds_alternative<Currency>(asset_))
Throw<std::logic_error>("Invalid Currency cast");
return std::get<Currency>(asset_);
}

operator CFT const&() const
{
assert(std::holds_alternative<CFT>(asset_));
if (!std::holds_alternative<CFT>(asset_))
Throw<std::logic_error>("Invalid CFT cast");
return std::get<CFT>(asset_);
}

friend bool
Expand Down Expand Up @@ -169,6 +175,23 @@ class Asset
{
return !(a1 < a2);
}
friend inline constexpr std::weak_ordering
operator<=>(Asset const& lhs, Asset const& rhs)
{
assert(lhs.isCurrency() == rhs.isCurrency());
if (lhs.isCurrency() != rhs.isCurrency())
Throw<std::logic_error>("Invalid Asset comparison");
if (lhs.isCurrency())
return std::get<Currency>(lhs.asset_) <=>
std::get<Currency>(rhs.asset_);
if (auto const c{
std::get<CFT>(lhs.asset_).second <=>
std::get<CFT>(rhs.asset_).second};
c != 0)
return c;
return std::get<CFT>(lhs.asset_).first <=>
std::get<CFT>(rhs.asset_).first;
}
friend std::string
to_string(Asset const& a)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/Book.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ operator==(Book const& lhs, Book const& rhs)

/** Strict weak ordering. */
/** @{ */
[[nodiscard]] inline std::weak_ordering
[[nodiscard]] inline constexpr std::weak_ordering
operator<=>(Book const& lhs, Book const& rhs)
{
if (auto const c{lhs.in <=> rhs.in}; c != 0)
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/Issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Issue
return *this;
}

Asset const&
Asset constexpr const&
asset() const
{
return asset_;
Expand Down Expand Up @@ -185,7 +185,7 @@ operator==(Issue const& lhs, Issue const& rhs)

/** Strict weak ordering. */
/** @{ */
[[nodiscard]] inline std::weak_ordering
[[nodiscard]] inline constexpr std::weak_ordering
operator<=>(Issue const& lhs, Issue const& rhs)
{
if (auto const c{lhs.asset().asset() <=> rhs.asset().asset()}; c != 0)
Expand Down

0 comments on commit d6123da

Please sign in to comment.