BAN: Add specialization for ErrorOr<LValueReference>
ErrorOr can now return a reference :)
This commit is contained in:
		
							parent
							
								
									2c52e0aad8
								
							
						
					
					
						commit
						8e31ef9905
					
				| 
						 | 
					@ -85,6 +85,33 @@ namespace BAN
 | 
				
			||||||
		Variant<Error, T> m_data;
 | 
							Variant<Error, T> m_data;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template<lvalue_reference T>
 | 
				
			||||||
 | 
						class [[nodiscard]] ErrorOr<T>
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						public:
 | 
				
			||||||
 | 
							ErrorOr(T value)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								m_data.template set<T>(value);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							ErrorOr(Error&& error)
 | 
				
			||||||
 | 
								: m_data(move(error))
 | 
				
			||||||
 | 
							{ }
 | 
				
			||||||
 | 
							ErrorOr(const Error& error)
 | 
				
			||||||
 | 
								: m_data(error)
 | 
				
			||||||
 | 
							{ }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							bool is_error() const			{ return m_data.template has<Error>(); }
 | 
				
			||||||
 | 
							Error& error()					{ return m_data.template get<Error>(); }
 | 
				
			||||||
 | 
							const Error& error() const		{ return m_data.template get<Error>(); }
 | 
				
			||||||
 | 
							T value()						{ return m_data.template get<T>(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Error release_error()			{ return move(error()); m_data.clear(); }
 | 
				
			||||||
 | 
							T release_value()				{ return value(); m_data.clear(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private:
 | 
				
			||||||
 | 
							Variant<Error, T> m_data;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	template<>
 | 
						template<>
 | 
				
			||||||
	class [[nodiscard]] ErrorOr<void>
 | 
						class [[nodiscard]] ErrorOr<void>
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,6 +40,7 @@ namespace BAN
 | 
				
			||||||
	template<typename T> struct is_lvalue_reference		: false_type {};
 | 
						template<typename T> struct is_lvalue_reference		: false_type {};
 | 
				
			||||||
	template<typename T> struct is_lvalue_reference<T&>	: true_type {};
 | 
						template<typename T> struct is_lvalue_reference<T&>	: true_type {};
 | 
				
			||||||
	template<typename T> inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
 | 
						template<typename T> inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
 | 
				
			||||||
 | 
						template<typename T> concept lvalue_reference = is_lvalue_reference_v<T>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	template<typename T> struct is_integral { static constexpr bool value = requires (T t, T* p, void (*f)(T)) { reinterpret_cast<T>(t); f(0); p + t; }; };
 | 
						template<typename T> struct is_integral { static constexpr bool value = requires (T t, T* p, void (*f)(T)) { reinterpret_cast<T>(t); f(0); p + t; }; };
 | 
				
			||||||
	template<typename T> inline constexpr bool is_integral_v = is_integral<T>::value;
 | 
						template<typename T> inline constexpr bool is_integral_v = is_integral<T>::value;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue