[libcxx-commits] [libcxx] [libc++][NFC] Simplify some overloads in fs::path a bit (PR #181053)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 13 01:50:52 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
We can use `if constexpr` instead, removing a bit of code and making things easier to read.
---
Full diff: https://github.com/llvm/llvm-project/pull/181053.diff
1 Files Affected:
- (modified) libcxx/include/__filesystem/path.h (+13-30)
``````````diff
diff --git a/libcxx/include/__filesystem/path.h b/libcxx/include/__filesystem/path.h
index d567ff5dbb4f4..47ecf1ce19782 100644
--- a/libcxx/include/__filesystem/path.h
+++ b/libcxx/include/__filesystem/path.h
@@ -259,15 +259,14 @@ struct _PathCVT {
template <>
struct _PathCVT<__path_value> {
- template <class _Iter, __enable_if_t<__has_exactly_input_iterator_category<_Iter>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
- for (; __b != __e; ++__b)
- __dest.push_back(*__b);
- }
-
- template <class _Iter, __enable_if_t<__has_forward_iterator_category<_Iter>::value, int> = 0>
+ template <class _Iter>
_LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
- __dest.append(__b, __e);
+ if constexpr (__has_forward_iterator_category<_Iter>::value) {
+ __dest.append(__b, __e);
+ } else {
+ for (; __b != __e; ++__b)
+ __dest.push_back(*__b);
+ }
}
template <class _Iter>
@@ -294,13 +293,7 @@ struct _PathCVT<char> {
__char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size);
}
- template <class _Iter, __enable_if_t<__has_exactly_input_iterator_category<_Iter>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
- basic_string<char> __tmp(__b, __e);
- __append_string(__dest, __tmp);
- }
-
- template <class _Iter, __enable_if_t<__has_forward_iterator_category<_Iter>::value, int> = 0>
+ template <class _Iter>
_LIBCPP_HIDE_FROM_ABI static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) {
basic_string<char> __tmp(__b, __e);
__append_string(__dest, __tmp);
@@ -874,23 +867,13 @@ class _LIBCPP_EXPORTED_FROM_ABI path {
[[nodiscard]] iterator end() const;
# if _LIBCPP_HAS_LOCALIZATION
- template <
- class _CharT,
- class _Traits,
- __enable_if_t<is_same<_CharT, value_type>::value && is_same<_Traits, char_traits<value_type> >::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI friend basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
- __os << std::quoted(__p.native());
- return __os;
- }
-
- template <
- class _CharT,
- class _Traits,
- __enable_if_t<!is_same<_CharT, value_type>::value || !is_same<_Traits, char_traits<value_type> >::value, int> = 0>
+ template <class _CharT, class _Traits>
_LIBCPP_HIDE_FROM_ABI friend basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
- __os << std::quoted(__p.string<_CharT, _Traits>());
+ if constexpr (is_same<_CharT, value_type>::value && is_same<_Traits, char_traits<value_type> >::value)
+ __os << std::quoted(__p.native());
+ else
+ __os << std::quoted(__p.string<_CharT, _Traits>());
return __os;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/181053
More information about the libcxx-commits
mailing list