3#include <StormByte/type_traits.hxx>
28 template <
typename T,
class E>
31 std::expected<std::reference_wrapper<std::remove_reference_t<T>>, std::shared_ptr<E>>,
32 std::expected<T, std::shared_ptr<E>>
45 return std::unexpected<std::shared_ptr<E>>(std::move(error_ptr));
58 return std::unexpected<std::shared_ptr<std::decay_t<E>>>(
59 std::make_shared<std::decay_t<E>>(std::forward<E>(error))
70 template <
typename Base,
typename Derived>
71 auto Unexpected(Derived&& error) -> std::unexpected<std::shared_ptr<Base>>
72 requires std::is_base_of_v<Base, std::decay_t<Derived>>
74 using DerivedT = std::decay_t<Derived>;
75 return std::unexpected<std::shared_ptr<Base>>(std::static_pointer_cast<Base>(std::make_shared<DerivedT>(std::forward<Derived>(error))));
89 template <
typename E,
typename... Args>
90 auto Unexpected(
const std::string& fmt, Args&&... args) {
91 std::string formatted_message;
93 if constexpr (
sizeof...(Args) == 0) {
95 formatted_message = fmt;
98 auto format_args = std::make_format_args(args...);
101 formatted_message = std::vformat(fmt, format_args);
105 return std::unexpected<std::shared_ptr<E>>(
106 std::make_shared<E>(std::move(formatted_message))
Concept to check if a type is a reference.
Definition type_traits.hxx:135
Main namespace for the StormByte library.
auto Unexpected(std::shared_ptr< E > error_ptr)
Creates an std::unexpected with a shared pointer to the error.
Definition expected.hxx:44
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
Expected type with support for reference types.
Definition expected.hxx:33