ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::Result< T > Struct Template Reference

Result type template. More...

#include <ndn/common.hpp>

Public Member Functions

bool ok () const
 Check if the operation succeeded.
 
 operator bool () const
 Implicit conversion to bool.
 

Public Attributes

value
 Result value.
 
Error error
 Error code.
 

Detailed Description

template<typename T>
struct ndn::Result< T >

Result type template.

A type for returning both a value and an error code without using exceptions.

Template Parameters
TType of the value returned on success
Result<int> divide(int a, int b) {
if (b == 0) return {0, Error::InvalidParam};
return {a / b, Error::Success};
}
auto result = divide(10, 2);
if (result.ok()) {
printf("Result: %d\n", result.value);
}
Result type template.
Definition common.hpp:147

Definition at line 147 of file common.hpp.

Member Function Documentation

◆ ok()

template<typename T >
bool ndn::Result< T >::ok ( ) const
inline

Check if the operation succeeded.

Returns
true if successful

Definition at line 155 of file common.hpp.

References ndn::Result< T >::error.

Referenced by ndn::Result< T >::operator bool().

◆ operator bool()

template<typename T >
ndn::Result< T >::operator bool ( ) const
inlineexplicit

Implicit conversion to bool.

Returns
true if successful

Definition at line 161 of file common.hpp.

References ndn::Result< T >::ok().

Member Data Documentation

◆ error

template<typename T >
Error ndn::Result< T >::error

Error code.

Definition at line 149 of file common.hpp.

Referenced by ndn::Result< T >::ok().

◆ value


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