BAN: Make ErrorOr<> have attribute [[nodiscard]]
We don't have to specify it everytime we make function return ErrorOr
This commit is contained in:
		
							parent
							
								
									feaeee11e5
								
							
						
					
					
						commit
						247f03c79e
					
				|  | @ -38,7 +38,7 @@ namespace BAN | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	template<typename T> | 	template<typename T> | ||||||
| 	class ErrorOr | 	class [[nodiscard]] ErrorOr | ||||||
| 	{ | 	{ | ||||||
| 	public: | 	public: | ||||||
| 		ErrorOr(const T& value)		: m_has_error(false)	{ m_data = (void*)new T(value); } | 		ErrorOr(const T& value)		: m_has_error(false)	{ m_data = (void*)new T(value); } | ||||||
|  | @ -56,7 +56,7 @@ namespace BAN | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	template<> | 	template<> | ||||||
| 	class ErrorOr<void> | 	class [[nodiscard]] ErrorOr<void> | ||||||
| 	{ | 	{ | ||||||
| 	public: | 	public: | ||||||
| 		ErrorOr()														{ } | 		ErrorOr()														{ } | ||||||
|  |  | ||||||
|  | @ -28,8 +28,8 @@ namespace BAN | ||||||
| 		HashSet<T, HASH>& operator=(const HashSet<T, HASH>&); | 		HashSet<T, HASH>& operator=(const HashSet<T, HASH>&); | ||||||
| 		HashSet<T, HASH>& operator=(HashSet<T, HASH>&&); | 		HashSet<T, HASH>& operator=(HashSet<T, HASH>&&); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(const T&); | 		ErrorOr<void> insert(const T&); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(T&&); | 		ErrorOr<void> insert(T&&); | ||||||
| 		void remove(const T&); | 		void remove(const T&); | ||||||
| 		void clear(); | 		void clear(); | ||||||
| 
 | 
 | ||||||
|  | @ -42,7 +42,7 @@ namespace BAN | ||||||
| 		bool empty() const; | 		bool empty() const; | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		[[nodiscard]] ErrorOr<void> rebucket(size_type); | 		ErrorOr<void> rebucket(size_type); | ||||||
| 		Vector<T>& get_bucket(const T&); | 		Vector<T>& get_bucket(const T&); | ||||||
| 		const Vector<T>& get_bucket(const T&) const; | 		const Vector<T>& get_bucket(const T&) const; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -28,14 +28,14 @@ namespace BAN | ||||||
| 		LinkedList<T>& operator=(const LinkedList<T>&); | 		LinkedList<T>& operator=(const LinkedList<T>&); | ||||||
| 		LinkedList<T>& operator=(LinkedList<T>&&); | 		LinkedList<T>& operator=(LinkedList<T>&&); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> push_back(const T&); | 		ErrorOr<void> push_back(const T&); | ||||||
| 		[[nodiscard]] ErrorOr<void> push_back(T&&); | 		ErrorOr<void> push_back(T&&); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(iterator, const T&); | 		ErrorOr<void> insert(iterator, const T&); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(iterator, T&&); | 		ErrorOr<void> insert(iterator, T&&); | ||||||
| 		template<typename... Args> | 		template<typename... Args> | ||||||
| 		[[nodiscard]] ErrorOr<void> emplace_back(Args&&...); | 		ErrorOr<void> emplace_back(Args&&...); | ||||||
| 		template<typename... Args> | 		template<typename... Args> | ||||||
| 		[[nodiscard]] ErrorOr<void> emplace(iterator, Args&&...); | 		ErrorOr<void> emplace(iterator, Args&&...); | ||||||
| 
 | 
 | ||||||
| 		void pop_back(); | 		void pop_back(); | ||||||
| 		void remove(iterator); | 		void remove(iterator); | ||||||
|  | @ -64,7 +64,7 @@ namespace BAN | ||||||
| 			Node* prev; | 			Node* prev; | ||||||
| 		}; | 		}; | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<Node*> allocate_node() const; | 		ErrorOr<Node*> allocate_node() const; | ||||||
| 
 | 
 | ||||||
| 		Node* m_data = nullptr; | 		Node* m_data = nullptr; | ||||||
| 		Node* m_last = nullptr; | 		Node* m_last = nullptr; | ||||||
|  |  | ||||||
|  | @ -24,10 +24,10 @@ namespace BAN | ||||||
| 		Queue<T>& operator=(Queue<T>&&); | 		Queue<T>& operator=(Queue<T>&&); | ||||||
| 		Queue<T>& operator=(const Queue<T>&); | 		Queue<T>& operator=(const Queue<T>&); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> push(T&&); | 		ErrorOr<void> push(T&&); | ||||||
| 		[[nodiscard]] ErrorOr<void> push(const T&); | 		ErrorOr<void> push(const T&); | ||||||
| 		template<typename... Args> | 		template<typename... Args> | ||||||
| 		[[nodiscard]] ErrorOr<void> emplace(Args&&...); | 		ErrorOr<void> emplace(Args&&...); | ||||||
| 
 | 
 | ||||||
| 		void pop(); | 		void pop(); | ||||||
| 		void clear(); | 		void clear(); | ||||||
|  | @ -39,7 +39,7 @@ namespace BAN | ||||||
| 		T& front(); | 		T& front(); | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		[[nodiscard]] ErrorOr<void> ensure_capacity(size_type size); | 		ErrorOr<void> ensure_capacity(size_type size); | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		T*			m_data		= nullptr; | 		T*			m_data		= nullptr; | ||||||
|  |  | ||||||
|  | @ -25,11 +25,11 @@ namespace BAN | ||||||
| 		String& operator=(String&&); | 		String& operator=(String&&); | ||||||
| 		String& operator=(StringView); | 		String& operator=(StringView); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> push_back(char); | 		ErrorOr<void> push_back(char); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(char, size_type); | 		ErrorOr<void> insert(char, size_type); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(StringView, size_type); | 		ErrorOr<void> insert(StringView, size_type); | ||||||
| 		[[nodiscard]] ErrorOr<void> append(StringView); | 		ErrorOr<void> append(StringView); | ||||||
| 		[[nodiscard]] ErrorOr<void> append(const String&); | 		ErrorOr<void> append(const String&); | ||||||
| 		 | 		 | ||||||
| 		void pop_back(); | 		void pop_back(); | ||||||
| 		void remove(size_type); | 		void remove(size_type); | ||||||
|  | @ -44,8 +44,8 @@ namespace BAN | ||||||
| 		bool operator==(StringView) const; | 		bool operator==(StringView) const; | ||||||
| 		bool operator==(const char*) const; | 		bool operator==(const char*) const; | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> resize(size_type, char = '\0'); | 		ErrorOr<void> resize(size_type, char = '\0'); | ||||||
| 		[[nodiscard]] ErrorOr<void> reserve(size_type); | 		ErrorOr<void> reserve(size_type); | ||||||
| 
 | 
 | ||||||
| 		StringView sv() const; | 		StringView sv() const; | ||||||
| 
 | 
 | ||||||
|  | @ -56,9 +56,9 @@ namespace BAN | ||||||
| 		const char* data() const; | 		const char* data() const; | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		[[nodiscard]] ErrorOr<void> ensure_capacity(size_type); | 		ErrorOr<void> ensure_capacity(size_type); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> copy_impl(StringView); | 		ErrorOr<void> copy_impl(StringView); | ||||||
| 		void move_impl(String&&); | 		void move_impl(String&&); | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
|  |  | ||||||
|  | @ -24,8 +24,8 @@ namespace BAN | ||||||
| 
 | 
 | ||||||
| 		StringView substring(size_type, size_type = -1) const; | 		StringView substring(size_type, size_type = -1) const; | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<Vector<StringView>> split(char, bool = false); | 		ErrorOr<Vector<StringView>> split(char, bool = false); | ||||||
| 		[[nodiscard]] ErrorOr<Vector<StringView>> split(bool(*comp)(char), bool = false); | 		ErrorOr<Vector<StringView>> split(bool(*comp)(char), bool = false); | ||||||
| 
 | 
 | ||||||
| 		char back() const; | 		char back() const; | ||||||
| 		char front() const; | 		char front() const; | ||||||
|  |  | ||||||
|  | @ -31,14 +31,14 @@ namespace BAN | ||||||
| 		Vector<T>& operator=(Vector<T>&&); | 		Vector<T>& operator=(Vector<T>&&); | ||||||
| 		Vector<T>& operator=(const Vector<T>&); | 		Vector<T>& operator=(const Vector<T>&); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> push_back(T&&); | 		ErrorOr<void> push_back(T&&); | ||||||
| 		[[nodiscard]] ErrorOr<void> push_back(const T&); | 		ErrorOr<void> push_back(const T&); | ||||||
| 		template<typename... Args> | 		template<typename... Args> | ||||||
| 		[[nodiscard]] ErrorOr<void> emplace_back(Args&&...); | 		ErrorOr<void> emplace_back(Args&&...); | ||||||
| 		template<typename... Args> | 		template<typename... Args> | ||||||
| 		[[nodiscard]] ErrorOr<void> emplace(size_type, Args&&...); | 		ErrorOr<void> emplace(size_type, Args&&...); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(size_type, T&&); | 		ErrorOr<void> insert(size_type, T&&); | ||||||
| 		[[nodiscard]] ErrorOr<void> insert(size_type, const T&); | 		ErrorOr<void> insert(size_type, const T&); | ||||||
| 		 | 		 | ||||||
| 		iterator begin()				{ return iterator      (m_data); } | 		iterator begin()				{ return iterator      (m_data); } | ||||||
| 		const_iterator begin() const	{ return const_iterator(m_data); } | 		const_iterator begin() const	{ return const_iterator(m_data); } | ||||||
|  | @ -62,15 +62,15 @@ namespace BAN | ||||||
| 		const T& front() const; | 		const T& front() const; | ||||||
| 		T& front(); | 		T& front(); | ||||||
| 
 | 
 | ||||||
| 		[[nodiscard]] ErrorOr<void> resize(size_type); | 		ErrorOr<void> resize(size_type); | ||||||
| 		[[nodiscard]] ErrorOr<void> reserve(size_type); | 		ErrorOr<void> reserve(size_type); | ||||||
| 
 | 
 | ||||||
| 		bool empty() const; | 		bool empty() const; | ||||||
| 		size_type size() const; | 		size_type size() const; | ||||||
| 		size_type capacity() const; | 		size_type capacity() const; | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		[[nodiscard]] ErrorOr<void> ensure_capacity(size_type); | 		ErrorOr<void> ensure_capacity(size_type); | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		T*			m_data		= nullptr; | 		T*			m_data		= nullptr; | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ namespace Kernel | ||||||
| 		const Thread& current_thread() const; | 		const Thread& current_thread() const; | ||||||
| 
 | 
 | ||||||
| 		template<typename... Args> | 		template<typename... Args> | ||||||
| 		[[nodiscard]] BAN::ErrorOr<void> add_thread(const BAN::Function<void(Args...)>& func, Args... args) | 		BAN::ErrorOr<void> add_thread(const BAN::Function<void(Args...)>& func, Args... args) | ||||||
| 		{ | 		{ | ||||||
| 			uintptr_t flags; | 			uintptr_t flags; | ||||||
| 			asm volatile("pushf; pop %0" : "=r"(flags)); | 			asm volatile("pushf; pop %0" : "=r"(flags)); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue