Преглед на файлове

Simplify how numeric values are read/pushed

No longer check if numeric types will be truncated.
Ole преди 9 години
родител
ревизия
74408f7cbe
променени са 2 файла, в които са добавени 16 реда и са изтрити 70 реда
  1. 3 44
      lib/luwra/types.hpp
  2. 13 26
      tests/types.cpp

+ 3 - 44
lib/luwra/types.hpp

@@ -173,20 +173,12 @@ namespace internal {
 		}
 	};
 
-	// Base for `Value<I>` specializations which uses `B` as transport unit, where `I` is smaller
-	// than `B`.
+	// Base for `Value<I>` specializations which uses `B` as transport unit
 	template <typename I, typename B>
-	struct NumericContainedValueBase {
-		static constexpr
-		bool qualifies =
-			// TODO: Remove warning about comparsion between signed and unsigned integers
-			std::numeric_limits<I>::max() <= std::numeric_limits<B>::max()
-			&& std::numeric_limits<I>::lowest() >= std::numeric_limits<B>::lowest();
-
+	struct NumericValueBase {
 		static inline
 		I read(State* state, int index) {
-			return
-				static_cast<I>(NumericTransportValue<B>::read(state, index));
+			return static_cast<I>(NumericTransportValue<B>::read(state, index));
 		}
 
 		static inline
@@ -195,39 +187,6 @@ namespace internal {
 			return 1;
 		}
 	};
-
-	// Base for `Value<I>` specializations which uses `B` as transport unit, where `I` is bigger
-	// than `B`.
-	template <typename I, typename B>
-	struct NumericTruncatingValueBase {
-		static inline
-		I read(State* state, int index) {
-			return static_cast<I>(NumericTransportValue<B>::read(state, index));
-		}
-
-		static inline
-		size_t push(State*, I) {
-			static_assert(
-				sizeof(I) == -1,
-				"You must not use 'Value<I>::push' specializations which inherit from NumericTruncatingValueBase"
-			);
-
-			return -1;
-		}
-	};
-
-	// Base for `Value<I>` specializations which uses `B` as transport unit
-	template <typename I, typename B>
-	using NumericValueBase =
-		typename std::conditional<
-			std::is_same<I, B>::value,
-			NumericTransportValue<B>,
-			typename std::conditional<
-				NumericContainedValueBase<I, B>::qualifies,
-				NumericContainedValueBase<I, B>,
-				NumericTruncatingValueBase<I, B>
-			>::type
-		>::type;
 }
 
 /**

+ 13 - 26
tests/types.cpp

@@ -30,38 +30,25 @@ struct NumericTest {
 	}
 };
 
-struct TautologyTest {
-	static
-	void test(lua_State*) {}
-};
-
-template <typename B, typename I>
-using SelectNumericTest =
-	typename std::conditional<
-		luwra::internal::NumericContainedValueBase<I, B>::qualifies,
-		NumericTest<I>,
-		TautologyTest
-	>::type;
-
 TEST_CASE("NumberLimits") {
 	luwra::StateWrapper state;
 
 	// Integer-based types
-	SelectNumericTest<lua_Integer, signed char>::test(state);
-	SelectNumericTest<lua_Integer, unsigned char>::test(state);
-	SelectNumericTest<lua_Integer, signed short>::test(state);
-	SelectNumericTest<lua_Integer, unsigned short>::test(state);
-	SelectNumericTest<lua_Integer, signed int>::test(state);
-	SelectNumericTest<lua_Integer, unsigned int>::test(state);
-	SelectNumericTest<lua_Integer, signed long int>::test(state);
-	SelectNumericTest<lua_Integer, unsigned long int>::test(state);
-	SelectNumericTest<lua_Integer, signed long long int>::test(state);
-	SelectNumericTest<lua_Integer, unsigned long long int>::test(state);
+	NumericTest<signed char>::test(state);
+	NumericTest<unsigned char>::test(state);
+	NumericTest<signed short>::test(state);
+	NumericTest<unsigned short>::test(state);
+	NumericTest<signed int>::test(state);
+	NumericTest<unsigned int>::test(state);
+	NumericTest<signed long int>::test(state);
+	NumericTest<unsigned long int>::test(state);
+	NumericTest<signed long long int>::test(state);
+	NumericTest<unsigned long long int>::test(state);
 
 	// Number-based types
-	SelectNumericTest<lua_Number, float>::test(state);
-	SelectNumericTest<lua_Number, double>::test(state);
-	SelectNumericTest<lua_Number, long double>::test(state);
+	NumericTest<float>::test(state);
+	NumericTest<double>::test(state);
+	NumericTest<long double>::test(state);
 }
 
 #endif /* LUA_VERSION_NUM >= 503 */