Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Commit 0ddcf83

Browse files
committed
improve Result documentation
1 parent ec85c2c commit 0ddcf83

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

include/common/result.hpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ class Result {
207207
: m_error(std::forward<E>(error)),
208208
m_value(traits::sentinel_v<T>) {}
209209

210+
/**
211+
* @brief Get the error of the given type, wrapped in std::optional
212+
*
213+
* @tparam Self the deduced self type
214+
* @tparam E the error type to get
215+
* @param self the self object
216+
* @return the error type, wrapped in std::optional
217+
*/
210218
template<typename Self, traits::IsResultError E>
211219
requires traits::is_in_pack_v<E, Errs...>
212220
constexpr auto&& get_error(this Self&& self) {
@@ -217,11 +225,24 @@ class Result {
217225
}
218226
}
219227

228+
/**
229+
* @brief Get the normal value
230+
*
231+
* @tparam Self the deduced self type
232+
* @param self the self object
233+
* @return the normal value
234+
*/
220235
template<typename Self>
221236
constexpr auto&& get_value(this Self&& self) {
222237
return std::forward<Self>(self).m_value;
223238
}
224239

240+
/**
241+
* @brief whether there is an error value
242+
*
243+
* @return true
244+
* @return false
245+
*/
225246
constexpr bool has_error() {
226247
return !std::holds_alternative<std::monostate>(m_error);
227248
}
@@ -291,6 +312,14 @@ class Result<void, Errs...> {
291312
constexpr Result()
292313
: m_error(std::monostate()) {}
293314

315+
/**
316+
* @brief Get the error of the given type, wrapped in std::optional
317+
*
318+
* @tparam Self the deduced self type
319+
* @tparam E the error type to get
320+
* @param self the self object
321+
* @return the error type, wrapped in std::optional
322+
*/
294323
template<typename Self, traits::IsResultError E>
295324
requires traits::is_in_pack_v<E, Errs...>
296325
constexpr auto&& get_error(this Self&& self) {
@@ -301,11 +330,12 @@ class Result<void, Errs...> {
301330
}
302331
}
303332

304-
template<typename Self>
305-
constexpr auto&& get_value(this Self&& self) {
306-
return std::forward<Self>(self).m_value;
307-
}
308-
333+
/**
334+
* @brief whether there is an error value
335+
*
336+
* @return true
337+
* @return false
338+
*/
309339
constexpr bool has_error() {
310340
return !std::holds_alternative<std::monostate>(m_error);
311341
}

0 commit comments

Comments
 (0)