iceberg-cpp
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions | Variables
expected.h File Reference

A C++20 backport of C++23 std::expected, used as the storage type behind iceberg::Result. More...

#include <exception>
#include <functional>
#include <type_traits>
#include <utility>
#include <version>
#include "iceberg/compat/compiler.h"
#include "iceberg/iceberg_export.h"

Go to the source code of this file.

Classes

struct  iceberg::expected_detail::remove_cvref< T >
 
struct  iceberg::expected_detail::is_equality_result_convertible_to_bool< Lhs, Rhs, class >
 
struct  iceberg::expected_detail::is_equality_result_convertible_to_bool< Lhs, Rhs, std::void_t< decltype(std::declval< const Lhs & >()==std::declval< const Rhs & >())> >
 
struct  iceberg::expected_detail::is_nothrow_equality_result_convertible_to_bool< Lhs, Rhs, class >
 
struct  iceberg::expected_detail::is_nothrow_equality_result_convertible_to_bool< Lhs, Rhs, std::void_t< decltype(implicitly_convert_to_bool(std::declval< const Lhs & >()==std::declval< const Rhs & >()))> >
 
struct  iceberg::expected_detail::is_error_type_valid< E >
 
class  iceberg::unexpected< E >
 
struct  iceberg::unexpect_t
 
class  iceberg::bad_expected_access< void >
 
class  iceberg::bad_expected_access< E >
 
struct  iceberg::expected_detail::construct_from_expected_t
 
struct  iceberg::expected_detail::construct_with_invoke_result_t
 
struct  iceberg::expected_detail::ReinitGuard< T >
 
struct  iceberg::expected_detail::storage_base< T, E, bool >
 
struct  iceberg::expected_detail::storage_base< T, E, false >
 
struct  iceberg::expected_detail::storage_base< void, E, true >
 
struct  iceberg::expected_detail::storage_base< void, E, true >::dummy
 
struct  iceberg::expected_detail::storage_base< void, E, false >
 
struct  iceberg::expected_detail::storage_base< void, E, false >::dummy
 
struct  iceberg::expected_detail::operations_base< T, E >
 
struct  iceberg::expected_detail::operations_base< void, E >
 
struct  iceberg::expected_detail::copy_ctor_base< T, E, Enabled, Trivially >
 
struct  iceberg::expected_detail::copy_ctor_base< T, E, false, false >
 
struct  iceberg::expected_detail::copy_ctor_base< T, E, true, false >
 
struct  iceberg::expected_detail::move_ctor_base< T, E, Enabled, Trivially >
 
struct  iceberg::expected_detail::move_ctor_base< T, E, false, false >
 
struct  iceberg::expected_detail::move_ctor_base< T, E, true, false >
 
struct  iceberg::expected_detail::copy_assign_base< T, E, Enabled, Trivially >
 
struct  iceberg::expected_detail::copy_assign_base< T, E, false, false >
 
struct  iceberg::expected_detail::copy_assign_base< T, E, true, false >
 
struct  iceberg::expected_detail::copy_assign_base< void, E, true, false >
 
struct  iceberg::expected_detail::move_assign_base< T, E, Enabled, Trivially >
 
struct  iceberg::expected_detail::move_assign_base< T, E, false, false >
 
struct  iceberg::expected_detail::move_assign_base< T, E, true, false >
 
struct  iceberg::expected_detail::move_assign_base< void, E, true, false >
 
struct  iceberg::expected_detail::default_constructor_tag
 
struct  iceberg::expected_detail::default_ctor_base< T, E, Enable >
 
struct  iceberg::expected_detail::default_ctor_base< T, E, false >
 
class  iceberg::expected< T, E >
 
class  iceberg::expected< void, E >
 

Namespaces

namespace  iceberg
 Core Apache Iceberg C++ APIs.
 

Macros

#define ICEBERG_EXPECTED_CPLUSPLUS   __cplusplus
 
#define ICEBERG_EXPECTED_CONSTEXPR_DTOR
 
#define ICEBERG_EXPECTED_THROW(e)   ((void)(e), std::terminate())
 

Typedefs

template<class T >
using iceberg::expected_detail::remove_cvref_t = typename remove_cvref< T >::type
 
template<class T , class U >
using iceberg::expected_detail::is_void_or = std::conditional_t< std::is_void_v< T >, std::true_type, U >
 

Functions

template<class T , class... Args>
constexpr T * iceberg::expected_detail::construct_at (T *p, Args &&... args) noexcept(noexcept(::new(static_cast< void * >(p)) T(std::forward< Args >(args)...)))
 
constexpr bool iceberg::expected_detail::implicitly_convert_to_bool (bool value) noexcept
 
template<class E >
 iceberg::unexpected (E) -> unexpected< E >
 
template<class Rhs >
constexpr bool iceberg::expected_detail::expected_source_has_value (const Rhs &rhs) noexcept
 
template<class Rhs >
constexpr decltype(auto) iceberg::expected_detail::expected_source_value (Rhs &&rhs) noexcept
 
template<class Rhs >
constexpr decltype(auto) iceberg::expected_detail::expected_source_error (Rhs &&rhs) noexcept
 
template<class First , class Second , class... Args>
constexpr void iceberg::expected_detail::reinit_expected (First &new_val, Second &old_val, Args &&... args) noexcept(std::is_nothrow_constructible_v< First, Args... >)
 
template<class T , class E , std::enable_if_t<!std::is_void_v< T > &&std::is_move_constructible_v< T > &&std::is_swappable_v< T > &&std::is_move_constructible_v< E > &&std::is_swappable_v< E > &&(std::is_nothrow_move_constructible_v< T >||std::is_nothrow_move_constructible_v< E >)> * = nullptr>
constexpr void iceberg::swap (expected< T, E > &lhs, expected< T, E > &rhs) noexcept(noexcept(lhs.swap(rhs)))
 
template<class T , class E , class T2 >
constexpr std::enable_if_t< !std::is_void_v< T > &&!expected_detail::is_specialization_v< T2, iceberg::expected > &&expected_detail::is_equality_result_convertible_to_bool_v< T, T2 >, bool > iceberg::operator== (const T2 &v, const expected< T, E > &x) noexcept(noexcept(x==v))
 
template<class T , class E , class T2 >
constexpr std::enable_if_t< !std::is_void_v< T > &&!expected_detail::is_specialization_v< T2, iceberg::expected > &&expected_detail::is_equality_result_convertible_to_bool_v< T, T2 >, bool > iceberg::operator!= (const T2 &v, const expected< T, E > &x) noexcept(noexcept(x==v))
 
template<class T , class E , class E2 , std::enable_if_t< expected_detail::is_equality_result_convertible_to_bool_v< E, E2 > > * = nullptr>
constexpr bool iceberg::operator== (const unexpected< E2 > &e, const expected< T, E > &x) noexcept(noexcept(x==e))
 
template<class T , class E , class E2 , std::enable_if_t< expected_detail::is_equality_result_convertible_to_bool_v< E, E2 > > * = nullptr>
constexpr bool iceberg::operator!= (const unexpected< E2 > &e, const expected< T, E > &x) noexcept(noexcept(x==e))
 
template<class E , std::enable_if_t< std::is_move_constructible_v< E > &&std::is_swappable_v< E > > * = nullptr>
constexpr void iceberg::swap (expected< void, E > &lhs, expected< void, E > &rhs) noexcept(noexcept(lhs.swap(rhs)))
 

Variables

template<class T , template< class... > class Template>
constexpr bool iceberg::expected_detail::is_specialization_v
 
template<template< class... > class Template, class... Types>
constexpr bool iceberg::expected_detail::is_specialization_v< Template< Types... >, Template > = true
 
template<class T , class U >
constexpr bool iceberg::expected_detail::is_void_or_v = is_void_or<T, U>::value
 
template<class T >
constexpr bool iceberg::expected_detail::is_trivially_destructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_trivially_copy_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_trivially_move_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_trivially_copy_assignable_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_trivially_move_assignable_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_nothrow_copy_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_nothrow_move_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_default_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_copy_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_move_constructible_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_copy_assignable_or_void_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_move_assignable_or_void_v
 
template<class From , class To >
constexpr bool iceberg::expected_detail::is_nothrow_convertible_v
 
template<class Lhs , class Rhs >
constexpr bool iceberg::expected_detail::is_equality_result_convertible_to_bool_v
 
template<class Lhs , class Rhs >
constexpr bool iceberg::expected_detail::is_nothrow_equality_result_convertible_to_bool_v
 
template<class T >
constexpr bool iceberg::expected_detail::is_error_type_valid_v = is_error_type_valid<T>::value
 
constexpr unexpect_t iceberg::unexpect {}
 
constexpr construct_from_expected_t iceberg::expected_detail::construct_from_expected {}
 
constexpr construct_with_invoke_result_t iceberg::expected_detail::construct_with_invoke_result {}
 
template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_copy_assignable_v
 
template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_trivially_copy_assignable_v
 
template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_move_assignable_v
 
template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_trivially_move_assignable_v
 

Detailed Description

A C++20 backport of C++23 std::expected, used as the storage type behind iceberg::Result.

Purpose: the library is developed and built as C++23. Compatibility-mode packages additionally support C++20 consumers. iceberg::Result<T> (see iceberg/result.h) uses the same iceberg::expected type in both package modes rather than selecting a storage type per translation unit. The API mirrors std::expected (including the monadic and_then, or_else, transform and transform_error), so code can be written as if against the standard type.

Upstream: https://github.com/zeus-cpp/expected (MIT), include/zeus/expected.hpp at tag v1.4.0 (f9dde3b062f1b3a5d1a9f2888e4b6f6d2303557b).

Local changes (search for "iceberg:" for the non-mechanical ones):

History:

Once C++23 can be required of all consumers, this header can be dropped and iceberg::Result aliased back to std::expected.

Variable Documentation

◆ is_copy_assignable_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_copy_assignable_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_copy_assignable<T>>

◆ is_copy_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_copy_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_copy_constructible<T>>

◆ is_default_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_default_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_default_constructible<T>>

◆ is_equality_result_convertible_to_bool_v

template<class Lhs , class Rhs >
constexpr bool iceberg::expected_detail::is_equality_result_convertible_to_bool_v
inlineconstexpr
Initial value:
=
is_equality_result_convertible_to_bool<Lhs, Rhs>::value

◆ is_expected_copy_assignable_v

template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_copy_assignable_v
inlineconstexpr
Initial value:
=
is_copy_assignable_or_void_v<T> && is_copy_constructible_or_void_v<T> &&
std::is_copy_assignable_v<E> && std::is_copy_constructible_v<E> &&
(is_nothrow_move_constructible_or_void_v<T> ||
std::is_nothrow_move_constructible_v<E>)

◆ is_expected_move_assignable_v

template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_move_assignable_v
inlineconstexpr
Initial value:
=
is_move_assignable_or_void_v<T> && is_move_constructible_or_void_v<T> &&
std::is_move_assignable_v<E> && std::is_move_constructible_v<E> &&
(is_nothrow_move_constructible_or_void_v<T> ||
std::is_nothrow_move_constructible_v<E>)

◆ is_expected_trivially_copy_assignable_v

template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_trivially_copy_assignable_v
inlineconstexpr
Initial value:
=
is_trivially_copy_constructible_or_void_v<T> &&
is_trivially_copy_assignable_or_void_v<T> && is_trivially_destructible_or_void_v<T> &&
std::is_trivially_copy_constructible_v<E> && std::is_trivially_copy_assignable_v<E> &&
std::is_trivially_destructible_v<E>

◆ is_expected_trivially_move_assignable_v

template<class T , class E >
constexpr bool iceberg::expected_detail::is_expected_trivially_move_assignable_v
inlineconstexpr
Initial value:
=
is_trivially_move_constructible_or_void_v<T> &&
is_trivially_move_assignable_or_void_v<T> && is_trivially_destructible_or_void_v<T> &&
std::is_trivially_move_constructible_v<E> && std::is_trivially_move_assignable_v<E> &&
std::is_trivially_destructible_v<E>

◆ is_move_assignable_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_move_assignable_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_move_assignable<T>>

◆ is_move_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_move_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_move_constructible<T>>

◆ is_nothrow_convertible_v

template<class From , class To >
constexpr bool iceberg::expected_detail::is_nothrow_convertible_v
inlineconstexpr
Initial value:
=
noexcept(static_cast<To>(std::declval<From>()))

◆ is_nothrow_copy_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_nothrow_copy_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_nothrow_copy_constructible<T>>

◆ is_nothrow_equality_result_convertible_to_bool_v

template<class Lhs , class Rhs >
constexpr bool iceberg::expected_detail::is_nothrow_equality_result_convertible_to_bool_v
inlineconstexpr
Initial value:
=
is_nothrow_equality_result_convertible_to_bool<Lhs, Rhs>::value

◆ is_nothrow_move_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_nothrow_move_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_nothrow_move_constructible<T>>

◆ is_specialization_v

template<class T , template< class... > class Template>
constexpr bool iceberg::expected_detail::is_specialization_v
inlineconstexpr
Initial value:
=
false

◆ is_trivially_copy_assignable_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_trivially_copy_assignable_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_trivially_copy_assignable<T>>

◆ is_trivially_copy_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_trivially_copy_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_trivially_copy_constructible<T>>

◆ is_trivially_destructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_trivially_destructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_trivially_destructible<T>>

◆ is_trivially_move_assignable_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_trivially_move_assignable_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_trivially_move_assignable<T>>

◆ is_trivially_move_constructible_or_void_v

template<class T >
constexpr bool iceberg::expected_detail::is_trivially_move_constructible_or_void_v
inlineconstexpr
Initial value:
=
is_void_or_v<T, std::is_trivially_move_constructible<T>>