mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 10:35:50 +00:00
Simplify code using if constexpr:
Also simplify msig construction
This commit is contained in:
@@ -129,14 +129,11 @@ class FeatureBitset
|
||||
{
|
||||
using base = std::bitset<detail::FeatureCollections::numFeatures()>;
|
||||
|
||||
void initFromFeatures()
|
||||
{
|
||||
}
|
||||
|
||||
template<class... Fs>
|
||||
void initFromFeatures(uint256 const& f, Fs&&... fs)
|
||||
{
|
||||
set(f);
|
||||
if constexpr (sizeof...(fs) > 0)
|
||||
initFromFeatures(std::forward<Fs>(fs)...);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,33 +83,23 @@ stpath_append_one (STPath& st,
|
||||
boost::none, book.currency, book.account }));
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
stpath_append (STPath& st)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
void
|
||||
stpath_append (STPath& st,
|
||||
T const& t, Args const&... args)
|
||||
{
|
||||
stpath_append_one(st, t);
|
||||
if constexpr (sizeof...(args) > 0)
|
||||
stpath_append(st, args...);
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
stpathset_append (STPathSet& st)
|
||||
{
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
void
|
||||
stpathset_append(STPathSet& st,
|
||||
STPath const& p, Args const&... args)
|
||||
{
|
||||
st.push_back(p);
|
||||
if constexpr (sizeof...(args) > 0)
|
||||
stpathset_append(st, args...);
|
||||
}
|
||||
|
||||
|
||||
@@ -548,14 +548,6 @@ private:
|
||||
STAmount const& amount,
|
||||
Account const& account);
|
||||
|
||||
// If you get an error here it means
|
||||
// you're calling fund with no accounts
|
||||
inline
|
||||
void
|
||||
fund (STAmount const&)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
fund_arg (STAmount const& amount,
|
||||
Account const& account)
|
||||
@@ -605,7 +597,8 @@ public:
|
||||
Arg const& arg, Args const&... args)
|
||||
{
|
||||
fund_arg (amount, arg);
|
||||
fund (amount, args...);
|
||||
if constexpr (sizeof...(args) > 0)
|
||||
fund(amount, args...);
|
||||
}
|
||||
|
||||
/** Establish trust lines.
|
||||
|
||||
@@ -69,9 +69,8 @@ public:
|
||||
Path& push_back (STPathElement const& pe);
|
||||
Json::Value json () const;
|
||||
private:
|
||||
Path& addHelper (){return *this;}
|
||||
template <class First, class... Rest>
|
||||
Path& addHelper (First&& first, Rest&&... rest);
|
||||
void addHelper (First&& first, Rest&&... rest);
|
||||
};
|
||||
|
||||
inline Path& Path::push_back (STPathElement const& pe)
|
||||
@@ -95,10 +94,11 @@ Path& Path::push_back (jtx::Account const& account)
|
||||
}
|
||||
|
||||
template <class First, class... Rest>
|
||||
Path& Path::addHelper (First&& first, Rest&&... rest)
|
||||
void Path::addHelper (First&& first, Rest&&... rest)
|
||||
{
|
||||
push_back (std::forward<First> (first));
|
||||
return addHelper (std::forward<Rest> (rest)...);
|
||||
if constexpr (sizeof...(rest) > 0)
|
||||
addHelper(std::forward<Rest>(rest)...);
|
||||
}
|
||||
|
||||
inline
|
||||
@@ -130,15 +130,12 @@ public:
|
||||
return v;
|
||||
}
|
||||
private:
|
||||
PathSet& addHelper ()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
template <class First, class... Rest>
|
||||
PathSet& addHelper (First first, Rest... rest)
|
||||
void addHelper (First first, Rest... rest)
|
||||
{
|
||||
paths.emplace_back (std::move (first.path));
|
||||
return addHelper (std::move (rest)...);
|
||||
if constexpr (sizeof...(rest) > 0)
|
||||
addHelper(std::move(rest)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -53,12 +53,6 @@ protected:
|
||||
std::uint32_t mask_;
|
||||
|
||||
private:
|
||||
inline
|
||||
void
|
||||
set_args()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
set_args (std::uint32_t flag)
|
||||
{
|
||||
@@ -85,7 +79,9 @@ private:
|
||||
set_args (std::uint32_t flag,
|
||||
Args... args)
|
||||
{
|
||||
set_args(flag, args...);
|
||||
set_args(flag);
|
||||
if constexpr (sizeof...(args))
|
||||
set_args(args...);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -96,48 +96,14 @@ public:
|
||||
msig (std::vector<Reg> signers_);
|
||||
|
||||
template <class AccountType, class... Accounts>
|
||||
msig (AccountType&& a0, Accounts&&... aN)
|
||||
: msig(make_vector(
|
||||
std::forward<AccountType>(a0),
|
||||
std::forward<Accounts>(aN)...))
|
||||
explicit msig(AccountType&& a0, Accounts&&... aN)
|
||||
: msig{std::vector<Reg>{std::forward<AccountType>(a0),
|
||||
std::forward<Accounts>(aN)...}}
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
operator()(Env&, JTx& jt) const;
|
||||
|
||||
private:
|
||||
template <class AccountType>
|
||||
static
|
||||
void
|
||||
helper (std::vector<Reg>& v,
|
||||
AccountType&& account)
|
||||
{
|
||||
v.emplace_back(std::forward<
|
||||
Reg>(account));
|
||||
}
|
||||
|
||||
template <class AccountType, class... Accounts>
|
||||
static
|
||||
void
|
||||
helper (std::vector<Reg>& v,
|
||||
AccountType&& a0, Accounts&&... aN)
|
||||
{
|
||||
helper(v, std::forward<AccountType>(a0));
|
||||
helper(v, std::forward<Accounts>(aN)...);
|
||||
}
|
||||
|
||||
template <class... Accounts>
|
||||
static
|
||||
std::vector<Reg>
|
||||
make_vector(Accounts&&... signers)
|
||||
{
|
||||
std::vector<Reg> v;
|
||||
v.reserve(sizeof...(signers));
|
||||
helper(v, std::forward<
|
||||
Accounts>(signers)...);
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -91,12 +91,6 @@ private:
|
||||
void
|
||||
append_one(BookSpec const& book);
|
||||
|
||||
inline
|
||||
void
|
||||
append()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
void
|
||||
append (T const& t, Args const&... args);
|
||||
@@ -114,6 +108,7 @@ void
|
||||
path::append (T const& t, Args const&... args)
|
||||
{
|
||||
append_one(t);
|
||||
if constexpr (sizeof...(args) > 0)
|
||||
append(args...);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,6 @@ namespace jtx {
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline
|
||||
void
|
||||
require_args (requires_t& vec)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Cond, class... Args>
|
||||
inline
|
||||
void
|
||||
@@ -43,6 +37,7 @@ require_args (requires_t& vec,
|
||||
Cond const& cond, Args const&... args)
|
||||
{
|
||||
vec.push_back(cond);
|
||||
if constexpr (sizeof...(args) > 0)
|
||||
require_args(vec, args...);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,13 +64,6 @@ create_arg (boost::optional<Account>&,
|
||||
opt = value;
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
create_args (boost::optional<Account>&,
|
||||
boost::optional<std::uint32_t>&)
|
||||
{
|
||||
}
|
||||
|
||||
template<class Arg, class... Args>
|
||||
void
|
||||
create_args(boost::optional<Account>& account_opt,
|
||||
@@ -78,6 +71,7 @@ create_args(boost::optional<Account>& account_opt,
|
||||
Arg const& arg, Args const&... args)
|
||||
{
|
||||
create_arg(account_opt, expire_opt, arg);
|
||||
if constexpr (sizeof...(args))
|
||||
create_args(account_opt, expire_opt, args...);
|
||||
}
|
||||
|
||||
@@ -91,6 +85,7 @@ create (Account const& account,
|
||||
{
|
||||
boost::optional<Account> target;
|
||||
boost::optional<std::uint32_t> expire;
|
||||
if constexpr (sizeof...(args) > 0)
|
||||
detail::create_args(target, expire, args...);
|
||||
return detail::create(
|
||||
account, target, expire);
|
||||
|
||||
Reference in New Issue
Block a user