Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions include/tl/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ template <class E> class unexpected {

constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {}

template <class... Args, typename std::enable_if<std::is_constructible<
E, Args &&...>::value>::type * = nullptr>
constexpr explicit unexpected(in_place_t, Args &&...args)
: m_val(std::forward<Args>(args)...) {}
template <
class U, class... Args,
typename std::enable_if<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value>::type * = nullptr>
constexpr explicit unexpected(in_place_t, std::initializer_list<U> l, Args &&...args)
: m_val(l, std::forward<Args>(args)...) {}

#ifndef TL_EXPECTED_STRICT
template <class... Args, typename std::enable_if<std::is_constructible<
E, Args &&...>::value>::type * = nullptr>
constexpr explicit unexpected(Args &&...args)
Expand All @@ -158,6 +170,7 @@ template <class E> class unexpected {
E, std::initializer_list<U> &, Args &&...>::value>::type * = nullptr>
constexpr explicit unexpected(std::initializer_list<U> l, Args &&...args)
: m_val(l, std::forward<Args>(args)...) {}
#endif

constexpr const E &value() const & { return m_val; }
TL_EXPECTED_11_CONSTEXPR E &value() & { return m_val; }
Expand Down Expand Up @@ -465,15 +478,15 @@ struct expected_storage_base {
detail::enable_if_t<std::is_constructible<E, Args &&...>::value> * =
nullptr>
constexpr explicit expected_storage_base(unexpect_t, Args &&...args)
: m_unexpect(std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, std::forward<Args>(args)...), m_has_val(false) {}

template <class U, class... Args,
detail::enable_if_t<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
constexpr explicit expected_storage_base(unexpect_t,
std::initializer_list<U> il,
Args &&...args)
: m_unexpect(il, std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, il, std::forward<Args>(args)...), m_has_val(false) {}

~expected_storage_base() {
if (m_has_val) {
Expand Down Expand Up @@ -512,15 +525,15 @@ template <class T, class E> struct expected_storage_base<T, E, true, true> {
detail::enable_if_t<std::is_constructible<E, Args &&...>::value> * =
nullptr>
constexpr explicit expected_storage_base(unexpect_t, Args &&...args)
: m_unexpect(std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, std::forward<Args>(args)...), m_has_val(false) {}

template <class U, class... Args,
detail::enable_if_t<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
constexpr explicit expected_storage_base(unexpect_t,
std::initializer_list<U> il,
Args &&...args)
: m_unexpect(il, std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, il, std::forward<Args>(args)...), m_has_val(false) {}

~expected_storage_base() = default;
union {
Expand Down Expand Up @@ -553,15 +566,15 @@ template <class T, class E> struct expected_storage_base<T, E, true, false> {
detail::enable_if_t<std::is_constructible<E, Args &&...>::value> * =
nullptr>
constexpr explicit expected_storage_base(unexpect_t, Args &&...args)
: m_unexpect(std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, std::forward<Args>(args)...), m_has_val(false) {}

template <class U, class... Args,
detail::enable_if_t<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
constexpr explicit expected_storage_base(unexpect_t,
std::initializer_list<U> il,
Args &&...args)
: m_unexpect(il, std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, il, std::forward<Args>(args)...), m_has_val(false) {}

~expected_storage_base() {
if (!m_has_val) {
Expand Down Expand Up @@ -598,15 +611,15 @@ template <class T, class E> struct expected_storage_base<T, E, false, true> {
detail::enable_if_t<std::is_constructible<E, Args &&...>::value> * =
nullptr>
constexpr explicit expected_storage_base(unexpect_t, Args &&...args)
: m_unexpect(std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, std::forward<Args>(args)...), m_has_val(false) {}

template <class U, class... Args,
detail::enable_if_t<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
constexpr explicit expected_storage_base(unexpect_t,
std::initializer_list<U> il,
Args &&...args)
: m_unexpect(il, std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, il, std::forward<Args>(args)...), m_has_val(false) {}

~expected_storage_base() {
if (m_has_val) {
Expand Down Expand Up @@ -638,15 +651,15 @@ template <class E> struct expected_storage_base<void, E, false, true> {
detail::enable_if_t<std::is_constructible<E, Args &&...>::value> * =
nullptr>
constexpr explicit expected_storage_base(unexpect_t, Args &&...args)
: m_unexpect(std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, std::forward<Args>(args)...), m_has_val(false) {}

template <class U, class... Args,
detail::enable_if_t<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
constexpr explicit expected_storage_base(unexpect_t,
std::initializer_list<U> il,
Args &&...args)
: m_unexpect(il, std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, il, std::forward<Args>(args)...), m_has_val(false) {}

~expected_storage_base() = default;
struct dummy {};
Expand All @@ -668,15 +681,15 @@ template <class E> struct expected_storage_base<void, E, false, false> {
detail::enable_if_t<std::is_constructible<E, Args &&...>::value> * =
nullptr>
constexpr explicit expected_storage_base(unexpect_t, Args &&...args)
: m_unexpect(std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, std::forward<Args>(args)...), m_has_val(false) {}

template <class U, class... Args,
detail::enable_if_t<std::is_constructible<
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
constexpr explicit expected_storage_base(unexpect_t,
std::initializer_list<U> il,
Args &&...args)
: m_unexpect(il, std::forward<Args>(args)...), m_has_val(false) {}
: m_unexpect(in_place, il, std::forward<Args>(args)...), m_has_val(false) {}

~expected_storage_base() {
if (!m_has_val) {
Expand Down