[libcxx-commits] [libcxx] a354fd5 - [libc++] Adds __utility/to_underlying.h.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sun Apr 25 04:27:27 PDT 2021


Author: Mark de Wever
Date: 2021-04-25T13:27:19+02:00
New Revision: a354fd56c5046cc4317a301d90908520f6c4717a

URL: https://github.com/llvm/llvm-project/commit/a354fd56c5046cc4317a301d90908520f6c4717a
DIFF: https://github.com/llvm/llvm-project/commit/a354fd56c5046cc4317a301d90908520f6c4717a.diff

LOG: [libc++] Adds __utility/to_underlying.h.

During the review of D97115 it was mentioned adding the `<utility>`
header for `__to_underlying` was a bit unfortunate. Nowadays we tend to
implement smaller headers, so a good reason to move `std::to_underlying`
to its own header and adjust `<charconv>` to use the new header.

Differential Revision: https://reviews.llvm.org/D101233

Added: 
    libcxx/include/__utility/to_underlying.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/charconv
    libcxx/include/utility

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index d95d70b3b103..3c3a229c6b1d 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -44,6 +44,7 @@ set(files
   __tree
   __tuple
   __undef_macros
+  __utility/to_underlying.h
   algorithm
   any
   array

diff  --git a/libcxx/include/__utility/to_underlying.h b/libcxx/include/__utility/to_underlying.h
new file mode 100644
index 000000000000..fd22f89ff595
--- /dev/null
+++ b/libcxx/include/__utility/to_underlying.h
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//===----------------- __utility/to_underlying.h --------------------------===//
+//
+// 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 _LIBCPP___UTILITY_TO_UNDERLYING_H
+#define _LIBCPP___UTILITY_TO_UNDERLYING_H
+
+#include <__config>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_CXX03_LANG
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY constexpr typename underlying_type<_Tp>::type
+__to_underlying(_Tp __val) noexcept {
+  return static_cast<typename underlying_type<_Tp>::type>(__val);
+}
+#endif // !_LIBCPP_CXX03_LANG
+
+#if _LIBCPP_STD_VER > 20
+template <class _Tp>
+_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY constexpr underlying_type_t<_Tp>
+to_underlying(_Tp __val) noexcept {
+  return _VSTD::__to_underlying(__val);
+}
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___UTILITY_TO_UNDERLYING_H

diff  --git a/libcxx/include/charconv b/libcxx/include/charconv
index 77cc2684f85e..811355219347 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -76,12 +76,12 @@ namespace std {
 #include <__config>
 #include <__availability>
 #include <__errc>
+#include <__utility/to_underlying.h>
 #include <cmath> // for log2f
 #include <cstdint>
 #include <cstring>
 #include <limits>
 #include <type_traits>
-#include <utility>
 
 #include <__debug>
 

diff  --git a/libcxx/include/utility b/libcxx/include/utility
index b494723fa40a..6e028bacf0da 100644
--- a/libcxx/include/utility
+++ b/libcxx/include/utility
@@ -209,6 +209,7 @@ template <class T>
 
 #include <__config>
 #include <__tuple>
+#include <__utility/to_underlying.h>
 #include <compare>
 #include <type_traits>
 #include <initializer_list>
@@ -1718,21 +1719,8 @@ template <class _Type, class ...>
 using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type;
 #endif
 
-template <class _Tp>
-_LIBCPP_INLINE_VISIBILITY constexpr typename underlying_type<_Tp>::type
-__to_underlying(_Tp __val) noexcept {
-  return static_cast<typename underlying_type<_Tp>::type>(__val);
-}
 #endif // !_LIBCPP_CXX03_LANG
 
-#if _LIBCPP_STD_VER > 20
-template <class _Tp>
-_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY constexpr underlying_type_t<_Tp>
-to_underlying(_Tp __val) noexcept {
-  return _VSTD::__to_underlying(__val);
-}
-#endif
-
 _LIBCPP_END_NAMESPACE_STD
 
 _LIBCPP_POP_MACROS


        


More information about the libcxx-commits mailing list