Skip to content

Commit

Permalink
Fix linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jul 17, 2024
1 parent 20721a8 commit eaca1da
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
75 changes: 39 additions & 36 deletions include/xrpl/protocol/STEitherAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,43 +127,37 @@ class STEitherAmount : public STBase, public CountedObject<STEitherAmount>
};

template <ValidAmountType T>
T const&
get(STEitherAmount const& amount)
decltype(auto)
get(auto&& amount)
{
if (std::holds_alternative<T>(amount.getValue()))
return std::get<T>(amount.getValue());
Throw<std::logic_error>("Incorrect type to STEitherAmount::get");
}

template <ValidAmountType T>
T&
get(STEitherAmount& amount)
{
if (std::holds_alternative<T>(amount.getValue()))
return std::get<T>(amount.getValue());
Throw<std::logic_error>("Incorrect type to STEitherAmount::get");
}

template <typename T>
std::optional<T>
get(std::optional<STEitherAmount> const& amount);

template <>
inline std::optional<STAmount>
get(std::optional<STEitherAmount> const& amount)
{
if (amount)
return get<STAmount>(*amount);
return std::nullopt;
}

template <>
inline std::optional<STMPTAmount>
get(std::optional<STEitherAmount> const& amount)
{
if (amount)
return get<STMPTAmount>(*amount);
return std::nullopt;
if constexpr (std::
is_same_v<std::decay_t<decltype(amount)>, STEitherAmount>)
{
if (std::holds_alternative<T>(amount.getValue()))
return std::get<T>(amount.getValue());
Throw<std::logic_error>("Invalid STEitherAmount conversion");
}
else if constexpr (std::is_same_v<
std::decay_t<decltype(amount)>,
std::optional<STEitherAmount>>)
{
static std::optional<T> t;
if (amount.has_value())
return std::make_optional(get<T>(*amount));
return t;
}
else if constexpr (std::is_convertible_v<
std::decay_t<decltype(amount)>,
STEitherAmount>)
{
T a = get<T>(amount.operator STEitherAmount());
return a;
}
else
{
bool const alwaysFalse = !std::is_same_v<T, T>;
static_assert(alwaysFalse, "Converting non-STEitherAmount");
}
}

STEitherAmount
Expand All @@ -178,6 +172,15 @@ amountFromJsonNoThrow(STAmount& result, Json::Value const& jvSource);
inline bool
operator==(STEitherAmount const& lhs, STEitherAmount const& rhs)
{
return std::visit(
[&]<typename T1, typename T2>(T1 const& a1, T2 const& a2) {
if constexpr (std::is_same_v<T1, T2>)
return a1 == a2;
else
return false;
},
lhs.getValue(),
rhs.getValue());
if (lhs.isIssue() == rhs.isIssue())
return lhs.getValue() == rhs.getValue();
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ class MPToken_test : public beast::unit_test::suite
env,
alice,
{.holders = {&bob},
.xrpHolders = acctReserve + get<STAmount>(XRP(1)).xrp()});
.xrpHolders =
acctReserve + get<STAmount>(XRP(1).value()).xrp()});
mptAlice1.create();

MPTTester mptAlice2(env, alice, {.fund = false});
Expand Down

0 comments on commit eaca1da

Please sign in to comment.