STX  1.0.0
Namespaces | Classes | Typedefs | Functions | Variables
stx Namespace Reference

Namespaces

 backtrace
 
 internal
 
 this_thread
 

Classes

struct  Err
 
class  FixedReport
 
struct  is_equality_comparable
 
struct  is_equality_comparable< T, Cmp, typename std::enable_if_t< true, decltype((std::declval< std::remove_reference_t< T > const & >()==std::declval< std::remove_reference_t< Cmp > const & >()) &&(std::declval< std::remove_reference_t< T > const & >() !=std::declval< std::remove_reference_t< Cmp > const & >()),(void) 0)> >
 
struct  NoneType
 
struct  Ok
 
struct  Option
 
class  ReportPayload
 
struct  ReportQuery
 Tag type for dispatching reports. More...
 
struct  Result
 
struct  Some
 
struct  SourceLocation
 
class  SpanReport
 

Typedefs

template<typename Fn , typename... Args>
using invoke_result = typename std::invoke_result_t< Fn, Args... >
 
template<typename T >
using Ref = std::reference_wrapper< T >
 
template<typename T >
using ConstRef = std::reference_wrapper< std::add_const_t< std::remove_reference_t< T > >>
 ConstRef is an always-const Ref. More...
 
template<typename T >
using MutRef = std::reference_wrapper< std::remove_const_t< std::remove_reference_t< T > >>
 MutRef is an always-mutable Ref More...
 
using PanicHook = decltype(panic_handler) *
 
using AtomicPanicHook = std::atomic< PanicHook >
 

Functions

template<typename U , typename T >
STX_FORCE_INLINE constexpr bool operator== (Some< U > const &cmp, Option< T > const &option)
 
template<typename U , typename T >
STX_FORCE_INLINE constexpr bool operator!= (Some< U > const &cmp, Option< T > const &option)
 
template<typename T >
STX_FORCE_INLINE constexpr bool operator== (NoneType const &, Option< T > const &option) noexcept
 
template<typename T >
STX_FORCE_INLINE constexpr bool operator!= (NoneType const &, Option< T > const &option) noexcept
 
template<typename U , typename T , typename E >
STX_FORCE_INLINE constexpr bool operator== (Ok< U > const &cmp, Result< T, E > const &result)
 
template<typename U , typename T , typename E >
STX_FORCE_INLINE constexpr bool operator!= (Ok< U > const &cmp, Result< T, E > const &result)
 
template<typename F , typename T , typename E >
STX_FORCE_INLINE constexpr bool operator== (Err< F > const &cmp, Result< T, E > const &result)
 
template<typename F , typename T , typename E >
STX_FORCE_INLINE constexpr bool operator!= (Err< F > const &cmp, Result< T, E > const &result)
 
template<typename T >
STX_FORCE_INLINE constexpr auto make_some (T value) -> Option< T >
 
template<typename T >
STX_FORCE_INLINE constexpr auto make_none () noexcept -> Option< T >
 
template<typename T , typename E >
STX_FORCE_INLINE constexpr auto make_ok (T value) -> Result< T, E >
 
template<typename T , typename E >
STX_FORCE_INLINE constexpr auto make_err (E err) -> Result< T, E >
 
template<typename T >
STX_FORCE_INLINE auto some_ref (T &value) noexcept
 
template<typename T >
STX_FORCE_INLINE auto ok_ref (T &value) noexcept
 
template<typename E >
STX_FORCE_INLINE auto err_ref (E &value) noexcept
 
void panic_abort (std::string_view const &info, ReportPayload const &payload, SourceLocation const &location)
 Causes the abort instruction to be executed. More...
 
void panic_default (std::string_view const &info, ReportPayload const &payload, SourceLocation const &location) noexcept
 
void panic_halt (std::string_view const &info, ReportPayload const &payload, SourceLocation const &location) noexcept
 
STX_EXPORT bool panic_hook_visible () noexcept
 
STX_LOCAL bool attach_panic_hook (PanicHook hook) noexcept
 
STX_LOCAL bool take_panic_hook (PanicHook *hook) noexcept
 
void panic_handler (std::string_view const &info, ReportPayload const &payload, SourceLocation const &location) noexcept
 
void begin_panic (std::string_view const &info, ReportPayload const &payload, SourceLocation const &location) noexcept
 
template<typename T >
STX_FORCE_INLINE void panic (std::string_view const &info, T const &value, SourceLocation const &location=SourceLocation::current()) noexcept
 
template<typename T = void>
STX_FORCE_INLINE void panic (std::string_view const &info="explicit panic", SourceLocation const &location=SourceLocation::current()) noexcept
 
template<typename T >
SpanReport operator>> (ReportQuery, T const &) noexcept
 
template<typename T >
FixedReport operator>> (ReportQuery, T const *const &ptr) noexcept
 
template<typename T >
FixedReport operator>> (ReportQuery, T *const &ptr) noexcept
 
FixedReport operator>> (ReportQuery, int8_t const &v) noexcept
 
FixedReport operator>> (ReportQuery, uint8_t const &v) noexcept
 
FixedReport operator>> (ReportQuery, int16_t const &v) noexcept
 
FixedReport operator>> (ReportQuery, uint16_t const &v) noexcept
 
FixedReport operator>> (ReportQuery, int32_t const &v) noexcept
 
FixedReport operator>> (ReportQuery, uint32_t const &v) noexcept
 
SpanReport operator>> (ReportQuery, std::string_view const &v) noexcept
 
SpanReport operator>> (ReportQuery, std::string const &v) noexcept
 

Variables

template<typename Fn , typename... Args>
constexpr bool invocable = std::is_invocable_v<Fn, Args...>
 
template<typename T >
constexpr bool movable
 
template<typename T >
constexpr bool copy_constructible = std::is_copy_constructible_v<T>
 
template<typename From , typename To >
constexpr bool convertible = std::is_convertible_v<From, To>
 
template<typename T , typename Cmp = T>
constexpr bool equality_comparable = is_equality_comparable<T, Cmp>::value
 Checks if the type has a compatible 'operator ==' and 'operator!='. More...
 
template<typename T >
constexpr bool is_reference = std::is_reference_v<T>
 
constexpr NoneType const None {}
 value-variant for Option<T> representing no-value More...
 
constexpr bool kPanicHookVisible = false
 
constexpr size_t kReportReserveSize = 128
 
constexpr char const kReportTruncationMessage []
 
constexpr ReportQuery const report_query {}
 Tag value for dispatching reports. More...
 
constexpr char const kFormatError [] = "<format error>"
 
constexpr size_t const kFormatErrorSize = sizeof(kFormatError) - 1
 

Typedef Documentation

◆ AtomicPanicHook

using stx::AtomicPanicHook = typedef std::atomic<PanicHook>

◆ ConstRef

template<typename T >
using stx::ConstRef = typedef std::reference_wrapper<std::add_const_t<std::remove_reference_t<T> >>

ConstRef is an always-const Ref.

◆ invoke_result

template<typename Fn , typename... Args>
using stx::invoke_result = typedef typename std::invoke_result_t<Fn, Args...>

◆ MutRef

template<typename T >
using stx::MutRef = typedef std::reference_wrapper<std::remove_const_t<std::remove_reference_t<T> >>

MutRef is an always-mutable Ref

◆ PanicHook

using stx::PanicHook = typedef decltype(panic_handler)*

◆ Ref

template<typename T >
using stx::Ref = typedef std::reference_wrapper<T>

Ref is an alias for std::reference_wrapper Ref can be mutable and immutable depending on the const-qualifier for T To offer stronger guarantees prefer ConstRef and MutRef

Function Documentation

◆ attach_panic_hook()

STX_LOCAL bool stx::attach_panic_hook ( PanicHook  hook)
noexcept

Attaches a new panic hook, the attached panic hook is called in place of the default panic hook.

Returns true if the thread is not panicking and the panic hook was successfully attached, else returns false.

Thread-safe?

Yes

◆ begin_panic()

void stx::begin_panic ( std::string_view const &  info,
ReportPayload const &  payload,
SourceLocation const &  location 
)
noexcept

Handles and dispatches the panic handler. The debugging breakpoint should be attached to this function to investigate panics.

WARNING

DO NOT INVOKE THIS FUNCTION!!!

◆ err_ref()

template<typename E >
STX_FORCE_INLINE auto stx::err_ref ( E &  value)
noexcept

Helper function to construct an Err containing a std::reference_wrapper (stx::Ref)

Examples

Basic usage:

int x = 4;
Result<int, Ref<int>> y = err_ref(x); // constructs an
// Err<std::reference_wrapper<int>>
// a.k.a. Err<Ref<int>>
int const a = 5;
Result<int, Ref<const int>> b = err_ref(a); // constructs an
// Err<std::reference_wrapper<const int>>
// a.k.a. Err<Ref<const int>>
// note that 'a' is const

◆ make_err()

template<typename T , typename E >
STX_FORCE_INLINE constexpr auto stx::make_err ( err) -> Result<T, E>

Helper function to construct a Result<T, E> with an Err<E> value. if the template parameter E is not specified, it is auto-deduced from the parameter's value.

NOTE

The value type T must be specified and is the first template parameter.

Examples

Basic usage:

// these are some of the various ways to construct on Result<T, E> with an
// Err<E> value
Result<int, string> a = Err("foo"s);
Result<int, string> b = Err<string>("foo"s);
// to make it easier and less verbose:
auto c = make_err<int, string>("bar"s); // 'c' = Result<int, string>
ASSERT_EQ(c, Err("bar"s));

Constexpr ?

C++ 20 and above

◆ make_none()

template<typename T >
STX_FORCE_INLINE constexpr auto stx::make_none ( ) -> Option<T>
noexcept

Helper function to construct an Option<T> with a None value. note that the value parameter T must be specified.

Examples

Basic usage:

// these are some of the various ways to construct on Option<T> with
// a None value
Option<int> h = None;
auto i = Option<int>(None);
Option j = Option<int>(None);
Option<int> k = make_none<int>();
// to make it easier and less verbose:
auto m = make_none<int>(); // 'm' = Option<int>
ASSERT_EQ(m, None);

Constexpr ?

C++ 20 and above

◆ make_ok()

template<typename T , typename E >
STX_FORCE_INLINE constexpr auto stx::make_ok ( value) -> Result<T, E>

Helper function to construct a Result<T, E> with an Ok<T> value.

NOTE

The value type T must be specified and is the first template parameter.

Examples

Basic usage:

// these are some of the various ways to construct on Result<T, E> with an
// Ok<T> value
Result<int, string> a = Ok(8);
Result<int, string> b = Ok<int>(8);
// to make it easier and less verbose:
auto c = make_ok<int, string>(9); // 'c' = Result<string, int>
ASSERT_EQ(c, Ok(9));
auto d = make_ok<string, int>("Hello"s);
ASSERT_EQ(d, Ok("Hello"s));

Constexpr ?

C++ 20 and above

◆ make_some()

template<typename T >
STX_FORCE_INLINE constexpr auto stx::make_some ( value) -> Option<T>

Helper function to construct an Option<T> with a Some<T> value. if the template parameter is not specified, it is auto-deduced from the parameter's value.

Examples

Basic usage:

// these are some of the various ways to construct on Option<T> with a
// Some<T> value
Option g = Some(9);
Option h = Some<int>(9);
Option<int> i = Some(9);
auto j = Option(Some(9));
auto k = Option<int>(Some<int>(9));
auto l = Option<int>(Some(9));
// ... and a few more
// to make it easier and less verbose:
auto m = make_some(9); // 'm' is of type Option<int>
ASSERT_EQ(m, Some(9));
auto n = make_some<int>(9); // to be explicit
ASSERT_EQ(m, Some(9));

Constexpr ?

C++ 20 and above

◆ ok_ref()

template<typename T >
STX_FORCE_INLINE auto stx::ok_ref ( T &  value)
noexcept

Helper function to construct an Ok containing a std::reference_wrapper (stx::Ref)

Examples

Basic usage:

int x = 4;
Result<Ref<int>, int> y = ok_ref(x); // constructs an
// Ok<std::reference_wrapper<int>>
// a.k.a. Ok<Ref<int>>
int const a = 5;
Result<Ref<const int>, int> b = ok_ref(a); // constructs an
// Ok<std::reference_wrapper<const int>> a.k.a.
// Ok<Ref<const int>
// note that 'a' is const

◆ operator!=() [1/4]

template<typename U , typename T >
STX_FORCE_INLINE constexpr bool stx::operator!= ( Some< U > const &  cmp,
Option< T > const &  option 
)

◆ operator!=() [2/4]

template<typename T >
STX_FORCE_INLINE constexpr bool stx::operator!= ( NoneType const &  ,
Option< T > const &  option 
)
noexcept

◆ operator!=() [3/4]

template<typename U , typename T , typename E >
STX_FORCE_INLINE constexpr bool stx::operator!= ( Ok< U > const &  cmp,
Result< T, E > const &  result 
)

◆ operator!=() [4/4]

template<typename F , typename T , typename E >
STX_FORCE_INLINE constexpr bool stx::operator!= ( Err< F > const &  cmp,
Result< T, E > const &  result 
)

◆ operator==() [1/4]

template<typename U , typename T >
STX_FORCE_INLINE constexpr bool stx::operator== ( Some< U > const &  cmp,
Option< T > const &  option 
)

◆ operator==() [2/4]

template<typename T >
STX_FORCE_INLINE constexpr bool stx::operator== ( NoneType const &  ,
Option< T > const &  option 
)
noexcept

◆ operator==() [3/4]

template<typename U , typename T , typename E >
STX_FORCE_INLINE constexpr bool stx::operator== ( Ok< U > const &  cmp,
Result< T, E > const &  result 
)

◆ operator==() [4/4]

template<typename F , typename T , typename E >
STX_FORCE_INLINE constexpr bool stx::operator== ( Err< F > const &  cmp,
Result< T, E > const &  result 
)

◆ operator>>() [1/11]

template<typename T >
SpanReport stx::operator>> ( ReportQuery  ,
T const &   
)
inlinenoexcept

◆ operator>>() [2/11]

template<typename T >
FixedReport stx::operator>> ( ReportQuery  ,
T const *const &  ptr 
)
inlinenoexcept

◆ operator>>() [3/11]

template<typename T >
FixedReport stx::operator>> ( ReportQuery  ,
T *const &  ptr 
)
inlinenoexcept

◆ operator>>() [4/11]

FixedReport stx::operator>> ( ReportQuery  ,
int8_t const &  v 
)
inlinenoexcept

◆ operator>>() [5/11]

FixedReport stx::operator>> ( ReportQuery  ,
uint8_t const &  v 
)
inlinenoexcept

◆ operator>>() [6/11]

FixedReport stx::operator>> ( ReportQuery  ,
int16_t const &  v 
)
inlinenoexcept

◆ operator>>() [7/11]

FixedReport stx::operator>> ( ReportQuery  ,
uint16_t const &  v 
)
inlinenoexcept

◆ operator>>() [8/11]

FixedReport stx::operator>> ( ReportQuery  ,
int32_t const &  v 
)
inlinenoexcept

◆ operator>>() [9/11]

FixedReport stx::operator>> ( ReportQuery  ,
uint32_t const &  v 
)
inlinenoexcept

◆ operator>>() [10/11]

SpanReport stx::operator>> ( ReportQuery  ,
std::string_view const &  v 
)
inlinenoexcept

◆ operator>>() [11/11]

SpanReport stx::operator>> ( ReportQuery  ,
std::string const &  v 
)
inlinenoexcept

◆ panic() [1/2]

template<typename T >
STX_FORCE_INLINE void stx::panic ( std::string_view const &  info,
T const &  value,
SourceLocation const &  location = SourceLocation::current() 
)
noexcept

This allows a program to terminate immediately and provide feedback to the caller of the program. panic should be used when a program reaches an unrecoverable state. This function is the perfect way to assert conditions in example code and in tests. panic is closely tied with the unwrap and expect method of both Option and Result. Both implementations call panic when they are set to None or Err variants.

◆ panic() [2/2]

template<typename T = void>
STX_FORCE_INLINE void stx::panic ( std::string_view const &  info = "explicit panic",
SourceLocation const &  location = SourceLocation::current() 
)
noexcept

◆ panic_abort()

void stx::panic_abort ( std::string_view const &  info,
ReportPayload const &  payload,
SourceLocation const &  location 
)
inline

Causes the abort instruction to be executed.

◆ panic_default()

void stx::panic_default ( std::string_view const &  info,
ReportPayload const &  payload,
SourceLocation const &  location 
)
inlinenoexcept

◆ panic_halt()

void stx::panic_halt ( std::string_view const &  info,
ReportPayload const &  payload,
SourceLocation const &  location 
)
inlinenoexcept

Causes the program, or the current thread, to halt by entering an infinite loop. You can force the program to continue via a debugger by setting the halt value to true. after which the program will abort.

◆ panic_handler()

void stx::panic_handler ( std::string_view const &  info,
ReportPayload const &  payload,
SourceLocation const &  location 
)
noexcept

The global panic handler. It is advisable to be avoid heap memory allocation of any sort and be conscious of shared state as it can be called from mulitple threads.

◆ panic_hook_visible()

STX_EXPORT bool stx::panic_hook_visible ( )
noexcept

Checks if panic hooks are visible to be attached-to when loaded as a dynamic library. This should be called before calling any of attach_panic_hook or take_panic_hook when loaded as a dynamic library.

Thread-safe?

Yes

◆ some_ref()

template<typename T >
STX_FORCE_INLINE auto stx::some_ref ( T &  value)
noexcept

Helper function to construct a Some containing a std::reference_wrapper (stx::Ref)

Examples

Basic usage:

int x = 4;
Option<Ref<int>> y = some_ref(x); // constructs a
// Some<std::reference_wrapper<int>>
// a.k.a. Some<Ref<int>>
int const a = 5;
Option<Ref<const int>> b = some_ref(a); // constructs a
// Some<std::reference_wrapper<const int>>
// a.k.a. Some<Ref<const int>>
// note that 'a' is const

◆ take_panic_hook()

STX_LOCAL bool stx::take_panic_hook ( PanicHook hook)
noexcept

Removes the registered panic hook (if any) and resets it to the default panic hook. hook is set to the last-registered panic hook or the default.

Returns true if the thread is not panicking and the panic hook was successfully taken, else returns false.

Thread-safe?

Yes

Variable Documentation

◆ convertible

template<typename From , typename To >
constexpr bool stx::convertible = std::is_convertible_v<From, To>

◆ copy_constructible

template<typename T >
constexpr bool stx::copy_constructible = std::is_copy_constructible_v<T>

◆ equality_comparable

template<typename T , typename Cmp = T>
constexpr bool stx::equality_comparable = is_equality_comparable<T, Cmp>::value

Checks if the type has a compatible 'operator ==' and 'operator!='.

◆ invocable

template<typename Fn , typename... Args>
constexpr bool stx::invocable = std::is_invocable_v<Fn, Args...>

◆ is_reference

template<typename T >
constexpr bool stx::is_reference = std::is_reference_v<T>

◆ kFormatError

constexpr char const stx::kFormatError[] = "<format error>"

◆ kFormatErrorSize

constexpr size_t const stx::kFormatErrorSize = sizeof(kFormatError) - 1

◆ kPanicHookVisible

constexpr bool stx::kPanicHookVisible = false

◆ kReportReserveSize

constexpr size_t stx::kReportReserveSize = 128

◆ kReportTruncationMessage

constexpr char const stx::kReportTruncationMessage[]
Initial value:
=
"... (error report truncated)"

◆ movable

template<typename T >
constexpr bool stx::movable
Initial value:
= std::is_object_v<T>&& std::is_move_constructible_v<T>&&
std::is_assignable_v<T&, T>&& std::is_swappable_v<T>

◆ None

constexpr NoneType const stx::None {}

value-variant for Option<T> representing no-value

◆ report_query

constexpr ReportQuery const stx::report_query {}

Tag value for dispatching reports.