algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::Result< T > Class Template Reference

Either a value or a BrokerError. More...

#include <algotradelib/src/core/types.hpp>

Public Member Functions

 Result (T value)
 Constructs a successful result.
 Result (BrokerError error)
 Constructs a failed result.
bool has_value () const noexcept
 Tests whether the result holds a value.
 operator bool () const noexcept
 Tests whether the result holds a value.
T & value ()
 Returns the value.
const T & value () const
 Returns the value.
BrokerError & error ()
 Returns the error.
const BrokerError & error () const
 Returns the error.

Detailed Description

template<typename T>
class algotradelib::Result< T >

Either a value or a BrokerError.

Test it with has_value() (or if (result)) before calling value() or error(); the wrong accessor throws std::bad_variant_access.

Template Parameters
TThe value type.

Definition at line 797 of file types.hpp.

Constructor & Destructor Documentation

◆ Result() [1/2]

◆ Result() [2/2]

template<typename T>
algotradelib::Result< T >::Result ( BrokerError error)
inline

Constructs a failed result.

Parameters
errorThe error.

Definition at line 809 of file types.hpp.

Member Function Documentation

◆ error() [1/2]

template<typename T>
BrokerError & algotradelib::Result< T >::error ( )
inline

Returns the error.

Returns
The error.
Exceptions
std::bad_variant_accessif the result holds a value.

Definition at line 842 of file types.hpp.

Referenced by algotradelib::DataOnlyTraits< Tag >::normalize_place(), and Result().

◆ error() [2/2]

template<typename T>
const BrokerError & algotradelib::Result< T >::error ( ) const
inline

Returns the error.

Returns
The error.
Exceptions
std::bad_variant_accessif the result holds a value.

Definition at line 849 of file types.hpp.

◆ has_value()

template<typename T>
bool algotradelib::Result< T >::has_value ( ) const
inlinenoexcept

Tests whether the result holds a value.

Returns
true for success.

Definition at line 815 of file types.hpp.

Referenced by operator bool().

◆ operator bool()

template<typename T>
algotradelib::Result< T >::operator bool ( ) const
inlineexplicitnoexcept

Tests whether the result holds a value.

Returns
true for success.

Definition at line 821 of file types.hpp.

◆ value() [1/2]

template<typename T>
T & algotradelib::Result< T >::value ( )
inline

Returns the value.

Returns
The value.
Exceptions
std::bad_variant_accessif the result holds an error.

Definition at line 828 of file types.hpp.

Referenced by Result().

◆ value() [2/2]

template<typename T>
const T & algotradelib::Result< T >::value ( ) const
inline

Returns the value.

Returns
The value.
Exceptions
std::bad_variant_accessif the result holds an error.

Definition at line 835 of file types.hpp.


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