MCPcopy Create free account
hub / github.com/apache/arrow / Result

Class Result

cpp/src/arrow/result.h:99–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97/// ```
98template <class T>
99class [[nodiscard]] Result : public util::EqualityComparable<Result<T>> {
100 template <typename U>
101 friend class Result;
102
103 static_assert(!std::is_same<T, Status>::value,
104 "this assert indicates you have probably made a metaprogramming error");
105
106 public:
107 using ValueType = T;
108
109 /// Constructs a Result object that contains a non-OK status.
110 ///
111 /// This constructor is marked `explicit` to prevent attempts to `return {}`
112 /// from a function with a return type of, for example,
113 /// `Result<std::vector<int>>`. While `return {}` seems like it would return
114 /// an empty vector, it will actually invoke the default constructor of
115 /// Result.
116 explicit Result() noexcept // NOLINT(runtime/explicit)
117 : status_(internal::UninitializedResult()) {}
118
119 ~Result() noexcept { Destroy(); }
120
121 /// Constructs a Result object with the given non-OK Status object. All
122 /// calls to ValueOrDie() on this object will abort. The given `status` must
123 /// not be an OK status, otherwise this constructor will abort.
124 ///
125 /// This constructor is not declared explicit so that a function with a return
126 /// type of `Result<T>` can return a Status object, and the status will be
127 /// implicitly converted to the appropriate return type as a matter of
128 /// convenience.
129 ///
130 /// \param status The non-OK Status object to initialize to.
131 Result(const Status& status) noexcept // NOLINT(runtime/explicit)
132 : status_(status) {
133 if (ARROW_PREDICT_FALSE(status.ok())) {
134 internal::DieWithMessage(std::string("Constructed with a non-error status: ") +
135 status.ToString());
136 }
137 }
138
139 /// Constructs a Result object that contains `value`. The resulting object
140 /// is considered to have an OK status. The wrapped element can be accessed
141 /// with ValueOrDie().
142 ///
143 /// This constructor is made implicit so that a function with a return type of
144 /// `Result<T>` can return an object of type `U &&`, implicitly converting
145 /// it to a `Result<T>` object.
146 ///
147 /// Note that `T` must be implicitly constructible from `U`, and `U` must not
148 /// be a (cv-qualified) Status or Status-reference type. Due to C++
149 /// reference-collapsing rules and perfect-forwarding semantics, this
150 /// constructor matches invocations that pass `value` either as a const
151 /// reference or as an rvalue reference. Since Result needs to work for both
152 /// reference and rvalue-reference types, the constructor uses perfect
153 /// forwarding to avoid invalidating arguments that were passed by reference.
154 /// See http://thbecker.net/articles/rvalue_references/section_08.html for
155 /// additional details.
156 ///

Callers

nothing calls this directly

Calls 6

okFunction · 0.85
InvalidValueOrDieFunction · 0.85
ValueUnsafeMethod · 0.80
MoveValueUnsafeMethod · 0.80
okMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected