diff include/core/date.h @ 196:f0ff06a45c42

date: use std::optional for values
author Paper <mrpapersonic@gmail.com>
date Thu, 07 Dec 2023 16:28:11 -0500
parents 9613d72b097e
children c4ca035c565d
line wrap: on
line diff
--- a/include/core/date.h	Thu Dec 07 11:14:01 2023 -0500
+++ b/include/core/date.h	Thu Dec 07 16:28:11 2023 -0500
@@ -3,6 +3,8 @@
 
 #include "json/json_fwd.hpp"
 
+#include <optional>
+
 class QDate;
 
 class Date {
@@ -30,23 +32,9 @@
 		bool operator>=(const Date& other) const;
 
 	private:
-		/* this implementation sucks and we should really use a struct instead */
-		template<typename T>
-		struct OptionalNumber {
-			public:
-				T Get() const { return enabled ? num : 0; }
-				bool Enabled() const { return enabled; }
-				void Set(T n) { num = n; enabled = true; }
-				void Void() { num = 0; enabled = false; }
-
-			protected:
-				T num = 0;
-				bool enabled = false;
-		};
-
-		OptionalNumber<unsigned int> year;
-		OptionalNumber<unsigned int> month;
-		OptionalNumber<unsigned int> day;
+		std::optional<unsigned int> year;
+		std::optional<unsigned int> month;
+		std::optional<unsigned int> day;
 };
 
 #endif // __core__date_h