From bff9a95056e9fb5bbd4a46ae6dfc95872dbb1c1b Mon Sep 17 00:00:00 2001 From: GregoryKogan Date: Sat, 23 Dec 2023 19:39:17 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20GregoryK?= =?UTF-8?q?ogan/result-cpp@f152e40be39a1d352e90497b2a72be33e6888812=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- annotated.html | 2 + annotated_dup.js | 4 +- classes.html | 8 +- classres_1_1Err-members.html | 108 ++++++++++ classres_1_1Err.html | 249 +++++++++++++++++++++++ classres_1_1Err.js | 7 + classres_1_1Ok-members.html | 108 ++++++++++ classres_1_1Ok.html | 253 ++++++++++++++++++++++++ classres_1_1Ok.js | 7 + classres_1_1Result-members.html | 15 +- classres_1_1Result.html | 229 ++------------------- classres_1_1Result.js | 4 +- dir_68267d1309a1af8e8297ef4c3efbcdba.js | 4 +- functions.html | 8 +- functions_func.html | 8 +- index.html | 6 +- navtreeindex0.js | 14 +- result_8h.html | 6 + result_8h_source.html | 155 +++++++-------- search/all_0.js | 2 +- search/all_2.js | 3 +- search/all_3.js | 6 +- search/all_4.js | 4 +- search/classes_0.js | 2 +- search/classes_1.html | 37 ++++ search/classes_1.js | 4 + search/classes_2.html | 37 ++++ search/classes_2.js | 4 + search/files_0.js | 2 +- search/functions_0.js | 2 +- search/functions_1.js | 4 +- search/functions_2.js | 3 +- search/functions_3.js | 4 +- search/pages_0.js | 2 +- search/searchdata.js | 2 +- 35 files changed, 976 insertions(+), 337 deletions(-) create mode 100644 classres_1_1Err-members.html create mode 100644 classres_1_1Err.html create mode 100644 classres_1_1Err.js create mode 100644 classres_1_1Ok-members.html create mode 100644 classres_1_1Ok.html create mode 100644 classres_1_1Ok.js create mode 100644 search/classes_1.html create mode 100644 search/classes_1.js create mode 100644 search/classes_2.html create mode 100644 search/classes_2.js diff --git a/annotated.html b/annotated.html index 7f9b873..f0344cd 100644 --- a/annotated.html +++ b/annotated.html @@ -93,6 +93,8 @@
[detail level 12]
+ +
 Nres
 CResultResult is a type that represents either success or failure
 COkOk object represents a successful outcome and can be converted to a Result
 CErrErr object represents an unsuccessful outcome and can be converted to a Result
diff --git a/annotated_dup.js b/annotated_dup.js index 896fbeb..b73e011 100644 --- a/annotated_dup.js +++ b/annotated_dup.js @@ -1,6 +1,8 @@ var annotated_dup = [ [ "res", null, [ - [ "Result", "classres_1_1Result.html", "classres_1_1Result" ] + [ "Result", "classres_1_1Result.html", "classres_1_1Result" ], + [ "Ok", "classres_1_1Ok.html", "classres_1_1Ok" ], + [ "Err", "classres_1_1Err.html", "classres_1_1Err" ] ] ] ]; \ No newline at end of file diff --git a/classes.html b/classes.html index 90f176e..c76fa56 100644 --- a/classes.html +++ b/classes.html @@ -89,9 +89,15 @@
Class Index
- +
E | O | R
+
E
+
Err (res)
+
+
O
+
Ok (res)
+
R
Result (res)
diff --git a/classres_1_1Err-members.html b/classres_1_1Err-members.html new file mode 100644 index 0000000..2c96698 --- /dev/null +++ b/classres_1_1Err-members.html @@ -0,0 +1,108 @@ + + + + + + + +C++ Result: Member List + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
C++ Result +  0.0.1 +
+
A modern C++ Result<T, E> type inspired by Rust
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
res::Err< E > Member List
+
+
+ +

This is the complete list of members for res::Err< E >, including all inherited members.

+ + + + + +
Err()=delete (defined in res::Err< E >)res::Err< E >
Err(const E &error)res::Err< E >inlineexplicit
Err(E &&error)res::Err< E >inlineexplicit
operator Result< T, E >() constres::Err< E >inline
+
+ + + + diff --git a/classres_1_1Err.html b/classres_1_1Err.html new file mode 100644 index 0000000..c1eb240 --- /dev/null +++ b/classres_1_1Err.html @@ -0,0 +1,249 @@ + + + + + + + +C++ Result: res::Err< E > Class Template Reference + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
C++ Result +  0.0.1 +
+
A modern C++ Result<T, E> type inspired by Rust
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
res::Err< E > Class Template Reference
+
+
+ +

Err object represents an unsuccessful outcome and can be converted to a Result. + More...

+ +

#include <result.h>

+ + + + + + + + + + + + +

+Public Member Functions

 Err (const E &error)
 Creates an Err object with an error. More...
 
 Err (E &&error)
 Creates an Err object with a moved error. More...
 
template<typename T >
 operator Result< T, E > () const
 Implicitly converts Err<E> object to a Result<T, E>. More...
 
+

Detailed Description

+

template<typename E>
+class res::Err< E >

+ +

Err object represents an unsuccessful outcome and can be converted to a Result.

+

Err object holds an error of type E. Err object can't be empty, E must not be std::monostate.

Template Parameters
+ + +
E
+
+
+

Constructor & Destructor Documentation

+ +

◆ Err() [1/2]

+ +
+
+
+template<typename E >
+ + + + + +
+ + + + + + + + +
res::Err< E >::Err (const E & error)
+
+inlineexplicit
+
+ +

Creates an Err object with an error.

+
Parameters
+ + +
error
+
+
+ +
+
+ +

◆ Err() [2/2]

+ +
+
+
+template<typename E >
+ + + + + +
+ + + + + + + + +
res::Err< E >::Err (E && error)
+
+inlineexplicit
+
+ +

Creates an Err object with a moved error.

+
Parameters
+ + +
error
+
+
+ +
+
+

Member Function Documentation

+ +

◆ operator Result< T, E >()

+ +
+
+
+template<typename E >
+
+template<typename T >
+ + + + + +
+ + + + + + + +
res::Err< E >::operator Result< T, E > () const
+
+inline
+
+ +

Implicitly converts Err<E> object to a Result<T, E>.

+
Template Parameters
+ + +
T
+
+
+ +
+
+
The documentation for this class was generated from the following file: +
+
+ + + + diff --git a/classres_1_1Err.js b/classres_1_1Err.js new file mode 100644 index 0000000..6db0a2d --- /dev/null +++ b/classres_1_1Err.js @@ -0,0 +1,7 @@ +var classres_1_1Err = +[ + [ "Err", "classres_1_1Err.html#aaf56647bc33179ad5807ac54b2bd1c0a", null ], + [ "Err", "classres_1_1Err.html#ac4633e3057ea869036b31112e8649ecc", null ], + [ "Err", "classres_1_1Err.html#a9d3b76543206206333fa5b7a0e8a5b32", null ], + [ "operator Result< T, E >", "classres_1_1Err.html#ab49f16277322b7085881fa2781a16cc4", null ] +]; \ No newline at end of file diff --git a/classres_1_1Ok-members.html b/classres_1_1Ok-members.html new file mode 100644 index 0000000..ae1d8e9 --- /dev/null +++ b/classres_1_1Ok-members.html @@ -0,0 +1,108 @@ + + + + + + + +C++ Result: Member List + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
C++ Result +  0.0.1 +
+
A modern C++ Result<T, E> type inspired by Rust
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
res::Ok< T > Member List
+
+
+ +

This is the complete list of members for res::Ok< T >, including all inherited members.

+ + + + + +
Ok()res::Ok< T >inline
Ok(const T &value)res::Ok< T >inlineexplicit
Ok(T &&value)res::Ok< T >inlineexplicit
operator Result< T, E >() constres::Ok< T >inline
+
+ + + + diff --git a/classres_1_1Ok.html b/classres_1_1Ok.html new file mode 100644 index 0000000..2581c08 --- /dev/null +++ b/classres_1_1Ok.html @@ -0,0 +1,253 @@ + + + + + + + +C++ Result: res::Ok< T > Class Template Reference + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
C++ Result +  0.0.1 +
+
A modern C++ Result<T, E> type inspired by Rust
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
res::Ok< T > Class Template Reference
+
+
+ +

Ok object represents a successful outcome and can be converted to a Result. + More...

+ +

#include <result.h>

+ + + + + + + + + + + + + + + +

+Public Member Functions

Ok ()
 Creates an empty Ok object.
 
 Ok (const T &value)
 Creates an Ok object with a value. More...
 
 Ok (T &&value)
 Creates an Ok object with a moved value. More...
 
template<typename E >
 operator Result< T, E > () const
 Implicitly converts Ok<T> object to a Result<T, E>. More...
 
+

Detailed Description

+

template<typename T = std::monostate>
+class res::Ok< T >

+ +

Ok object represents a successful outcome and can be converted to a Result.

+

Ok object holds a value of type T. Empty Ok object can be created if T is std::monostate.

Template Parameters
+ + +
TType of the value. Defaults to std::monostate.
+
+
+

Constructor & Destructor Documentation

+ +

◆ Ok() [1/2]

+ +
+
+
+template<typename T = std::monostate>
+ + + + + +
+ + + + + + + + +
res::Ok< T >::Ok (const T & value)
+
+inlineexplicit
+
+ +

Creates an Ok object with a value.

+
Parameters
+ + +
value
+
+
+ +
+
+ +

◆ Ok() [2/2]

+ +
+
+
+template<typename T = std::monostate>
+ + + + + +
+ + + + + + + + +
res::Ok< T >::Ok (T && value)
+
+inlineexplicit
+
+ +

Creates an Ok object with a moved value.

+
Parameters
+ + +
value
+
+
+ +
+
+

Member Function Documentation

+ +

◆ operator Result< T, E >()

+ +
+
+
+template<typename T = std::monostate>
+
+template<typename E >
+ + + + + +
+ + + + + + + +
res::Ok< T >::operator Result< T, E > () const
+
+inline
+
+ +

Implicitly converts Ok<T> object to a Result<T, E>.

+
Template Parameters
+ + +
E
+
+
+ +
+
+
The documentation for this class was generated from the following file: +
+
+ + + + diff --git a/classres_1_1Ok.js b/classres_1_1Ok.js new file mode 100644 index 0000000..2b02905 --- /dev/null +++ b/classres_1_1Ok.js @@ -0,0 +1,7 @@ +var classres_1_1Ok = +[ + [ "Ok", "classres_1_1Ok.html#aa4d6e6dacbe21d4e291efc3c08e0045b", null ], + [ "Ok", "classres_1_1Ok.html#a0a321d009597a5284ca1c90125fb9ed2", null ], + [ "Ok", "classres_1_1Ok.html#a166c9acb93b64c27c7fafe112b604a15", null ], + [ "operator Result< T, E >", "classres_1_1Ok.html#af1ef17effc3000b44c0b2fb42be0abbc", null ] +]; \ No newline at end of file diff --git a/classres_1_1Result-members.html b/classres_1_1Result-members.html index 27fb35c..49078a9 100644 --- a/classres_1_1Result-members.html +++ b/classres_1_1Result-members.html @@ -92,15 +92,12 @@

This is the complete list of members for res::Result< T, E >, including all inherited members.

- - - - - - - - - + + + + + +
Err(const E &error) -> Result< T, E >res::Result< T, E >inlinestatic
Err(E &&error) -> Result< T, E >res::Result< T, E >inlinestatic
is_err() const noexcept -> boolres::Result< T, E >inline
is_ok() const noexcept -> boolres::Result< T, E >inline
Ok(const T &value) -> Result< T, E >res::Result< T, E >inlinestatic
Ok(T &&value) -> Result< T, E >res::Result< T, E >inlinestatic
Ok() noexcept -> Result< std::monostate, E >res::Result< T, E >inlinestatic
unwrap() const -> Tres::Result< T, E >inline
unwrap_err() const -> Eres::Result< T, E >inline
Err (defined in res::Result< T, E >)res::Result< T, E >friend
is_err() const noexcept -> boolres::Result< T, E >inline
is_ok() const noexcept -> boolres::Result< T, E >inline
Ok (defined in res::Result< T, E >)res::Result< T, E >friend
unwrap() const -> Tres::Result< T, E >inline
unwrap_err() const -> Eres::Result< T, E >inline
diff --git a/classres_1_1Result.html b/classres_1_1Result.html index 7f82417..987ffd7 100644 --- a/classres_1_1Result.html +++ b/classres_1_1Result.html @@ -87,7 +87,7 @@
res::Result< T, E > Class Template Reference
@@ -114,23 +114,16 @@  Returns the error of an unsuccessful Result. More...
  - - - - - - - - - - - - - - - - + + + + + + +

-Static Public Member Functions

static auto Ok (const T &value) -> Result< T, E >
 Creates a successful Result object containing a value. More...
 
static auto Ok (T &&value) -> Result< T, E >
 Analogous to Ok(const T &value) but for rvalue reference. More...
 
static auto Ok () noexcept -> Result< std::monostate, E >
 Creates a successful Result object containing an empty value. More...
 
static auto Err (const E &error) -> Result< T, E >
 Creates an unsuccessful Result object containing an error. More...
 
static auto Err (E &&error) -> Result< T, E >
 Analogous to Err(const E &error) but for rvalue reference. More...
 

+Friends

+template<typename T1 >
struct Ok
 
+template<typename E1 >
struct Err
 

Detailed Description

template<typename T, typename E>
@@ -145,93 +138,6 @@

Member Function Documentation

- -

◆ Err() [1/2]

- -
-
-
-template<typename T , typename E >
- - - - - -
- - - - - - - - -
auto res::Result< T, E >::Err (const E & error) -> Result<T, E>
-
-inlinestatic
-
- -

Creates an unsuccessful Result object containing an error.

-
Parameters
- - -
error
-
-
-
Note
Although it's possible to create a Result with an empty value, it's impossible to create it with an empty error. This is enforced by static_assert.
-
Returns
Result<T, E>
-
Exceptions
- - -
Anyexception thrown during the initialization of the E value.
-
-
- -
-
- -

◆ Err() [2/2]

- -
-
-
-template<typename T , typename E >
- - - - - -
- - - - - - - - -
auto res::Result< T, E >::Err (E && error) -> Result<T, E>
-
-inlinestatic
-
- -

Analogous to Err(const E &error) but for rvalue reference.

-
Parameters
- - -
error
-
-
-
Returns
Result<T, E>
-
Exceptions
- - -
Anyexception thrown during the initialization of the E value.
-
-
- -
-

◆ is_err()

@@ -284,119 +190,6 @@

Result is successful.

Returns
bool True if the Result is successful, false otherwise.
-

- - -

◆ Ok() [1/3]

- -
-
-
-template<typename T , typename E >
- - - - - -
- - - - -
auto res::Result< T, E >::Ok
-
-inlinestaticnoexcept
-
- -

Creates a successful Result object containing an empty value.

-
Returns
Result<std::monostate, E>
- -
-
- -

◆ Ok() [2/3]

- -
-
-
-template<typename T , typename E >
- - - - - -
- - - - - - - - -
auto res::Result< T, E >::Ok (const T & value) -> Result<T, E>
-
-inlinestatic
-
- -

Creates a successful Result object containing a value.

-
Parameters
- - -
value
-
-
-
Returns
Result<T, E>
-
Exceptions
- - -
Anyexception thrown during the initialization of the T value.
-
-
- -
-
- -

◆ Ok() [3/3]

- -
-
-
-template<typename T , typename E >
- - - - - -
- - - - - - - - -
auto res::Result< T, E >::Ok (T && value) -> Result<T, E>
-
-inlinestatic
-
- -

Analogous to Ok(const T &value) but for rvalue reference.

-
Parameters
- - -
value
-
-
-
Returns
Result<T, E>
-
Exceptions
- - -
Anyexception thrown during the initialization of the T value.
-
-
-
diff --git a/classres_1_1Result.js b/classres_1_1Result.js index 15f955c..f1e37d2 100644 --- a/classres_1_1Result.js +++ b/classres_1_1Result.js @@ -3,5 +3,7 @@ var classres_1_1Result = [ "is_err", "classres_1_1Result.html#aa33616d53b63aea7f3da728e9713f7f9", null ], [ "is_ok", "classres_1_1Result.html#a664f30279bdd1c81f7a170bf99c20a30", null ], [ "unwrap", "classres_1_1Result.html#aacd3069c9335ee26efb96ac814199688", null ], - [ "unwrap_err", "classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643", null ] + [ "unwrap_err", "classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643", null ], + [ "Err", "classres_1_1Result.html#af21a6521124e8d107c44cc55f8e4d607", null ], + [ "Ok", "classres_1_1Result.html#af3fa378cb2ff9c8e1a5b78142cdcfda5", null ] ]; \ No newline at end of file diff --git a/dir_68267d1309a1af8e8297ef4c3efbcdba.js b/dir_68267d1309a1af8e8297ef4c3efbcdba.js index f8b790e..2b0fdf3 100644 --- a/dir_68267d1309a1af8e8297ef4c3efbcdba.js +++ b/dir_68267d1309a1af8e8297ef4c3efbcdba.js @@ -1,6 +1,8 @@ var dir_68267d1309a1af8e8297ef4c3efbcdba = [ [ "result.h", "result_8h.html", [ - [ "Result", "classres_1_1Result.html", "classres_1_1Result" ] + [ "Result", "classres_1_1Result.html", "classres_1_1Result" ], + [ "Ok", "classres_1_1Ok.html", "classres_1_1Ok" ], + [ "Err", "classres_1_1Err.html", "classres_1_1Err" ] ] ] ]; \ No newline at end of file diff --git a/functions.html b/functions.html index 7a7d071..1fec2da 100644 --- a/functions.html +++ b/functions.html @@ -87,7 +87,7 @@
Here is a list of all documented class members with links to the class documentation for each member:
diff --git a/navtreeindex0.js b/navtreeindex0.js index dc421d0..a9315f3 100644 --- a/navtreeindex0.js +++ b/navtreeindex0.js @@ -2,17 +2,29 @@ var NAVTREEINDEX0 = { "annotated.html":[1,0], "classes.html":[1,1], +"classres_1_1Err.html":[1,0,0,2], +"classres_1_1Err.html#a9d3b76543206206333fa5b7a0e8a5b32":[1,0,0,2,2], +"classres_1_1Err.html#aaf56647bc33179ad5807ac54b2bd1c0a":[1,0,0,2,0], +"classres_1_1Err.html#ab49f16277322b7085881fa2781a16cc4":[1,0,0,2,3], +"classres_1_1Err.html#ac4633e3057ea869036b31112e8649ecc":[1,0,0,2,1], +"classres_1_1Ok.html":[1,0,0,1], +"classres_1_1Ok.html#a0a321d009597a5284ca1c90125fb9ed2":[1,0,0,1,1], +"classres_1_1Ok.html#a166c9acb93b64c27c7fafe112b604a15":[1,0,0,1,2], +"classres_1_1Ok.html#aa4d6e6dacbe21d4e291efc3c08e0045b":[1,0,0,1,0], +"classres_1_1Ok.html#af1ef17effc3000b44c0b2fb42be0abbc":[1,0,0,1,3], "classres_1_1Result.html":[1,0,0,0], "classres_1_1Result.html#a664f30279bdd1c81f7a170bf99c20a30":[1,0,0,0,1], "classres_1_1Result.html#aa33616d53b63aea7f3da728e9713f7f9":[1,0,0,0,0], "classres_1_1Result.html#aacd3069c9335ee26efb96ac814199688":[1,0,0,0,2], "classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643":[1,0,0,0,3], +"classres_1_1Result.html#af21a6521124e8d107c44cc55f8e4d607":[1,0,0,0,4], +"classres_1_1Result.html#af3fa378cb2ff9c8e1a5b78142cdcfda5":[1,0,0,0,5], "dir_68267d1309a1af8e8297ef4c3efbcdba.html":[2,0,0], "files.html":[2,0], "functions.html":[1,2,0], "functions_func.html":[1,2,1], -"index.html":[0], "index.html":[], +"index.html":[0], "index.html#autotoc_md1":[0,0], "index.html#autotoc_md2":[0,1], "pages.html":[], diff --git a/result_8h.html b/result_8h.html index 809d7a3..749a866 100644 --- a/result_8h.html +++ b/result_8h.html @@ -104,6 +104,12 @@ class  res::Result< T, E >  Result is a type that represents either success or failure. More...
  +class  res::Ok< T >Ok object represents a successful outcome and can be converted to a Result. More...
+  +class  res::Err< E >Err object represents an unsuccessful outcome and can be converted to a Result. More...

Detailed Description

result-cpp is a C++ library that provides a Result<T, E> type, which can be used to return and propagate errors. It's inspired by Rust's std::Result type.

diff --git a/result_8h_source.html b/result_8h_source.html index 6e6993a..38ebd30 100644 --- a/result_8h_source.html +++ b/result_8h_source.html @@ -101,89 +101,84 @@
28  enum ContentType { Value, Error };
29  std::variant<T, E> content_;
30 
-
31  auto emplace_value(const T &value) -> void;
-
32  auto emplace_error(const E &error) -> void;
+
31  template <typename T1> friend struct Ok;
+
32  template <typename E1> friend struct Err;
33 
-
34 public:
-
35  [[nodiscard]] static auto Ok(const T &value) -> Result<T, E>;
-
36  [[nodiscard]] static auto Ok(T &&value) -> Result<T, E>;
-
37  [[nodiscard]] static auto Ok() noexcept -> Result<std::monostate, E>;
-
38 
-
39  [[nodiscard]] static auto Err(const E &error) -> Result<T, E>;
-
40  [[nodiscard]] static auto Err(E &&error) -> Result<T, E>;
-
41 
-
42  [[nodiscard]] auto is_ok() const noexcept -> bool;
-
43  [[nodiscard]] auto is_err() const noexcept -> bool;
+
34  auto set_value(const T &value) -> void { content_.template emplace<ContentType::Value>(value); }
+
35  auto set_error(const E &error) -> void { content_.template emplace<ContentType::Error>(error); }
+
36 
+
37 public:
+
38  [[nodiscard]] auto is_ok() const noexcept -> bool;
+
39  [[nodiscard]] auto is_err() const noexcept -> bool;
+
40 
+
41  [[nodiscard]] auto unwrap() const -> T;
+
42  [[nodiscard]] auto unwrap_err() const -> E;
+
43 };
44 
-
45  [[nodiscard]] auto unwrap() const -> T;
-
46  [[nodiscard]] auto unwrap_err() const -> E;
-
47 };
-
48 
-
49 template <typename T, typename E> inline auto Result<T, E>::emplace_value(const T &value) -> void {
-
50  content_.template emplace<ContentType::Value>(value);
-
51 }
-
52 
-
53 template <typename T, typename E> inline auto Result<T, E>::emplace_error(const E &error) -> void {
-
54  content_.template emplace<ContentType::Error>(error);
-
55 }
-
56 
-
61 template <typename T, typename E> inline auto Result<T, E>::Ok(const T &value) -> Result<T, E> {
-
62  Result<T, E> result;
-
63  result.emplace_value(value);
-
64  return result;
-
65 }
-
66 
-
71 template <typename T, typename E> inline auto Result<T, E>::Ok(T &&value) -> Result<T, E> {
-
72  Result<T, E> result;
-
73  result.emplace_value(std::move(value));
-
74  return result;
-
75 }
-
76 
-
79 template <typename T, typename E> inline auto Result<T, E>::Ok() noexcept -> Result<std::monostate, E> {
- -
81  result.emplace_value(std::monostate{});
-
82  return result;
-
83 }
-
84 
-
91 template <typename T, typename E> inline auto Result<T, E>::Err(const E &error) -> Result<T, E> {
-
92  Result<T, E> result;
-
93  result.emplace_error(error);
-
94  return result;
-
95 }
-
96 
-
101 template <typename T, typename E> inline auto Result<T, E>::Err(E &&error) -> Result<T, E> {
-
102  Result<T, E> result;
-
103  result.emplace_error(std::move(error));
-
104  return result;
-
105 }
-
106 
-
109 template <typename T, typename E> inline auto Result<T, E>::is_ok() const noexcept -> bool {
-
110  return content_.index() == ContentType::Value;
-
111 }
-
112 
-
115 template <typename T, typename E> inline auto Result<T, E>::is_err() const noexcept -> bool {
-
116  return content_.index() == ContentType::Error;
-
117 }
-
118 
-
123 template <typename T, typename E> inline auto Result<T, E>::unwrap() const -> T {
-
124  if (is_err()) { throw std::runtime_error("Called unwrap on an Err value"); }
-
125  if constexpr (std::is_same_v<T, std::monostate>) { throw std::runtime_error("Called unwrap on an empty value"); }
-
126  return std::get<ContentType::Value>(content_);
-
127 }
-
128 
-
132 template <typename T, typename E> inline auto Result<T, E>::unwrap_err() const -> E {
-
133  if (is_ok()) { throw std::runtime_error("Called unwrap_err on an Ok value"); }
-
134  return std::get<ContentType::Error>(content_);
-
135 }
-
136 
-
137 } // namespace res
+
48 template <typename T = std::monostate> class Ok {
+
49  T value_;
+
50 
+
51 public:
+
53  Ok() : value_() {}
+
56  explicit Ok(const T &value) : value_(value) {}
+
59  explicit Ok(T &&value) : value_(std::move(value)) {}
+
60 
+
63  template <typename E> operator Result<T, E>() const { // NOLINT(google-explicit-constructor)
+
64  Result<T, E> result;
+
65  result.set_value(value_);
+
66  return result;
+
67  }
+
68 };
+
69 
+
73 template <typename E> class Err {
+
74  static_assert(!std::is_same_v<E, std::monostate>, "E must not be std::monostate");
+
75 
+
76  E error_;
+
77 
+
78 public:
+
79  Err() = delete;
+
82  explicit Err(const E &error) : error_(error) {}
+
85  explicit Err(E &&error) : error_(std::move(error)) {}
+
86 
+
89  template <typename T> operator Result<T, E>() const { // NOLINT(google-explicit-constructor)
+
90  Result<T, E> result;
+
91  result.set_error(error_);
+
92  return result;
+
93  }
+
94 };
+
95 
+
98 template <typename T, typename E> inline auto Result<T, E>::is_ok() const noexcept -> bool {
+
99  return content_.index() == ContentType::Value;
+
100 }
+
101 
+
104 template <typename T, typename E> inline auto Result<T, E>::is_err() const noexcept -> bool {
+
105  return content_.index() == ContentType::Error;
+
106 }
+
107 
+
112 template <typename T, typename E> inline auto Result<T, E>::unwrap() const -> T {
+
113  if (is_err()) { throw std::runtime_error("Called unwrap on an Err value"); }
+
114  if constexpr (std::is_same_v<T, std::monostate>) { throw std::runtime_error("Called unwrap on an empty value"); }
+
115  return std::get<ContentType::Value>(content_);
+
116 }
+
117 
+
121 template <typename T, typename E> inline auto Result<T, E>::unwrap_err() const -> E {
+
122  if (is_ok()) { throw std::runtime_error("Called unwrap_err on an Ok value"); }
+
123  return std::get<ContentType::Error>(content_);
+
124 }
+
125 
+
126 } // namespace res
+
Err object represents an unsuccessful outcome and can be converted to a Result.
Definition: result.h:73
+
Err(E &&error)
Creates an Err object with a moved error.
Definition: result.h:85
+
Err(const E &error)
Creates an Err object with an error.
Definition: result.h:82
+
Ok object represents a successful outcome and can be converted to a Result.
Definition: result.h:48
+
Ok(const T &value)
Creates an Ok object with a value.
Definition: result.h:56
+
Ok(T &&value)
Creates an Ok object with a moved value.
Definition: result.h:59
+
Ok()
Creates an empty Ok object.
Definition: result.h:53
Result is a type that represents either success or failure.
Definition: result.h:25
-
auto is_ok() const noexcept -> bool
Checks if the Result is successful.
Definition: result.h:109
-
static auto Err(const E &error) -> Result< T, E >
Creates an unsuccessful Result object containing an error.
Definition: result.h:91
-
auto is_err() const noexcept -> bool
Checks if the Result is unsuccessful.
Definition: result.h:115
-
auto unwrap() const -> T
Returns the value of a successful Result.
Definition: result.h:123
-
auto unwrap_err() const -> E
Returns the error of an unsuccessful Result.
Definition: result.h:132
-
static auto Ok() noexcept -> Result< std::monostate, E >
Creates a successful Result object containing an empty value.
Definition: result.h:79
+
auto is_ok() const noexcept -> bool
Checks if the Result is successful.
Definition: result.h:98
+
auto is_err() const noexcept -> bool
Checks if the Result is unsuccessful.
Definition: result.h:104
+
auto unwrap() const -> T
Returns the value of a successful Result.
Definition: result.h:112
+
auto unwrap_err() const -> E
Returns the error of an unsuccessful Result.
Definition: result.h:121
diff --git a/search/all_0.js b/search/all_0.js index 9eebbd7..f3c67e5 100644 --- a/search/all_0.js +++ b/search/all_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['err_0',['Err',['../classres_1_1Result.html#a78e33a04a3f3b0689ebc1909b5dfb77a',1,'res::Result::Err(const E &error) -> Result< T, E >'],['../classres_1_1Result.html#a1b631a20b1b40d2c36e2504929aba8f1',1,'res::Result::Err(E &&error) -> Result< T, E >']]] + ['err_0',['Err',['../classres_1_1Err.html#ac4633e3057ea869036b31112e8649ecc',1,'res::Err::Err(const E &error)'],['../classres_1_1Err.html#a9d3b76543206206333fa5b7a0e8a5b32',1,'res::Err::Err(E &&error)'],['../classres_1_1Err.html',1,'res::Err< E >']]] ]; diff --git a/search/all_2.js b/search/all_2.js index cc021f2..8d51ac7 100644 --- a/search/all_2.js +++ b/search/all_2.js @@ -1,4 +1,5 @@ var searchData= [ - ['ok_3',['Ok',['../classres_1_1Result.html#a994dfd7b95549db48f540f4a6d7d24b8',1,'res::Result::Ok(const T &value) -> Result< T, E >'],['../classres_1_1Result.html#af23c1e04a472bab4c00e7c663392aa56',1,'res::Result::Ok(T &&value) -> Result< T, E >'],['../classres_1_1Result.html#afba7c5d69e4942722533c8c65232d0a3',1,'res::Result::Ok() noexcept -> Result< std::monostate, E >']]] + ['ok_3',['Ok',['../classres_1_1Ok.html#aa4d6e6dacbe21d4e291efc3c08e0045b',1,'res::Ok::Ok()'],['../classres_1_1Ok.html#a0a321d009597a5284ca1c90125fb9ed2',1,'res::Ok::Ok(const T &value)'],['../classres_1_1Ok.html#a166c9acb93b64c27c7fafe112b604a15',1,'res::Ok::Ok(T &&value)'],['../classres_1_1Ok.html',1,'res::Ok< T >']]], + ['operator_20result_3c_20t_2c_20e_20_3e_4',['operator Result< T, E >',['../classres_1_1Ok.html#af1ef17effc3000b44c0b2fb42be0abbc',1,'res::Ok::operator Result< T, E >()'],['../classres_1_1Err.html#ab49f16277322b7085881fa2781a16cc4',1,'res::Err::operator Result< T, E >()']]] ]; diff --git a/search/all_3.js b/search/all_3.js index fc05d6c..3a67938 100644 --- a/search/all_3.js +++ b/search/all_3.js @@ -1,6 +1,6 @@ var searchData= [ - ['result_4',['Result',['../classres_1_1Result.html',1,'res']]], - ['result_2dcpp_5',['result-cpp',['../index.html',1,'']]], - ['result_2eh_6',['result.h',['../result_8h.html',1,'']]] + ['result_5',['Result',['../classres_1_1Result.html',1,'res']]], + ['result_2dcpp_6',['result-cpp',['../index.html',1,'']]], + ['result_2eh_7',['result.h',['../result_8h.html',1,'']]] ]; diff --git a/search/all_4.js b/search/all_4.js index ef9e9e6..8e9a3eb 100644 --- a/search/all_4.js +++ b/search/all_4.js @@ -1,5 +1,5 @@ var searchData= [ - ['unwrap_7',['unwrap',['../classres_1_1Result.html#aacd3069c9335ee26efb96ac814199688',1,'res::Result']]], - ['unwrap_5ferr_8',['unwrap_err',['../classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643',1,'res::Result']]] + ['unwrap_8',['unwrap',['../classres_1_1Result.html#aacd3069c9335ee26efb96ac814199688',1,'res::Result']]], + ['unwrap_5ferr_9',['unwrap_err',['../classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643',1,'res::Result']]] ]; diff --git a/search/classes_0.js b/search/classes_0.js index 946b84f..294eb18 100644 --- a/search/classes_0.js +++ b/search/classes_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['result_9',['Result',['../classres_1_1Result.html',1,'res']]] + ['err_10',['Err',['../classres_1_1Err.html',1,'res']]] ]; diff --git a/search/classes_1.html b/search/classes_1.html new file mode 100644 index 0000000..576e916 --- /dev/null +++ b/search/classes_1.html @@ -0,0 +1,37 @@ + + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/search/classes_1.js b/search/classes_1.js new file mode 100644 index 0000000..2cf8bf2 --- /dev/null +++ b/search/classes_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['ok_11',['Ok',['../classres_1_1Ok.html',1,'res']]] +]; diff --git a/search/classes_2.html b/search/classes_2.html new file mode 100644 index 0000000..956405e --- /dev/null +++ b/search/classes_2.html @@ -0,0 +1,37 @@ + + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/search/classes_2.js b/search/classes_2.js new file mode 100644 index 0000000..f1b1a3d --- /dev/null +++ b/search/classes_2.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['result_12',['Result',['../classres_1_1Result.html',1,'res']]] +]; diff --git a/search/files_0.js b/search/files_0.js index 4136f74..e9ab203 100644 --- a/search/files_0.js +++ b/search/files_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['result_2eh_10',['result.h',['../result_8h.html',1,'']]] + ['result_2eh_13',['result.h',['../result_8h.html',1,'']]] ]; diff --git a/search/functions_0.js b/search/functions_0.js index 63b8d16..856a8f9 100644 --- a/search/functions_0.js +++ b/search/functions_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['err_11',['Err',['../classres_1_1Result.html#a78e33a04a3f3b0689ebc1909b5dfb77a',1,'res::Result::Err(const E &error) -> Result< T, E >'],['../classres_1_1Result.html#a1b631a20b1b40d2c36e2504929aba8f1',1,'res::Result::Err(E &&error) -> Result< T, E >']]] + ['err_14',['Err',['../classres_1_1Err.html#ac4633e3057ea869036b31112e8649ecc',1,'res::Err::Err(const E &error)'],['../classres_1_1Err.html#a9d3b76543206206333fa5b7a0e8a5b32',1,'res::Err::Err(E &&error)']]] ]; diff --git a/search/functions_1.js b/search/functions_1.js index 2d57d40..46577ce 100644 --- a/search/functions_1.js +++ b/search/functions_1.js @@ -1,5 +1,5 @@ var searchData= [ - ['is_5ferr_12',['is_err',['../classres_1_1Result.html#aa33616d53b63aea7f3da728e9713f7f9',1,'res::Result']]], - ['is_5fok_13',['is_ok',['../classres_1_1Result.html#a664f30279bdd1c81f7a170bf99c20a30',1,'res::Result']]] + ['is_5ferr_15',['is_err',['../classres_1_1Result.html#aa33616d53b63aea7f3da728e9713f7f9',1,'res::Result']]], + ['is_5fok_16',['is_ok',['../classres_1_1Result.html#a664f30279bdd1c81f7a170bf99c20a30',1,'res::Result']]] ]; diff --git a/search/functions_2.js b/search/functions_2.js index ed9f12c..2757cb9 100644 --- a/search/functions_2.js +++ b/search/functions_2.js @@ -1,4 +1,5 @@ var searchData= [ - ['ok_14',['Ok',['../classres_1_1Result.html#a994dfd7b95549db48f540f4a6d7d24b8',1,'res::Result::Ok(const T &value) -> Result< T, E >'],['../classres_1_1Result.html#af23c1e04a472bab4c00e7c663392aa56',1,'res::Result::Ok(T &&value) -> Result< T, E >'],['../classres_1_1Result.html#afba7c5d69e4942722533c8c65232d0a3',1,'res::Result::Ok() noexcept -> Result< std::monostate, E >']]] + ['ok_17',['Ok',['../classres_1_1Ok.html#aa4d6e6dacbe21d4e291efc3c08e0045b',1,'res::Ok::Ok()'],['../classres_1_1Ok.html#a0a321d009597a5284ca1c90125fb9ed2',1,'res::Ok::Ok(const T &value)'],['../classres_1_1Ok.html#a166c9acb93b64c27c7fafe112b604a15',1,'res::Ok::Ok(T &&value)']]], + ['operator_20result_3c_20t_2c_20e_20_3e_18',['operator Result< T, E >',['../classres_1_1Ok.html#af1ef17effc3000b44c0b2fb42be0abbc',1,'res::Ok::operator Result< T, E >()'],['../classres_1_1Err.html#ab49f16277322b7085881fa2781a16cc4',1,'res::Err::operator Result< T, E >()']]] ]; diff --git a/search/functions_3.js b/search/functions_3.js index 63186d6..3d6cd9a 100644 --- a/search/functions_3.js +++ b/search/functions_3.js @@ -1,5 +1,5 @@ var searchData= [ - ['unwrap_15',['unwrap',['../classres_1_1Result.html#aacd3069c9335ee26efb96ac814199688',1,'res::Result']]], - ['unwrap_5ferr_16',['unwrap_err',['../classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643',1,'res::Result']]] + ['unwrap_19',['unwrap',['../classres_1_1Result.html#aacd3069c9335ee26efb96ac814199688',1,'res::Result']]], + ['unwrap_5ferr_20',['unwrap_err',['../classres_1_1Result.html#ae62cbc23e0435b8da8674d22ae27b643',1,'res::Result']]] ]; diff --git a/search/pages_0.js b/search/pages_0.js index c9a5811..be95bcc 100644 --- a/search/pages_0.js +++ b/search/pages_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['result_2dcpp_17',['result-cpp',['../index.html',1,'']]] + ['result_2dcpp_21',['result-cpp',['../index.html',1,'']]] ]; diff --git a/search/searchdata.js b/search/searchdata.js index af5359e..f4d1cbb 100644 --- a/search/searchdata.js +++ b/search/searchdata.js @@ -1,7 +1,7 @@ var indexSectionsWithContent = { 0: "eioru", - 1: "r", + 1: "eor", 2: "r", 3: "eiou", 4: "r"