diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -44,6 +44,7 @@ __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 --- /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 + +#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 +_LIBCPP_INLINE_VISIBILITY constexpr typename underlying_type<_Tp>::type +__to_underlying(_Tp __val) noexcept { + return static_cast::type>(__val); +} +#endif // !_LIBCPP_CXX03_LANG + +#if _LIBCPP_STD_VER > 20 +template +_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 --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -76,12 +76,12 @@ #include <__config> #include <__availability> #include <__errc> +#include <__utility/to_underlying.h> #include // for log2f #include #include #include #include -#include #include <__debug> diff --git a/libcxx/include/utility b/libcxx/include/utility --- a/libcxx/include/utility +++ b/libcxx/include/utility @@ -209,6 +209,7 @@ #include <__config> #include <__tuple> +#include <__utility/to_underlying.h> #include #include #include @@ -1718,21 +1719,8 @@ using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type; #endif -template -_LIBCPP_INLINE_VISIBILITY constexpr typename underlying_type<_Tp>::type -__to_underlying(_Tp __val) noexcept { - return static_cast::type>(__val); -} #endif // !_LIBCPP_CXX03_LANG -#if _LIBCPP_STD_VER > 20 -template -_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