[libcxx-commits] [libcxx] a7a249f - [libc++][NFC] Simplify some overloads in fs::path a bit (#181053)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 13 01:50:21 PST 2026
Author: Nikolas Klauser
Date: 2026-02-13T10:50:17+01:00
New Revision: a7a249f072461bbb2a429848bb31682d0b9a93a4
URL: https://github.com/llvm/llvm-project/commit/a7a249f072461bbb2a429848bb31682d0b9a93a4
DIFF: https://github.com/llvm/llvm-project/commit/a7a249f072461bbb2a429848bb31682d0b9a93a4.diff
LOG: [libc++][NFC] Simplify some overloads in fs::path a bit (#181053)
We can use `if constexpr` instead, removing a bit of code and making
things easier to read.
Added:
Modified:
libcxx/include/__filesystem/path.h
Removed:
################################################################################
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;
}
More information about the libcxx-commits
mailing list