Require context in aggregators. (#10075)

This commit is contained in:
Jiaming Yuan
2024-02-28 03:12:42 +08:00
committed by GitHub
parent 761845f594
commit 5ac233280e
23 changed files with 190 additions and 144 deletions

View File

@@ -1,8 +1,10 @@
/**
* Copyright 2023, XGBoost Contributors
* Copyright 2023-2024, XGBoost Contributors
*/
#pragma once
#include <xgboost/logging.h>
#include <memory> // for unique_ptr
#include <sstream> // for stringstream
#include <stack> // for stack
@@ -160,10 +162,16 @@ struct Result {
// We don't have monad, a simple helper would do.
template <typename Fn>
Result operator<<(Result&& r, Fn&& fn) {
[[nodiscard]] Result operator<<(Result&& r, Fn&& fn) {
if (!r.OK()) {
return std::forward<Result>(r);
}
return fn();
}
inline void SafeColl(Result const& rc) {
if (!rc.OK()) {
LOG(FATAL) << rc.Report();
}
}
} // namespace xgboost::collective