[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 11:34:02 PDT 2021
michaelrj created this revision.
michaelrj added a reviewer: sivachandra.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added a project: libc-project.
michaelrj requested review of this revision.
Add an implementation of numeric_limits for use in str_conv_utils.
It currently only supports the basic integer types, with more types
coming as needed.
Repository:
rG LLVM Github Monorepo
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,57 @@
+//===-- 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
+
+namespace __llvm_libc {
+namespace cpp {
+
+#include <limits.h>
+
+template <class T> class numeric_limits {
+public:
+ static T max();
+ static T min();
+};
+
+template <> class numeric_limits<int> {
+public:
+ static int max() { return INT_MAX; }
+ static int min() { return INT_MIN; }
+};
+template <> class numeric_limits<unsigned int> {
+public:
+ static unsigned int max() { return UINT_MAX; }
+ static unsigned int min() { return 0; }
+};
+template <> class numeric_limits<long> {
+public:
+ static long max() { return LONG_MAX; }
+ static long min() { return LONG_MIN; }
+};
+template <> class numeric_limits<unsigned long> {
+public:
+ static long max() { return ULONG_MAX; }
+ static long min() { return 0; }
+};
+template <> class numeric_limits<long long> {
+public:
+ static long long max() { return LLONG_MAX; }
+ static long long min() { return LLONG_MIN; }
+};
+template <> class numeric_limits<unsigned long long> {
+public:
+ static long max() { return ULLONG_MAX; }
+ static 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.366055.patch
Type: text/x-patch
Size: 2004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210812/f88afa93/attachment.bin>
More information about the libc-commits
mailing list