Write improved forAllApiVersions used in NetworkOPs (#4833)

This commit is contained in:
Bronek Kozicki
2024-03-23 04:28:16 +09:00
committed by GitHub
parent 47c8cc24f4
commit 6edf03c152
26 changed files with 1724 additions and 689 deletions

View File

@@ -758,40 +758,6 @@ Env::rpc(std::string const& cmd, Args&&... args)
std::forward<Args>(args)...);
}
/**
* The SingleVersionedTestCallable concept checks for a callable that takes
* an unsigned integer as its argument and returns void.
*/
template <class T>
concept SingleVersionedTestCallable = requires(T callable, unsigned int version)
{
{
callable(version)
}
->std::same_as<void>;
};
/**
* The VersionedTestCallable concept checks if a set of callables all satisfy
* the SingleVersionedTestCallable concept. This allows forAllApiVersions to
* accept any number of functions. It executes a set of provided functions over
* a range of versions from RPC::apiMinimumSupportedVersion to
* RPC::apiBetaVersion. This is useful for running a series of tests or
* operations that need to be performed on multiple versions of an API.
*/
template <class... T>
concept VersionedTestCallable = (... && SingleVersionedTestCallable<T>);
void
forAllApiVersions(VersionedTestCallable auto... testCallable)
{
for (auto testVersion = RPC::apiMinimumSupportedVersion;
testVersion <= RPC::apiMaximumValidVersion;
++testVersion)
{
(..., testCallable(testVersion));
}
}
} // namespace jtx
} // namespace test
} // namespace ripple