RTI Connext Modern C++ API Version 7.1.0
rti::core::Result< T > Class Template Reference

A result from an operation that doesn't throw exceptions containing a return code and (if successful) a value. More...

#include <Result.hpp>

Public Member Functions

 Result ()=default
 Creates a Result object with a return code of DDS_RETCODE_ERROR and no value. More...
 
 Result (const T &value)
 Creates a Result object with a return code of DDS_RETCODE_OK and a value that is copied. More...
 
 Result (T &&value)
 Creates a Result object with a return code of DDS_RETCODE_OK and a value that is moved. More...
 
 Result (DDS_ReturnCode_t retcode)
 Creates a Result object with a return code and no value. More...
 
const T & get () const &noexcept
 Gets the value without checking if the operation was successful. More...
 
T & get () &noexcept
 Gets the value without checking if the operation was successful. More...
 
DDS_ReturnCode_t get_return_code () const noexcept
 Gets the return code. More...
 
bool is_ok () const noexcept
 Returns true if the operation was successful. More...
 
const T & get_if_ok () const &
 Gets the value if the operation was successful, otherwise throws an exception. More...
 
T & get_if_ok () &
 Gets the value if the operation was successful, otherwise throws an exception. More...
 
T && get_if_ok () &&
 Gets the value if the operation was successful, otherwise throws an exception. More...
 
void throw_if_error () const
 Throws an exception if the operation was not successful. More...
 

Detailed Description

template<typename T>
class rti::core::Result< T >

A result from an operation that doesn't throw exceptions containing a return code and (if successful) a value.

For some critical operations in the API a exception-throwing and a noexcept version of the same function are provided. The noexcept versions return a Result<T> object to indicate if the operation was successful or not and, if it was, provide the return value of type T.

Note that Result<void> is specialized to not provide a value, only a return code.

Constructor & Destructor Documentation

◆ Result() [1/4]

template<typename T >
rti::core::Result< T >::Result ( )
default

Creates a Result object with a return code of DDS_RETCODE_ERROR and no value.

◆ Result() [2/4]

template<typename T >
rti::core::Result< T >::Result ( const T &  value)
inlineexplicit

Creates a Result object with a return code of DDS_RETCODE_OK and a value that is copied.

◆ Result() [3/4]

template<typename T >
rti::core::Result< T >::Result ( T &&  value)
inlineexplicit

Creates a Result object with a return code of DDS_RETCODE_OK and a value that is moved.

◆ Result() [4/4]

template<typename T >
rti::core::Result< T >::Result ( DDS_ReturnCode_t  retcode)
inlineexplicit

Creates a Result object with a return code and no value.

Member Function Documentation

◆ get() [1/2]

template<typename T >
const T & rti::core::Result< T >::get ( ) const &
inlinenoexcept

Gets the value without checking if the operation was successful.

If the operation was not successful, the behavior is undefined; use is_ok() first or use get_if_ok() instead.

◆ get() [2/2]

template<typename T >
T & rti::core::Result< T >::get ( ) &
inlinenoexcept

Gets the value without checking if the operation was successful.

If the operation was not successful, the behavior is undefined; use is_ok() first or use get_if_ok() instead.

◆ get_return_code()

template<typename T >
DDS_ReturnCode_t rti::core::Result< T >::get_return_code ( ) const
inlinenoexcept

Gets the return code.

◆ is_ok()

template<typename T >
bool rti::core::Result< T >::is_ok ( ) const
inlinenoexcept

Returns true if the operation was successful.

This is equivalent to get_return_code() == DDS_RETCODE_OK

◆ get_if_ok() [1/3]

template<typename T >
const T & rti::core::Result< T >::get_if_ok ( ) const &
inline

Gets the value if the operation was successful, otherwise throws an exception.

References rti::core::Result< T >::throw_if_error().

◆ get_if_ok() [2/3]

template<typename T >
T & rti::core::Result< T >::get_if_ok ( ) &
inline

Gets the value if the operation was successful, otherwise throws an exception.

References rti::core::Result< T >::throw_if_error().

◆ get_if_ok() [3/3]

template<typename T >
T && rti::core::Result< T >::get_if_ok ( ) &&
inline

Gets the value if the operation was successful, otherwise throws an exception.

References rti::core::Result< T >::throw_if_error().

◆ throw_if_error()

template<typename T >
void rti::core::Result< T >::throw_if_error ( ) const
inline

Throws an exception if the operation was not successful.

If the operation was successful, this function does nothing.

Referenced by rti::core::Result< T >::get_if_ok().