pitrou commented on code in PR #55457:
URL: https://github.com/apache/arrow/pull/55457#discussion_r4514839495


##########
cpp/src/parquet/column_reader.cc:
##########
@@ -83,10 +83,28 @@ inline void CheckNumberDecoded(int64_t number_decoded, 
int64_t expected) {
   }
 }
 
-/// True if a T can hold a U.
+/// True if an integer type T can hold every value of integer type U.
+///
+/// Written in terms of std::numeric_limits rather than std::in_range because
+/// the libc++ in the macOS 11.3 SDK used by CRAN does not provide the latter.
+template <typename T, typename U>
+struct CanHold {
+  static_assert(std::is_integral_v<T> && std::is_integral_v<U>,
+                "can_hold_v is only defined for integer types");
+  static constexpr bool value =
+      std::numeric_limits<T>::digits >= std::numeric_limits<U>::digits &&
+      (std::is_signed_v<T> || !std::is_signed_v<U>);
+};
+
 template <typename T, typename U>
-inline constexpr bool can_hold_v = 
std::in_range<T>(std::numeric_limits<U>::min()) &&
-                                   
std::in_range<T>(std::numeric_limits<U>::max());
+inline constexpr bool can_hold_v = CanHold<T, U>::value;
+
+static_assert(can_hold_v<int64_t, int32_t>);
+static_assert(can_hold_v<int64_t, uint32_t>);
+static_assert(can_hold_v<int32_t, int32_t>);
+static_assert(!can_hold_v<int32_t, int64_t>);
+static_assert(!can_hold_v<int32_t, uint32_t>);

Review Comment:
   The converse should hold true as well?
   ```suggestion
   static_assert(!can_hold_v<int32_t, uint32_t>);
   static_assert(!can_hold_v<uint32_t, int32_t>);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to