zpp
Zephyr C++20 Framework
zpp::result< T_Ok, T_Error > Class Template Reference

result class More...

#include <result.hpp>

Public Member Functions

 result () noexcept
 default initialization to error state More...
 
 result (const T_Ok &rhs) noexcept
 initialization to OK state More...
 
 result (T_Ok &&rhs) noexcept
 initialization to OK state More...
 
 result (const error_result< T_Error > &rhs) noexcept
 initialization to error state More...
 
 result (error_result< T_Error > &&rhs) noexcept
 initialization to error state More...
 
 result (const result &rhs) noexcept
 copy contructor More...
 
 result (result &&rhs) noexcept
 move contructor More...
 
 ~result () noexcept
 destructor More...
 
void assign_value (const T_Ok &v) noexcept
 
void assign_value (T_Ok &&v) noexcept
 
void assign_error (const T_Error &e) noexcept
 
void assign_error (T_Error &&e) noexcept
 
resultoperator= (const result &rhs) noexcept
 copy operator More...
 
resultoperator= (result &&rhs) noexcept
 move operator More...
 
resultoperator= (const T_Ok &rhs) noexcept
 copy operator More...
 
resultoperator= (T_Ok &&rhs) noexcept
 move operator More...
 
resultoperator= (const error_result< T_Error > &rhs) noexcept
 copy operator More...
 
resultoperator= (error_result< T_Error > &&rhs) noexcept
 move operator More...
 
T_Ok & value () noexcept
 return a reference to the OK value More...
 
const T_Ok & value () const noexcept
 return a const reference to the result value More...
 
T_Error & error () noexcept
 return a reference to the OK value More...
 
const T_Error & error () const noexcept
 return a const reference to the result value More...
 
T_Ok & operator* () noexcept
 return a reference to the result value More...
 
const T_Ok & operator* () const noexcept
 return a const reference to the result value More...
 
T_Ok * operator-> () noexcept
 return a pointer to the result value More...
 
const T_Ok * operator-> () const noexcept
 return a const pointer to the result value More...
 
constexpr bool has_value () const noexcept
 convert the result to a bool More...
 
constexpr operator bool () const noexcept
 convert the result to a bool More...
 

Detailed Description

template<typename T_Ok, typename T_Error>
class zpp::result< T_Ok, T_Error >

result class

Parameters
T_Okthe type for the OK result
T_Errorthe type for the error result

Definition at line 89 of file result.hpp.

Constructor & Destructor Documentation

◆ result() [1/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( )
inlinenoexcept

default initialization to error state

Definition at line 105 of file result.hpp.

106  : m_is_ok(false)
107  {
108  new(&m_error_value) T_Error();
109  }
T_Error m_error_value
Definition: result.hpp:453

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ result() [2/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( const T_Ok &  rhs)
inlinenoexcept

initialization to OK state

Parameters
rhsthe OK value to assign

Definition at line 116 of file result.hpp.

117  : m_is_ok(true)
118  {
119  new(&m_ok_value) T_Ok(rhs);
120  }
T_Ok m_ok_value
Definition: result.hpp:454

References zpp::result< T_Ok, T_Error >::m_ok_value.

◆ result() [3/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( T_Ok &&  rhs)
inlinenoexcept

initialization to OK state

Parameters
rhsthe OK value to assign

Definition at line 127 of file result.hpp.

128  : m_is_ok(true)
129  {
130  new(&m_ok_value) T_Ok(std::move(rhs));
131  }

References zpp::result< T_Ok, T_Error >::m_ok_value.

◆ result() [4/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( const error_result< T_Error > &  rhs)
inlinenoexcept

initialization to error state

Parameters
rhsthe error value to assign

Definition at line 138 of file result.hpp.

139  : m_is_ok(false)
140  {
141  new(&m_error_value) T_Error(rhs.error());
142  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ result() [5/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( error_result< T_Error > &&  rhs)
inlinenoexcept

initialization to error state

Parameters
rhsthe error value to assign

Definition at line 150 of file result.hpp.

151  : m_is_ok(false)
152  {
153  new(&m_error_value) T_Error(std::move(rhs.error()));
154  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ result() [6/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( const result< T_Ok, T_Error > &  rhs)
inlinenoexcept

copy contructor

Parameters
rhsthe value to assign

Definition at line 161 of file result.hpp.

162  : m_is_ok(rhs.m_is_ok)
163  {
164  if (m_is_ok) {
165  new(&m_ok_value) T_Ok(rhs.m_ok_value);
166  } else {
167  new(&m_error_value) T_Error(rhs.m_error_value);
168  }
169  }

References zpp::result< T_Ok, T_Error >::m_error_value, and zpp::result< T_Ok, T_Error >::m_ok_value.

◆ result() [7/7]

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::result ( result< T_Ok, T_Error > &&  rhs)
inlinenoexcept

move contructor

Parameters
rhsthe value to assign

Definition at line 176 of file result.hpp.

177  : m_is_ok(rhs.m_is_ok)
178  {
179  if (m_is_ok) {
180  new(&m_ok_value) T_Ok(std::move(rhs.m_ok_value));
181  } else {
182  new(&m_error_value) T_Error(std::move(rhs.m_error_value));
183  }
184  }

References zpp::result< T_Ok, T_Error >::m_error_value, and zpp::result< T_Ok, T_Error >::m_ok_value.

◆ ~result()

template<typename T_Ok , typename T_Error >
zpp::result< T_Ok, T_Error >::~result ( )
inlinenoexcept

destructor

Definition at line 189 of file result.hpp.

189  {
190  if (m_is_ok) {
191  m_ok_value.~T_Ok();
192  } else {
193  m_error_value.~T_Error();
194  }
195  }

References zpp::result< T_Ok, T_Error >::m_error_value, and zpp::result< T_Ok, T_Error >::m_ok_value.

Member Function Documentation

◆ assign_error() [1/2]

◆ assign_error() [2/2]

template<typename T_Ok , typename T_Error >
void zpp::result< T_Ok, T_Error >::assign_error ( T_Error &&  e)
inlinenoexcept

Definition at line 230 of file result.hpp.

230  {
231  if (m_is_ok) {
232  m_ok_value.~T_Ok();
233  } else {
234  m_error_value.~T_Error();
235  }
236 
237  m_is_ok = false;
238  new(&m_error_value) T_Error(std::move(e));
239  }

References zpp::result< T_Ok, T_Error >::m_error_value, and zpp::result< T_Ok, T_Error >::m_ok_value.

◆ assign_value() [1/2]

◆ assign_value() [2/2]

template<typename T_Ok , typename T_Error >
void zpp::result< T_Ok, T_Error >::assign_value ( T_Ok &&  v)
inlinenoexcept

Definition at line 208 of file result.hpp.

208  {
209  if (m_is_ok) {
210  m_ok_value.~T_Ok();
211  } else {
212  m_error_value.~T_Error();
213  }
214 
215  m_is_ok = true;
216  new(&m_ok_value) T_Ok(std::move(v));
217  }

References zpp::result< T_Ok, T_Error >::m_error_value, and zpp::result< T_Ok, T_Error >::m_ok_value.

◆ error() [1/2]

template<typename T_Ok , typename T_Error >
const T_Error& zpp::result< T_Ok, T_Error >::error ( ) const
inlinenoexcept

return a const reference to the result value

Returns
T_Ok const reference
Warning
when the result is in error state the the thread will terminate

Definition at line 373 of file result.hpp.

373  {
374  if (m_is_ok) {
375  // unhandeld error
376  }
377 
378  return m_error_value;
379  }

References zpp::result< T_Ok, T_Error >::m_error_value.

◆ error() [2/2]

template<typename T_Ok , typename T_Error >
T_Error& zpp::result< T_Ok, T_Error >::error ( )
inlinenoexcept

return a reference to the OK value

Returns
T_Ok reference
Warning
when the result is in error state the the thread will terminate

Definition at line 358 of file result.hpp.

358  {
359  if (m_is_ok) {
360  // unhandeld error
361  }
362 
363  return m_error_value;
364  }

References zpp::result< T_Ok, T_Error >::m_error_value.

Referenced by ZTEST().

◆ has_value()

template<typename T_Ok , typename T_Error >
constexpr bool zpp::result< T_Ok, T_Error >::has_value ( ) const
inlineconstexprnoexcept

convert the result to a bool

Returns
true if the result is valid

Definition at line 438 of file result.hpp.

438  {
439  return m_is_ok;
440  }

◆ operator bool()

template<typename T_Ok , typename T_Error >
constexpr zpp::result< T_Ok, T_Error >::operator bool ( ) const
inlineexplicitconstexprnoexcept

convert the result to a bool

Returns
true if the result is valid

Definition at line 447 of file result.hpp.

447  {
448  return m_is_ok;
449  }

◆ operator*() [1/2]

template<typename T_Ok , typename T_Error >
const T_Ok& zpp::result< T_Ok, T_Error >::operator* ( ) const
inlinenoexcept

return a const reference to the result value

Returns
T_Ok const reference
Warning
when the result is in error state the the thread will terminate

Definition at line 399 of file result.hpp.

399  {
400  return value();
401  }
T_Ok & value() noexcept
return a reference to the OK value
Definition: result.hpp:327

References zpp::result< T_Ok, T_Error >::value().

◆ operator*() [2/2]

template<typename T_Ok , typename T_Error >
T_Ok& zpp::result< T_Ok, T_Error >::operator* ( )
inlinenoexcept

return a reference to the result value

Returns
T_Ok reference
Warning
when the result is in error state the the thread will terminate

Definition at line 388 of file result.hpp.

388  {
389  return value();
390  }

References zpp::result< T_Ok, T_Error >::value().

◆ operator->() [1/2]

template<typename T_Ok , typename T_Error >
const T_Ok* zpp::result< T_Ok, T_Error >::operator-> ( ) const
inlinenoexcept

return a const pointer to the result value

Returns
T_Ok const pointer
Warning
when the result is in error state the the thread will terminate

Definition at line 425 of file result.hpp.

425  {
426  if (!m_is_ok) {
427  // unhandeld error
428  }
429 
430  return &m_ok_value;
431  }

References zpp::result< T_Ok, T_Error >::m_ok_value.

◆ operator->() [2/2]

template<typename T_Ok , typename T_Error >
T_Ok* zpp::result< T_Ok, T_Error >::operator-> ( )
inlinenoexcept

return a pointer to the result value

Returns
T_Ok pointer
Warning
when the result is in error state the the thread will terminate

Definition at line 410 of file result.hpp.

410  {
411  if (!m_is_ok) {
412  // unhandeld error
413  }
414 
415  return &m_ok_value;
416  }

References zpp::result< T_Ok, T_Error >::m_ok_value.

◆ operator=() [1/6]

template<typename T_Ok , typename T_Error >
result& zpp::result< T_Ok, T_Error >::operator= ( const error_result< T_Error > &  rhs)
inlinenoexcept

copy operator

Parameters
rhsthe value to assign

Definition at line 302 of file result.hpp.

303  {
304  assign_error(rhs.error());
305  return *this;
306  }
void assign_error(const T_Error &e) noexcept
Definition: result.hpp:219

References zpp::result< T_Ok, T_Error >::assign_error().

◆ operator=() [2/6]

template<typename T_Ok , typename T_Error >
result& zpp::result< T_Ok, T_Error >::operator= ( const result< T_Ok, T_Error > &  rhs)
inlinenoexcept

copy operator

Parameters
rhsthe value to assign

Definition at line 247 of file result.hpp.

248  {
249  if (rhs.m_is_ok) {
250  assign_value(rhs.m_ok_value);
251  } else {
252  assign_error(rhs.m_error_value);
253  }
254 
255  return *this;
256  }
void assign_value(const T_Ok &v) noexcept
Definition: result.hpp:197

References zpp::result< T_Ok, T_Error >::assign_error(), and zpp::result< T_Ok, T_Error >::assign_value().

◆ operator=() [3/6]

template<typename T_Ok , typename T_Error >
result& zpp::result< T_Ok, T_Error >::operator= ( const T_Ok &  rhs)
inlinenoexcept

copy operator

Parameters
rhsthe value to assign

Definition at line 280 of file result.hpp.

281  {
282  assign_value(rhs);
283  return *this;
284  }

References zpp::result< T_Ok, T_Error >::assign_value().

◆ operator=() [4/6]

template<typename T_Ok , typename T_Error >
result& zpp::result< T_Ok, T_Error >::operator= ( error_result< T_Error > &&  rhs)
inlinenoexcept

move operator

Parameters
rhsthe value to assign

Definition at line 313 of file result.hpp.

314  {
315  assign_error(std::move(rhs.error()));
316  return *this;
317  }

References zpp::result< T_Ok, T_Error >::assign_error().

◆ operator=() [5/6]

template<typename T_Ok , typename T_Error >
result& zpp::result< T_Ok, T_Error >::operator= ( result< T_Ok, T_Error > &&  rhs)
inlinenoexcept

move operator

Parameters
rhsthe value to assign

Definition at line 263 of file result.hpp.

264  {
265  if (rhs.m_is_ok) {
266  assign_value(std::move(rhs.m_ok_value));
267  } else {
268  assign_error(std::move(rhs.m_error_value));
269  }
270 
271  return *this;
272  }

References zpp::result< T_Ok, T_Error >::assign_error(), and zpp::result< T_Ok, T_Error >::assign_value().

◆ operator=() [6/6]

template<typename T_Ok , typename T_Error >
result& zpp::result< T_Ok, T_Error >::operator= ( T_Ok &&  rhs)
inlinenoexcept

move operator

Parameters
rhsthe value to assign

Definition at line 291 of file result.hpp.

292  {
293  assign_value(std::move(rhs));
294  return *this;
295  }

References zpp::result< T_Ok, T_Error >::assign_value().

◆ value() [1/2]

template<typename T_Ok , typename T_Error >
const T_Ok& zpp::result< T_Ok, T_Error >::value ( ) const
inlinenoexcept

return a const reference to the result value

Returns
T_Ok const reference
Warning
when the result is in error state the the thread will terminate

Definition at line 342 of file result.hpp.

342  {
343  if (!m_is_ok) {
344  // unhandeld error
345  }
346 
347  return m_ok_value;
348  }

References zpp::result< T_Ok, T_Error >::m_ok_value.

◆ value() [2/2]

template<typename T_Ok , typename T_Error >
T_Ok& zpp::result< T_Ok, T_Error >::value ( )
inlinenoexcept

return a reference to the OK value

Returns
T_Ok reference
Warning
when the result is in error state the the thread will terminate

Definition at line 327 of file result.hpp.

327  {
328  if (!m_is_ok) {
329  // unhandeld error
330  }
331 
332  return m_ok_value;
333  }

References zpp::result< T_Ok, T_Error >::m_ok_value.

Referenced by zpp::result< T_Ok, T_Error >::operator*(), and ZTEST().

Member Data Documentation

◆ m_error_value

◆ m_ok_value


The documentation for this class was generated from the following file: