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 1058 of file types.hpp.

Constructor & Destructor Documentation

◆ Result() [1/2]

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

Constructs a successful result.

Parameters
valueThe value.

Definition at line 1064 of file types.hpp.

Referenced by algotradelib::alpaca::AlpacaBlockingClient::bars(), algotradelib::BlockingSession< Client >::bars(), algotradelib::mock::Market::bars(), algotradelib::mock::MockClient::bars(), algotradelib::mock::Market::buying_power(), algotradelib::alpaca::AlpacaBlockingClient::calendar(), algotradelib::BlockingSession< Client >::calendar(), algotradelib::mock::Market::calendar(), algotradelib::mock::MockClient::calendar(), algotradelib::BlockingSession< Client >::cancel(), algotradelib::alpaca::AlpacaBlockingClient::cancel_order(), algotradelib::DataOnlyTraits< Tag >::cancel_order(), algotradelib::backtest::CommissionPolicy::charge(), algotradelib::backtest::commission_model_from(), algotradelib::DataOnlyTraits< Tag >::holdings(), algotradelib::mock::Market::holdings(), algotradelib::alpaca::AlpacaBlockingClient::instrument(), algotradelib::mock::Market::instrument(), algotradelib::mock::MockClient::instrument(), algotradelib::alpaca::AlpacaBlockingClient::order_by_id(), algotradelib::BlockingSession< Client >::order_history(), algotradelib::DataOnlyTraits< Tag >::order_history(), algotradelib::mock::MockClient::order_history(), algotradelib::BlockingSession< Client >::place(), algotradelib::alpaca::AlpacaBlockingClient::place_order(), algotradelib::DataOnlyTraits< Tag >::place_order(), algotradelib::data_only::post_refusal(), algotradelib::alpaca::AlpacaBlockingClient::quote(), algotradelib::mock::Market::quote(), algotradelib::mock::MockClient::quote(), algotradelib::BlockingSession< Client >::replace(), algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::replace_order(), algotradelib::BrokerTraits< mock::MockClient >::replace_order(), algotradelib::DataOnlyTraits< Tag >::replace_order(), algotradelib::backtest::CommissionPolicy::scheduled(), algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::to_cancellation(), algotradelib::BrokerTraits< mock::MockClient >::to_cancellation(), algotradelib::DataOnlyTraits< Tag >::to_cancellation(), algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::to_history_query(), algotradelib::BrokerTraits< mock::MockClient >::to_history_query(), algotradelib::DataOnlyTraits< Tag >::to_history_query(), algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::to_replacement(), algotradelib::BrokerTraits< mock::MockClient >::to_replacement(), and algotradelib::DataOnlyTraits< Tag >::to_replacement().

◆ Result() [2/2]

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

Constructs a failed result.

Parameters
errorThe error.

Definition at line 1070 of file types.hpp.

Member Function Documentation

◆ error() [1/2]

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

◆ 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 1120 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 1076 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 1084 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 1093 of file types.hpp.

Referenced by algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::normalize_place(), algotradelib::BrokerTraits< alpaca::AlpacaBlockingClient >::normalize_working_orders(), and 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 1102 of file types.hpp.


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