rusEFI
An attempt to build an Engine Control Unit
Public Member Functions | Data Fields
expected< TValue > Struct Template Reference

#include <expected.h>

Collaboration diagram for expected< TValue >:
Collaboration graph
[legend]

Public Member Functions

constexpr expected (const unexpected_t &)
 
constexpr expected (UnexpectedCode code)
 
constexpr expected (TValue validValue)
 
constexpr operator bool () const
 
constexpr TValue value_or (TValue valueIfInvalid) const
 
bool operator== (const expected< TValue > &other) const
 

Data Fields

bool Valid
 
union {
   TValue   Value
 
   UnexpectedCode   Code
 
}; 
 

Detailed Description

template<class TValue>
struct expected< TValue >

Definition at line 37 of file expected.h.

Constructor & Destructor Documentation

◆ expected() [1/3]

template<class TValue >
constexpr expected< TValue >::expected ( const unexpected_t )
inlineconstexpr

Definition at line 46 of file expected.h.

bool Valid
Definition: expected.h:38
UnexpectedCode Code
Definition: expected.h:42

◆ expected() [2/3]

template<class TValue >
constexpr expected< TValue >::expected ( UnexpectedCode  code)
inlineconstexpr

Definition at line 48 of file expected.h.

48 : Valid(false), Code{code} {}
uint8_t code
Definition: bluetooth.cpp:39

◆ expected() [3/3]

template<class TValue >
constexpr expected< TValue >::expected ( TValue  validValue)
inlineconstexpr

Definition at line 51 of file expected.h.

52  : Valid(true)
53  , Value(validValue)
54  {
55  }
TValue Value
Definition: expected.h:41

Member Function Documentation

◆ operator bool()

template<class TValue >
constexpr expected< TValue >::operator bool ( ) const
inlineexplicitconstexpr

Definition at line 58 of file expected.h.

58  {
59  return Valid;
60  }

◆ operator==()

template<class TValue >
bool expected< TValue >::operator== ( const expected< TValue > &  other) const
inline

Definition at line 67 of file expected.h.

67  {
68  // If validity mismatch, not equal
69  if (Valid != other.Valid) {
70  return false;
71  }
72 
73  // If both are invalid, they are equal
74  if (!Valid && !other.Valid) {
75  return true;
76  }
77 
78  // Both are guaranteed valid - simply compare values
79  return Value == other.Value;
80  }

◆ value_or()

template<class TValue >
constexpr TValue expected< TValue >::value_or ( TValue  valueIfInvalid) const
inlineconstexpr

Field Documentation

◆ 

union { ... }

◆ Code

template<class TValue >
UnexpectedCode expected< TValue >::Code

Definition at line 42 of file expected.h.

◆ Valid

template<class TValue >
bool expected< TValue >::Valid

◆ Value

template<class TValue >
TValue expected< TValue >::Value

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