nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
nros::Expected< T > Class Template Reference

#include <result.hpp>

Public Member Functions

ErrorCode error () const
 
Result error_as_result () const
 
bool ok () const
 
 operator bool () const
 
Tvalue () &
 
T && value () &&
 
const Tvalue () const &
 

Static Public Member Functions

static Expected error (const Result &r)
 
static Expected error (ErrorCode code)
 
static Expected ok (T value)
 

Detailed Description

template<typename T>
class nros::Expected< T >

Phase 123.B.4 — templated value-or-error wrapper.

Lets factory functions return constructed entities by value instead of forcing the out-param + Result idiom. Trade-off: requires T to be default-constructible and move-constructible (Node, Publisher, Subscription all satisfy both today). Storage is direct (the value lives inline, no allocation) — when the result holds an error the value member is default-constructed and idle.

Usage:

auto node_r = nros::Node::make("my_node");
if (!node_r.ok()) return node_r.error_as_result();
auto& node = node_r.value();
Definition future.hpp:40

Out-param create_node(node, "name") remains the canonical zero-cost API for embedded / strictly-no-alloc code; make() is a hosted-friendly convenience that closes the rclcpp / rclrs idiom gap.

Member Function Documentation

◆ error() [1/3]

template<typename T >
ErrorCode nros::Expected< T >::error ( ) const
inline

◆ error() [2/3]

template<typename T >
static Expected nros::Expected< T >::error ( const Result r)
inlinestatic

◆ error() [3/3]

template<typename T >
static Expected nros::Expected< T >::error ( ErrorCode  code)
inlinestatic

◆ error_as_result()

template<typename T >
Result nros::Expected< T >::error_as_result ( ) const
inline

◆ ok() [1/2]

template<typename T >
bool nros::Expected< T >::ok ( ) const
inline

◆ ok() [2/2]

template<typename T >
static Expected nros::Expected< T >::ok ( T  value)
inlinestatic

◆ operator bool()

template<typename T >
nros::Expected< T >::operator bool ( ) const
inlineexplicit

◆ value() [1/3]

template<typename T >
T & nros::Expected< T >::value ( ) &
inline

◆ value() [2/3]

template<typename T >
T && nros::Expected< T >::value ( ) &&
inline

◆ value() [3/3]

template<typename T >
const T & nros::Expected< T >::value ( ) const &
inline

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