|
|
@@ -1,4 +1,5 @@
|
|
|
#pragma once
|
|
|
+// NOLINTBEGIN(readability-identifier-naming)
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
@@ -27,13 +28,14 @@ inline constexpr struct unexpect_t {
|
|
|
template <typename E> class unexpected {
|
|
|
public:
|
|
|
template <typename Err = E>
|
|
|
- constexpr explicit unexpected(Err && e) : error_(std::forward<Err>(e)) {}
|
|
|
+ requires(not std::same_as<E, unexpected<E>>)
|
|
|
+ constexpr explicit unexpected(Err && err) : error_(std::forward<Err>(err)) {}
|
|
|
template <typename... Args>
|
|
|
constexpr explicit unexpected(std::in_place_t, Args &&... args)
|
|
|
: error_{std::forward<Args>(args)...} {}
|
|
|
template <typename U, typename... Args>
|
|
|
- constexpr explicit unexpected(std::in_place_t, std::initializer_list<U> il, Args &&... args)
|
|
|
- : error_{il, std::forward<Args>(args)...} {}
|
|
|
+ constexpr explicit unexpected(std::in_place_t, std::initializer_list<U> init, Args &&... args)
|
|
|
+ : error_{init, std::forward<Args>(args)...} {}
|
|
|
|
|
|
constexpr const E & error() const & noexcept { return error_; }
|
|
|
constexpr E & error() & noexcept { return error_; }
|
|
|
@@ -44,12 +46,13 @@ public:
|
|
|
swap(error(), other.error());
|
|
|
}
|
|
|
|
|
|
- template <typename E2> friend constexpr bool operator==(unexpected & x, unexpected<E2> & y) {
|
|
|
- return x.error() == y.error();
|
|
|
+ template <typename E2>
|
|
|
+ friend constexpr bool operator==(unexpected const & lhs, unexpected<E2> const & rhs) {
|
|
|
+ return lhs.error() == rhs.error();
|
|
|
}
|
|
|
|
|
|
- friend constexpr void swap(unexpected & x, unexpected & y) noexcept(noexcept(x.swap(y))) {
|
|
|
- return x.swap(y);
|
|
|
+ friend constexpr void swap(unexpected & lhs, unexpected & rhs) noexcept(noexcept(lhs.swap(rhs))) {
|
|
|
+ return lhs.swap(rhs);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -66,7 +69,7 @@ public:
|
|
|
|
|
|
template <typename E> class bad_expected_access : public bad_expected_access<void> {
|
|
|
public:
|
|
|
- bad_expected_access(E error) : error_(std::move(error)) {}
|
|
|
+ explicit bad_expected_access(E error) : error_(std::move(error)) {}
|
|
|
|
|
|
constexpr const E & error() const & noexcept { return error_; }
|
|
|
constexpr E & error() & noexcept { return error_; }
|
|
|
@@ -107,32 +110,33 @@ public:
|
|
|
}
|
|
|
|
|
|
template <typename U = std::remove_cv_t<T>>
|
|
|
- constexpr explicit(!std::is_convertible_v<U, T>) expected(U && v)
|
|
|
- : value_(std::in_place_index<0>, std::forward<T>(v)) {}
|
|
|
+ requires(not std::same_as<U, expected<T, E>>)
|
|
|
+ constexpr explicit(!std::is_convertible_v<U, T>) expected(U && val)
|
|
|
+ : value_(std::in_place_index<0>, std::forward<U>(val)) {}
|
|
|
|
|
|
template <typename G>
|
|
|
- constexpr explicit(!std::is_convertible_v<const G &, E>) expected(unexpected<G> const & e)
|
|
|
- : value_(std::in_place_index<1>, e.error()) {}
|
|
|
+ constexpr explicit(!std::is_convertible_v<const G &, E>) expected(unexpected<G> const & exp)
|
|
|
+ : value_(std::in_place_index<1>, exp.error()) {}
|
|
|
|
|
|
template <typename G>
|
|
|
- constexpr explicit(!std::is_convertible_v<G, E>) expected(unexpected<G> && e)
|
|
|
- : value_(std::in_place_index<1>, std::move(e).error()) {}
|
|
|
+ constexpr explicit(!std::is_convertible_v<G, E>) expected(unexpected<G> && exp)
|
|
|
+ : value_(std::in_place_index<1>, std::move(exp).error()) {}
|
|
|
|
|
|
template <typename... Args>
|
|
|
constexpr explicit expected(std::in_place_t, Args &&... args)
|
|
|
: value_(std::in_place_index<0>, std::forward<Args>(args)...) {}
|
|
|
|
|
|
template <typename U, typename... Args>
|
|
|
- constexpr explicit expected(std::in_place_t, std::initializer_list<U> il, Args &&... args)
|
|
|
- : value_(std::in_place_index<0>, il, std::forward<Args>(args)...) {}
|
|
|
+ constexpr explicit expected(std::in_place_t, std::initializer_list<U> init, Args &&... args)
|
|
|
+ : value_(std::in_place_index<0>, init, std::forward<Args>(args)...) {}
|
|
|
|
|
|
template <typename... Args>
|
|
|
constexpr explicit expected(unexpect_t, Args &&... args)
|
|
|
: value_(std::in_place_index<1>, std::forward<Args>(args)...) {}
|
|
|
|
|
|
template <typename U, typename... Args>
|
|
|
- constexpr explicit expected(unexpect_t, std::initializer_list<U> il, Args &&... args)
|
|
|
- : value_(std::in_place_index<1>, il, std::forward<Args>(args)...) {}
|
|
|
+ constexpr explicit expected(unexpect_t, std::initializer_list<U> init, Args &&... args)
|
|
|
+ : value_(std::in_place_index<1>, init, std::forward<Args>(args)...) {}
|
|
|
|
|
|
constexpr explicit operator bool() const noexcept { return has_value(); }
|
|
|
constexpr bool has_value() const noexcept { return value_.index() == 0; }
|
|
|
@@ -169,52 +173,52 @@ public:
|
|
|
constexpr E & error() & noexcept { return *std::get_if<1>(&value_); }
|
|
|
constexpr E && error() && noexcept { return std::move(*std::get_if<1>(&value_)); }
|
|
|
|
|
|
- template <typename F> constexpr auto transform(F && f) & {
|
|
|
+ template <typename F> constexpr auto transform(F && func) & {
|
|
|
using G = std::invoke_result_t<F, value_type &>;
|
|
|
if (has_value()) {
|
|
|
- return expected<G, error_type>(std::forward<F>(f)(**this));
|
|
|
+ return expected<G, error_type>(std::forward<F>(func)(**this));
|
|
|
}
|
|
|
return expected<G, error_type>(unexpect, error());
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform(F && f) const & {
|
|
|
+ template <typename F> constexpr auto transform(F && func) const & {
|
|
|
using G = std::invoke_result_t<F, value_type const &>;
|
|
|
if (has_value()) {
|
|
|
- return expected<G, error_type>(std::forward<F>(f)(**this));
|
|
|
+ return expected<G, error_type>(std::forward<F>(func)(**this));
|
|
|
}
|
|
|
return expected<G, error_type>(unexpect, error());
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform(F && f) && {
|
|
|
+ template <typename F> constexpr auto transform(F && func) && {
|
|
|
using G = std::invoke_result_t<F, value_type>;
|
|
|
if (has_value()) {
|
|
|
- return expected<G, error_type>(std::forward<F>(f)(*std::move(*this)));
|
|
|
+ return expected<G, error_type>(std::forward<F>(func)(*std::move(*this)));
|
|
|
}
|
|
|
return expected<G, error_type>(unexpect, std::move(*this).error());
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform_error(F && f) & {
|
|
|
+ template <typename F> constexpr auto transform_error(F && func) & {
|
|
|
using G = std::invoke_result_t<F, E &>;
|
|
|
if (has_value()) {
|
|
|
return expected<value_type, G>(**this);
|
|
|
}
|
|
|
- return expected<value_type, G>(unexpect, std::forward<F>(f)(error()));
|
|
|
+ return expected<value_type, G>(unexpect, std::forward<F>(func)(error()));
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform_error(F && f) const & {
|
|
|
+ template <typename F> constexpr auto transform_error(F && func) const & {
|
|
|
using G = std::invoke_result_t<F, E const &>;
|
|
|
if (has_value()) {
|
|
|
return expected<value_type, G>(**this);
|
|
|
}
|
|
|
- return expected<value_type, G>(unexpect, std::forward<F>(f)(error()));
|
|
|
+ return expected<value_type, G>(unexpect, std::forward<F>(func)(error()));
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform_error(F && f) && {
|
|
|
+ template <typename F> constexpr auto transform_error(F && func) && {
|
|
|
using G = std::invoke_result_t<F, E>;
|
|
|
if (has_value()) {
|
|
|
return expected<value_type, G>(*std::move(*this));
|
|
|
}
|
|
|
- return expected<value_type, G>(unexpect, std::forward<F>(f)(std::move(*this).error()));
|
|
|
+ return expected<value_type, G>(unexpect, std::forward<F>(func)(std::move(*this).error()));
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -247,12 +251,12 @@ public:
|
|
|
}
|
|
|
|
|
|
template <typename G>
|
|
|
- constexpr explicit(!std::is_convertible_v<const G &, E>) expected(unexpected<G> const & e)
|
|
|
- : value_(e.error()) {}
|
|
|
+ constexpr explicit(!std::is_convertible_v<const G &, E>) expected(unexpected<G> const & exp)
|
|
|
+ : value_(exp.error()) {}
|
|
|
|
|
|
template <typename G>
|
|
|
- constexpr explicit(!std::is_convertible_v<G, E>) expected(unexpected<G> && e)
|
|
|
- : value_(std::move(e).error()) {}
|
|
|
+ constexpr explicit(!std::is_convertible_v<G, E>) expected(unexpected<G> && exp)
|
|
|
+ : value_(std::move(exp).error()) {}
|
|
|
|
|
|
constexpr explicit expected(std::in_place_t) {}
|
|
|
|
|
|
@@ -261,8 +265,8 @@ public:
|
|
|
: value_(std::in_place, std::forward<Args>(args)...) {}
|
|
|
|
|
|
template <typename U, typename... Args>
|
|
|
- constexpr explicit expected(unexpect_t, std::initializer_list<U> il, Args &&... args)
|
|
|
- : value_(std::in_place, il, std::forward<Args>(args)...) {}
|
|
|
+ constexpr explicit expected(unexpect_t, std::initializer_list<U> init, Args &&... args)
|
|
|
+ : value_(std::in_place, init, std::forward<Args>(args)...) {}
|
|
|
|
|
|
constexpr explicit operator bool() const noexcept { return has_value(); }
|
|
|
constexpr bool has_value() const noexcept { return not value_.has_value(); }
|
|
|
@@ -287,52 +291,52 @@ public:
|
|
|
constexpr E & error() & noexcept { return *value_; }
|
|
|
constexpr E && error() && noexcept { return std::move(*value_); }
|
|
|
|
|
|
- template <typename F> constexpr auto transform(F && f) & {
|
|
|
+ template <typename F> constexpr auto transform(F && func) & {
|
|
|
using G = std::invoke_result_t<F>;
|
|
|
if (has_value()) {
|
|
|
- return expected<G, error_type>(std::forward<F>(f)());
|
|
|
+ return expected<G, error_type>(std::forward<F>(func)());
|
|
|
}
|
|
|
return expected<G, error_type>(unexpect, error());
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform(F && f) const & {
|
|
|
+ template <typename F> constexpr auto transform(F && func) const & {
|
|
|
using G = std::invoke_result_t<F>;
|
|
|
if (has_value()) {
|
|
|
- return expected<G, error_type>(std::forward<F>(f)());
|
|
|
+ return expected<G, error_type>(std::forward<F>(func)());
|
|
|
}
|
|
|
return expected<G, error_type>(unexpect, error());
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform(F && f) && {
|
|
|
+ template <typename F> constexpr auto transform(F && func) && {
|
|
|
using G = std::invoke_result_t<F>;
|
|
|
if (has_value()) {
|
|
|
- return expected<G, error_type>(std::forward<F>(f)());
|
|
|
+ return expected<G, error_type>(std::forward<F>(func)());
|
|
|
}
|
|
|
return expected<G, error_type>(unexpect, std::move(*this).error());
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform_error(F && f) & {
|
|
|
+ template <typename F> constexpr auto transform_error(F && func) & {
|
|
|
using G = std::invoke_result_t<F, E &>;
|
|
|
if (has_value()) {
|
|
|
return expected<value_type, G>(**this);
|
|
|
}
|
|
|
- return expected<value_type, G>(unexpect, std::forward<F>(f)(error()));
|
|
|
+ return expected<value_type, G>(unexpect, std::forward<F>(func)(error()));
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform_error(F && f) const & {
|
|
|
+ template <typename F> constexpr auto transform_error(F && func) const & {
|
|
|
using G = std::invoke_result_t<F, E const &>;
|
|
|
if (has_value()) {
|
|
|
return expected<value_type, G>(**this);
|
|
|
}
|
|
|
- return expected<value_type, G>(unexpect, std::forward<F>(f)(error()));
|
|
|
+ return expected<value_type, G>(unexpect, std::forward<F>(func)(error()));
|
|
|
}
|
|
|
|
|
|
- template <typename F> constexpr auto transform_error(F && f) && {
|
|
|
+ template <typename F> constexpr auto transform_error(F && func) && {
|
|
|
using G = std::invoke_result_t<F, E>;
|
|
|
if (has_value()) {
|
|
|
return expected<value_type, G>(*std::move(*this));
|
|
|
}
|
|
|
- return expected<value_type, G>(unexpect, std::forward<F>(f)(std::move(*this).error()));
|
|
|
+ return expected<value_type, G>(unexpect, std::forward<F>(func)(std::move(*this).error()));
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
@@ -342,5 +346,6 @@ private:
|
|
|
#endif
|
|
|
|
|
|
namespace jvalidate::detail {
|
|
|
-inline std::string to_message(std::errc ec) { return std::make_error_code(ec).message(); }
|
|
|
+inline std::string to_message(std::errc ecode) { return std::make_error_code(ecode).message(); }
|
|
|
}
|
|
|
+// NOLINTEND(readability-identifier-naming)
|