[libc-commits] [PATCH] D107987: [libc][nfc] add CPP Limits.h for numeric_limits
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Aug 12 14:31:26 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG472fa04de8f3: [libc][nfc] add CPP Limits.h for numeric_limits (authored by michaelrj).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107987/new/
https://reviews.llvm.org/D107987
Files:
libc/utils/CPP/CMakeLists.txt
libc/utils/CPP/Limits.h
Index: libc/utils/CPP/Limits.h
===================================================================
--- /dev/null
+++ libc/utils/CPP/Limits.h
@@ -0,0 +1,59 @@
+//===-- A self contained equivalent of std::limits --------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_UTILS_CPP_LIMITS_H
+#define LLVM_LIBC_UTILS_CPP_LIMITS_H
+
+#include <limits.h>
+
+namespace __llvm_libc {
+namespace cpp {
+
+template <class T> class NumericLimits {
+public:
+ static constexpr T max();
+ static constexpr T min();
+};
+
+// TODO: Add NumericLimits specializations as needed for new types.
+
+template <> class NumericLimits<int> {
+public:
+ static constexpr int max() { return INT_MAX; }
+ static constexpr int min() { return INT_MIN; }
+};
+template <> class NumericLimits<unsigned int> {
+public:
+ static constexpr unsigned int max() { return UINT_MAX; }
+ static constexpr unsigned int min() { return 0; }
+};
+template <> class NumericLimits<long> {
+public:
+ static constexpr long max() { return LONG_MAX; }
+ static constexpr long min() { return LONG_MIN; }
+};
+template <> class NumericLimits<unsigned long> {
+public:
+ static constexpr long max() { return ULONG_MAX; }
+ static constexpr long min() { return 0; }
+};
+template <> class NumericLimits<long long> {
+public:
+ static constexpr long long max() { return LLONG_MAX; }
+ static constexpr long long min() { return LLONG_MIN; }
+};
+template <> class NumericLimits<unsigned long long> {
+public:
+ static constexpr long max() { return ULLONG_MAX; }
+ static constexpr long min() { return 0; }
+};
+
+} // namespace cpp
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_UTILS_CPP_LIMITS_H
Index: libc/utils/CPP/CMakeLists.txt
===================================================================
--- libc/utils/CPP/CMakeLists.txt
+++ libc/utils/CPP/CMakeLists.txt
@@ -7,4 +7,5 @@
Functional.h
StringView.h
TypeTraits.h
+ Limits.h
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107987.366103.patch
Type: text/x-patch
Size: 2208 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210812/0453ba76/attachment.bin>
More information about the libc-commits
mailing list