[libcxx-commits] [PATCH] D102332: [libc++][nfc] remove duplicated __to_unsigned.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed May 12 08:52:11 PDT 2021
Mordante created this revision.
Mordante added reviewers: cjdb, zoecarver.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Both `<type_traits>` and `<charconv>` implemented this function with
different names and a slightly different behavior. This removes the
version in `<charconv>` and improves the version in `<typetraits>`.
- The code can be used again in C++11.
- The original claimed C++14 support, but `[[nodiscard]]` is not available in C++14.
- Adds `_LIBCPP_INLINE_VISIBILITY`.
- Uses the name from `<charconv>`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102332
Files:
libcxx/include/__ranges/size.h
libcxx/include/charconv
libcxx/include/type_traits
Index: libcxx/include/type_traits
===================================================================
--- libcxx/include/type_traits
+++ libcxx/include/type_traits
@@ -2309,12 +2309,13 @@
#if _LIBCPP_STD_VER > 11
template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
+#endif
-template<class _From>
-[[nodiscard]] constexpr auto __to_unsigned_like(_From __x) noexcept {
- return static_cast<make_unsigned_t<_From>>(__x);
+template <class _Tp>
+_LIBCPP_NODISCARD_ATTRIBUTE _LIBCPP_INLINE_VISIBILITY constexpr
+typename make_unsigned<_Tp>::type __to_unsigned(_Tp __x) noexcept {
+ return static_cast<typename make_unsigned<_Tp>::type>(__x);
}
-#endif
#if _LIBCPP_STD_VER > 14
template <class...> using void_t = void;
Index: libcxx/include/charconv
===================================================================
--- libcxx/include/charconv
+++ libcxx/include/charconv
@@ -331,13 +331,6 @@
return _Tp(~__x + 1);
}
-template <typename _Tp>
-inline _LIBCPP_INLINE_VISIBILITY typename make_unsigned<_Tp>::type
-__to_unsigned(_Tp __x)
-{
- return static_cast<typename make_unsigned<_Tp>::type>(__x);
-}
-
template <typename _Tp>
_LIBCPP_AVAILABILITY_TO_CHARS
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
Index: libcxx/include/__ranges/size.h
===================================================================
--- libcxx/include/__ranges/size.h
+++ libcxx/include/__ranges/size.h
@@ -89,7 +89,7 @@
template<__difference _Tp>
[[nodiscard]] constexpr __integer_like auto operator()(_Tp&& __t) const
noexcept(noexcept(ranges::end(__t) - ranges::begin(__t))) {
- return __to_unsigned_like<range_difference_t<remove_cvref_t<_Tp>>>(
+ return __to_unsigned<range_difference_t<remove_cvref_t<_Tp>>>(
ranges::end(__t) - ranges::begin(__t));
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102332.344842.patch
Type: text/x-patch
Size: 1840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210512/16dff320/attachment.bin>
More information about the libcxx-commits
mailing list