30#ifndef _GLIBCXX_FS_PATH_H
31#define _GLIBCXX_FS_PATH_H 1
33#if __cplusplus >= 201703L
49#if __cplusplus > 201703L
53#ifdef __glibcxx_format_path
57#if defined(_WIN32) && !defined(__CYGWIN__)
58# define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1
61namespace std _GLIBCXX_VISIBILITY(default)
63_GLIBCXX_BEGIN_NAMESPACE_VERSION
67_GLIBCXX_BEGIN_NAMESPACE_CXX11
76 template<
typename _CharT>
77 inline constexpr bool __is_encoded_char =
false;
79 inline constexpr bool __is_encoded_char<char> =
true;
80#ifdef _GLIBCXX_USE_CHAR8_T
82 inline constexpr bool __is_encoded_char<char8_t> =
true;
84#if _GLIBCXX_USE_WCHAR_T
86 inline constexpr bool __is_encoded_char<wchar_t> =
true;
89 inline constexpr bool __is_encoded_char<char16_t> =
true;
91 inline constexpr bool __is_encoded_char<char32_t> =
true;
93#if __cpp_concepts >= 201907L
94 template<
typename _Iter>
95 using __safe_iterator_traits = std::iterator_traits<_Iter>;
97 template<
typename _Iter>
98 struct __safe_iterator_traits : std::iterator_traits<_Iter>
102 template<>
struct __safe_iterator_traits<void*> { };
103 template<>
struct __safe_iterator_traits<const void*> { };
104 template<>
struct __safe_iterator_traits<volatile void*> { };
105 template<>
struct __safe_iterator_traits<const volatile void*> { };
108 template<
typename _Iter_traits,
typename =
void>
109 inline constexpr bool __is_path_iter_src =
false;
111 template<
typename _Iter_traits>
112 inline constexpr bool
113 __is_path_iter_src<_Iter_traits, void_t<typename _Iter_traits::value_type>>
114 = __is_encoded_char<typename _Iter_traits::value_type>;
116 template<
typename _Source>
117 inline constexpr bool __is_path_src
118 = __is_path_iter_src<iterator_traits<decay_t<_Source>>>;
121 inline constexpr bool __is_path_src<path> =
false;
124 inline constexpr bool __is_path_src<volatile path> =
false;
127 inline constexpr bool __is_path_src<void*> =
false;
130 inline constexpr bool __is_path_src<const void*> =
false;
133 inline constexpr bool __is_path_src<volatile void*> =
false;
136 inline constexpr bool __is_path_src<const volatile void*> =
false;
138 template<
typename _CharT,
typename _Traits,
typename _Alloc>
139 inline constexpr bool
140 __is_path_src<basic_string<_CharT, _Traits, _Alloc>>
141 = __is_encoded_char<_CharT>;
143 template<
typename _CharT,
typename _Traits>
144 inline constexpr bool
145 __is_path_src<basic_string_view<_CharT, _Traits>>
146 = __is_encoded_char<_CharT>;
149 template<
typename _Tp>
150 using _Path = enable_if_t<__is_path_src<_Tp>, path>;
153 template<
typename _Iter,
typename _Tr = __safe_iterator_traits<_Iter>>
154 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>, path>;
156#if __cpp_lib_concepts
157 template<
typename _Iter>
158 constexpr bool __is_contiguous = std::contiguous_iterator<_Iter>;
160 template<
typename _Iter>
161 constexpr bool __is_contiguous =
false;
164 template<
typename _Tp>
165 constexpr bool __is_contiguous<_Tp*> =
true;
167 template<
typename _Tp,
typename _Seq>
169 __is_contiguous<__gnu_cxx::__normal_iterator<_Tp*, _Seq>> =
true;
171#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
173 template<
typename _E
charT>
175 = __conditional_t<is_same_v<_EcharT, char8_t>, char, _EcharT>;
177 template<
typename _E
charT>
178 using __unified_u8_t = _EcharT;
185 template<
typename _CharT,
typename _Traits,
typename _Alloc>
186 inline basic_string_view<_CharT>
187 __effective_range(
const basic_string<_CharT, _Traits, _Alloc>& __source)
191 template<
typename _CharT,
typename _Traits>
192 inline basic_string_view<_CharT>
193 __effective_range(
const basic_string_view<_CharT, _Traits>& __source)
198 template<
typename _Source>
200 __effective_range(
const _Source& __source)
203 using _Iter =
decltype(std::__niter_base(__source));
204 using value_type =
typename iterator_traits<_Iter>::value_type;
206 if constexpr (__is_contiguous<_Iter>)
207 return basic_string_view<value_type>{&*__source};
212 basic_string<__unified_u8_t<value_type>> __str;
213 _Source __it = __source;
214 for (value_type __ch = *__it; __ch != value_type(); __ch = *++__it)
215 __str.push_back(__ch);
221 template<
typename _Source>
222 struct __source_value_type_impl
225 =
typename __safe_iterator_traits<decay_t<_Source>>::value_type;
228 template<
typename _CharT,
typename _Traits,
typename _Alloc>
229 struct __source_value_type_impl<basic_string<_CharT, _Traits, _Alloc>>
234 template<
typename _CharT,
typename _Traits>
235 struct __source_value_type_impl<basic_string_view<_CharT, _Traits>>
241 template<
typename _Source>
242 using __source_value_t =
typename __source_value_type_impl<_Source>::type;
247 template<
typename _Tp,
typename _Val = __source_value_t<_Tp>>
248 using __value_type_is_char
253 template<
typename _Tp,
typename _Val = __source_value_t<_Tp>>
254 using __value_type_is_char_or_char8_t
256#ifdef _GLIBCXX_USE_CHAR8_T
257 || std::is_same_v<_Val, char8_t>
262 template<
typename _InputIterator>
264 __string_from_range(_InputIterator __first, _InputIterator __last)
267 =
typename std::iterator_traits<_InputIterator>::value_type;
268 static_assert(__is_encoded_char<_EcharT>);
270 if constexpr (__is_contiguous<_InputIterator>)
273 if (
auto __len = __last - __first) [[__likely__]]
274 return basic_string_view<_EcharT>(&*__first, __len);
275 return basic_string_view<_EcharT>();
280 return basic_string<__unified_u8_t<_EcharT>>(__first, __last);
300#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
301 using value_type = wchar_t;
302 static constexpr value_type preferred_separator = L
'\\';
304# ifdef _GLIBCXX_DOXYGEN
306 using value_type = __os_dependent__;
308 using value_type = char;
310 static constexpr value_type preferred_separator =
'/';
315 enum format :
unsigned char { native_format, generic_format, auto_format };
321 path(
const path& __p) =
default;
323 path(path&& __p) noexcept
324 : _M_pathname(
std::move(__p._M_pathname)),
328 path(string_type&& __source,
format = auto_format)
329 : _M_pathname(
std::
move(__source))
330 { _M_split_cmpts(); }
332 template<
typename _Source,
333 typename _Require = __detail::_Path<_Source>>
334 path(_Source
const& __source,
format = auto_format)
335 : _M_pathname(_S_convert(__detail::__effective_range(__source)))
336 { _M_split_cmpts(); }
338 template<
typename _InputIterator,
339 typename _Require = __detail::_Path2<_InputIterator>>
340 path(_InputIterator __first, _InputIterator __last,
format = auto_format)
341 : _M_pathname(_S_convert(__detail::__string_from_range(__first, __last)))
342 { _M_split_cmpts(); }
344 template<
typename _Source,
345 typename _Require = __detail::_Path<_Source>,
346 typename _Require2 = __detail::__value_type_is_char<_Source>>
347 path(_Source
const& __src,
const locale& __loc,
format = auto_format)
348 : _M_pathname(_S_convert_loc(__detail::__effective_range(__src), __loc))
349 { _M_split_cmpts(); }
351 template<
typename _InputIterator,
352 typename _Require = __detail::_Path2<_InputIterator>,
353 typename _Req2 = __detail::__value_type_is_char<_InputIterator>>
354 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
356 : _M_pathname(_S_convert_loc(__first, __last, __loc))
357 { _M_split_cmpts(); }
363 path& operator=(
const path&);
364 path& operator=(path&&) noexcept;
365 path& operator=(string_type&& __source);
366 path& assign(string_type&& __source);
368 template<typename _Source>
369 __detail::_Path<_Source>&
370 operator=(_Source const& __source)
371 {
return *
this = path(__source); }
373 template<
typename _Source>
374 __detail::_Path<_Source>&
375 assign(_Source
const& __source)
376 {
return *
this = path(__source); }
378 template<
typename _InputIterator>
379 __detail::_Path2<_InputIterator>&
380 assign(_InputIterator __first, _InputIterator __last)
381 {
return *
this = path(__first, __last); }
385 path& operator/=(
const path& __p);
387 template<
typename _Source>
388 __detail::_Path<_Source>&
389 operator/=(_Source
const& __source)
391 _M_append(_S_convert(__detail::__effective_range(__source)));
395 template<
typename _Source>
396 __detail::_Path<_Source>&
397 append(_Source
const& __source)
399 _M_append(_S_convert(__detail::__effective_range(__source)));
403 template<
typename _InputIterator>
404 __detail::_Path2<_InputIterator>&
405 append(_InputIterator __first, _InputIterator __last)
407 _M_append(_S_convert(__detail::__string_from_range(__first, __last)));
413 path& operator+=(
const path& __x);
414 path& operator+=(
const string_type& __x);
415 path& operator+=(
const value_type* __x);
416 path& operator+=(value_type __x);
417 path& operator+=(basic_string_view<value_type> __x);
419 template<
typename _Source>
420 __detail::_Path<_Source>&
421 operator+=(_Source
const& __x) {
return concat(__x); }
423 template<
typename _CharT>
424 __detail::_Path2<_CharT*>&
425 operator+=(_CharT __x);
427 template<
typename _Source>
428 __detail::_Path<_Source>&
429 concat(_Source
const& __x)
431 _M_concat(_S_convert(__detail::__effective_range(__x)));
435 template<
typename _InputIterator>
436 __detail::_Path2<_InputIterator>&
437 concat(_InputIterator __first, _InputIterator __last)
439 _M_concat(_S_convert(__detail::__string_from_range(__first, __last)));
445 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
447 path& make_preferred();
448 path& remove_filename();
449 path& replace_filename(
const path& __replacement);
450 path& replace_extension(
const path& __replacement = path());
452 void swap(path& __rhs)
noexcept;
456 const string_type& native() const noexcept {
return _M_pathname; }
457 const value_type* c_str() const noexcept {
return _M_pathname.c_str(); }
458 operator string_type()
const {
return _M_pathname; }
460 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
461 typename _Allocator = std::allocator<_CharT>>
462 std::basic_string<_CharT, _Traits, _Allocator>
463 string(
const _Allocator& __a = _Allocator())
const;
466#if _GLIBCXX_USE_WCHAR_T
469#ifdef _GLIBCXX_USE_CHAR8_T
470 __attribute__((__abi_tag__(
"__u8")))
471 std::u8string u8string() const;
479 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
480 typename _Allocator = std::allocator<_CharT>>
481 std::basic_string<_CharT, _Traits, _Allocator>
482 generic_string(
const _Allocator& __a = _Allocator())
const;
485#if _GLIBCXX_USE_WCHAR_T
488#ifdef _GLIBCXX_USE_CHAR8_T
489 __attribute__((__abi_tag__(
"__u8")))
490 std::u8string generic_u8string() const;
499 int compare(
const path& __p)
const noexcept;
500 int compare(
const string_type& __s)
const noexcept;
501 int compare(
const value_type* __s)
const noexcept;
502 int compare(basic_string_view<value_type> __s)
const noexcept;
506 path root_name()
const;
507 path root_directory()
const;
508 path root_path()
const;
509 path relative_path()
const;
510 path parent_path()
const;
511 path filename()
const;
513 path extension()
const;
517 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.empty(); }
518 bool has_root_name() const noexcept;
519 bool has_root_directory() const noexcept;
520 bool has_root_path() const noexcept;
521 bool has_relative_path() const noexcept;
522 bool has_parent_path() const noexcept;
523 bool has_filename() const noexcept;
524 bool has_stem() const noexcept;
525 bool has_extension() const noexcept;
526 bool is_absolute() const noexcept;
527 bool is_relative() const noexcept {
return !is_absolute(); }
530 path lexically_normal()
const;
531 path lexically_relative(
const path& base)
const;
532 path lexically_proximate(
const path& base)
const;
542 template<typename _CharT, typename _Traits>
546 __os << std::quoted(__p.string<_CharT, _Traits>());
551 template<
typename _CharT,
typename _Traits>
556 if (__is >> std::quoted(__tmp))
564 friend bool operator==(
const path& __lhs,
const path& __rhs)
noexcept
565 {
return path::_S_compare(__lhs, __rhs) == 0; }
567#if __cpp_lib_three_way_comparison
569 friend strong_ordering
570 operator<=>(
const path& __lhs,
const path& __rhs)
noexcept
571 {
return path::_S_compare(__lhs, __rhs) <=> 0; }
574 friend bool operator!=(
const path& __lhs,
const path& __rhs)
noexcept
575 {
return !(__lhs == __rhs); }
578 friend bool operator<(
const path& __lhs,
const path& __rhs)
noexcept
579 {
return __lhs.compare(__rhs) < 0; }
582 friend bool operator<=(
const path& __lhs,
const path& __rhs)
noexcept
583 {
return !(__rhs < __lhs); }
586 friend bool operator>(
const path& __lhs,
const path& __rhs)
noexcept
587 {
return __rhs < __lhs; }
590 friend bool operator>=(
const path& __lhs,
const path& __rhs)
noexcept
591 {
return !(__lhs < __rhs); }
595 friend path
operator/(
const path& __lhs,
const path& __rhs)
597 path __result(__lhs);
603 enum class _Type :
unsigned char {
604 _Multi = 0, _Root_name, _Root_dir, _Filename
609 enum class _Split { _Stem, _Extension };
611 void _M_append(basic_string_view<value_type>);
612 void _M_concat(basic_string_view<value_type>);
620 template<typename _Tp>
622 _S_convert(_Tp __str)
623 noexcept(is_same_v<typename _Tp::value_type, value_type>)
625 if constexpr (is_same_v<typename _Tp::value_type, value_type>)
627#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
628 else if constexpr (is_same_v<_Tp, std::u8string>)
632 return string_type(_S_convert(__str.data(),
633 __str.data() + __str.size()));
636 return _S_convert(__str.data(), __str.data() + __str.size());
639 template<
typename _E
charT>
641 _S_convert(
const _EcharT* __first,
const _EcharT* __last);
647 _S_convert_loc(
const char* __first,
const char* __last,
648 const std::locale& __loc);
650 template<
typename _Iter>
652 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
654 const auto __s = __detail::__string_from_range(__first, __last);
655 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
658 template<
typename _Tp>
660 _S_convert_loc(
const _Tp& __s,
const std::locale& __loc)
662 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
665 template<
typename _CharT,
typename _Traits,
typename _Allocator>
666 static basic_string<_CharT, _Traits, _Allocator>
667 _S_str_convert(basic_string_view<value_type>,
const _Allocator&);
670 __attribute__((__always_inline__))
672 _S_compare(
const path& __lhs,
const path& __rhs)
noexcept;
674 void _M_split_cmpts();
676 _Type _M_type() const noexcept {
return _M_cmpts.type(); }
678 string_type _M_pathname;
684 using value_type = _Cmpt;
685 using iterator = value_type*;
686 using const_iterator =
const value_type*;
690 _List(_List&&) =
default;
691 _List& operator=(
const _List&);
692 _List& operator=(_List&&) =
default;
695 _Type type() const noexcept
696 {
return _Type(
reinterpret_cast<__UINTPTR_TYPE__
>(_M_impl.get()) & 0x3); }
698 void type(_Type)
noexcept;
700 int size() const noexcept;
701 bool empty() const noexcept;
703 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
704 int capacity() const noexcept;
705 void reserve(
int,
bool);
710 iterator begin() noexcept;
711 iterator end() noexcept;
712 const_iterator begin() const noexcept;
713 const_iterator end() const noexcept;
715 value_type& front() noexcept;
716 value_type& back() noexcept;
717 const value_type& front() const noexcept;
718 const value_type& back() const noexcept;
721 void _M_erase_from(const_iterator __pos);
726 void operator()(_Impl*)
const noexcept;
728 unique_ptr<_Impl, _Impl_deleter> _M_impl;
734 template<
typename _E
charT>
struct _Codecvt;
740 inline void swap(
path& __lhs,
path& __rhs)
noexcept { __lhs.swap(__rhs); }
742 size_t hash_value(
const path& __p)
noexcept;
754 filesystem_error(
const string& __what_arg,
error_code __ec);
756 filesystem_error(
const string& __what_arg,
const path& __p1,
759 filesystem_error(
const string& __what_arg,
const path& __p1,
762 filesystem_error(
const filesystem_error&) =
default;
763 filesystem_error& operator=(
const filesystem_error&) =
default;
770 const path& path1()
const noexcept;
771 const path& path2()
const noexcept;
772 const char*
what() const noexcept;
776 std::__shared_ptr<const _Impl> _M_impl;
782 [[noreturn]]
inline void
783 __throw_conversion_error()
785 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
786 "Cannot convert character sequence",
790#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
791 template<
typename _Tp>
793 __wstr_from_utf8(
const _Tp& __str)
795 static_assert(std::is_same_v<typename _Tp::value_type, char>);
798 std::codecvt_utf8_utf16<wchar_t> __wcvt;
799 const auto __p = __str.data();
800 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
801 __detail::__throw_conversion_error();
816 template<
typename _InputIterator,
817 typename _Require = __detail::_Path2<_InputIterator>,
819 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
820 _GLIBCXX20_DEPRECATED_SUGGEST(
"path(u8string(first, last))")
822 u8path(_InputIterator __first, _InputIterator __last)
824#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
825 if constexpr (is_same_v<_CharT, char>)
826 return path{ __detail::__wstr_from_utf8(
827 __detail::__string_from_range(__first, __last)) };
829 return path{ __first, __last };
832 return path{ __first, __last };
842 template<
typename _Source,
843 typename _Require = __detail::_Path<_Source>,
844 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
845 _GLIBCXX20_DEPRECATED_SUGGEST(
"path((const char8_t*)&*source)")
849#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
850 if constexpr (is_same_v<_CharT, char>)
851 return path{ __detail::__wstr_from_utf8(
852 __detail::__effective_range(__source)) };
854 return path{ __source };
857 return path{ __source };
863 struct path::_Cmpt :
path
867 _Cmpt() : _M_pos(-1) { }
878 template<
typename _E
charT>
879 struct path::_Codecvt
892 struct path::_Codecvt<wchar_t>
893 : __conditional_t<sizeof(wchar_t) == sizeof(char32_t),
894 std::codecvt_utf8<wchar_t>,
895 std::codecvt_utf8_utf16<wchar_t>>
898 template<
typename _E
charT>
900 path::_S_convert(
const _EcharT* __f,
const _EcharT* __l)
902 static_assert(__detail::__is_encoded_char<_EcharT>);
904#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
905# define _GLIBCXX_CONV_FROM_UTF8(S) __detail::__wstr_from_utf8(S)
907# define _GLIBCXX_CONV_FROM_UTF8(S) S
910 if constexpr (is_same_v<_EcharT, value_type>)
911 return basic_string_view<value_type>(__f, __l - __f);
912#ifdef _GLIBCXX_USE_CHAR8_T
913 else if constexpr (is_same_v<_EcharT, char8_t>)
915 string_view __str(
reinterpret_cast<const char*
>(__f), __l - __f);
916 return _GLIBCXX_CONV_FROM_UTF8(__str);
919#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
920 else if constexpr (is_same_v<_EcharT, char>)
923 path::_Codecvt<wchar_t> __cvt;
924 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
930 path::_Codecvt<_EcharT> __cvt;
932 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
933 return _GLIBCXX_CONV_FROM_UTF8(__str);
935 __detail::__throw_conversion_error();
937#undef _GLIBCXX_CONV_FROM_UTF8
949 using difference_type = std::ptrdiff_t;
950 using value_type = path;
951 using reference =
const path&;
952 using pointer =
const path*;
955 iterator() noexcept : _M_path(
nullptr), _M_cur(), _M_at_end() { }
957 iterator(
const iterator&) =
default;
958 iterator& operator=(
const iterator&) =
default;
960 reference operator*()
const noexcept;
963 iterator& operator++()
noexcept;
965 iterator operator++(
int)
noexcept
966 {
auto __tmp = *
this; ++*
this;
return __tmp; }
968 iterator& operator--()
noexcept;
970 iterator operator--(
int)
noexcept
971 {
auto __tmp = *
this; --*
this;
return __tmp; }
974 operator==(
const iterator& __lhs,
const iterator& __rhs)
noexcept
975 {
return __lhs._M_equals(__rhs); }
978 operator!=(
const iterator& __lhs,
const iterator& __rhs)
noexcept
979 {
return !__lhs._M_equals(__rhs); }
985 _M_is_multi()
const noexcept
986 {
return _M_path->_M_type() == _Type::_Multi; }
988 friend difference_type
989 __path_iter_distance(
const iterator& __first,
const iterator& __last)
992 __glibcxx_assert(__first._M_path !=
nullptr);
993 __glibcxx_assert(__first._M_path == __last._M_path);
994 if (__first._M_is_multi())
996 else if (__first._M_at_end == __last._M_at_end)
999 return __first._M_at_end ? -1 : 1;
1003 __path_iter_advance(iterator& __i, difference_type __n)
noexcept
1011 __glibcxx_assert(__i._M_path !=
nullptr);
1012 __glibcxx_assert(__i._M_is_multi());
1018 iterator(
const path* __path, path::_List::const_iterator __iter) noexcept
1019 : _M_path(__path), _M_cur(__iter), _M_at_end()
1022 iterator(
const path* __path,
bool __at_end) noexcept
1023 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
1026 bool _M_equals(iterator)
const noexcept;
1028 const path* _M_path;
1029 path::_List::const_iterator _M_cur;
1035 path::operator=(path&& __p)
noexcept
1037 if (&__p ==
this) [[__unlikely__]]
1040 _M_pathname =
std::move(__p._M_pathname);
1047 path::operator=(string_type&& __source)
1051 path::assign(string_type&& __source)
1052 {
return *
this = path(
std::move(__source)); }
1055 path::operator+=(
const string_type& __x)
1062 path::operator+=(
const value_type* __x)
1069 path::operator+=(value_type __x)
1071 _M_concat(basic_string_view<value_type>(&__x, 1));
1076 path::operator+=(basic_string_view<value_type> __x)
1082 template<
typename _CharT>
1083 inline __detail::_Path2<_CharT*>&
1084 path::operator+=(
const _CharT __x)
1086 _M_concat(_S_convert(&__x, &__x + 1));
1091 path::make_preferred()
1093#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1094 auto __pos = _M_pathname.find(L
'/');
1095 while (__pos != _M_pathname.npos)
1097 _M_pathname[__pos] = preferred_separator;
1098 __pos = _M_pathname.find(L
'/', __pos);
1104 inline void path::swap(path& __rhs)
noexcept
1106 _M_pathname.swap(__rhs._M_pathname);
1107 _M_cmpts.swap(__rhs._M_cmpts);
1111 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1112 std::basic_string<_CharT, _Traits, _Allocator>
1113 path::_S_str_convert(basic_string_view<value_type> __str,
1114 const _Allocator& __a)
1116 static_assert(!is_same_v<_CharT, value_type>);
1118 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1120 if (__str.size() == 0)
1121 return _WString(__a);
1123#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1124 string_view __u8str = __str;
1128 std::codecvt_utf8_utf16<value_type> __cvt;
1130 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1131 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1132 _String __u8str{_CharAlloc{__a}};
1133 const value_type* __wfirst = __str.data();
1134 const value_type* __wlast = __wfirst + __str.size();
1135 if (!__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt))
1136 __detail::__throw_conversion_error();
1137 if constexpr (is_same_v<_CharT, char>)
1142 const char* __first = __u8str.data();
1143 const char* __last = __first + __u8str.size();
1146#ifdef _GLIBCXX_USE_CHAR8_T
1147 if constexpr (is_same_v<_CharT, char8_t>)
1148 return _WString(__first, __last, __a);
1153 _WString __wstr(__a);
1154 path::_Codecvt<_CharT> __cvt;
1155 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1159 __detail::__throw_conversion_error();
1163 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1164 inline basic_string<_CharT, _Traits, _Allocator>
1165 path::string(
const _Allocator& __a)
const
1167 if constexpr (is_same_v<_CharT, value_type>)
1168 return { _M_pathname.c_str(), _M_pathname.length(), __a };
1170 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1176#if _GLIBCXX_USE_WCHAR_T
1181#ifdef _GLIBCXX_USE_CHAR8_T
1182 inline std::u8string
1186 path::u8string()
const
1188#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1191 std::codecvt_utf8_utf16<value_type> __cvt;
1192 const value_type* __first = _M_pathname.data();
1193 const value_type* __last = __first + _M_pathname.size();
1194 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1196 __detail::__throw_conversion_error();
1209 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1210 inline std::basic_string<_CharT, _Traits, _Allocator>
1211 path::generic_string(
const _Allocator& __a)
const
1213#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1214 const value_type __slash = L
'/';
1216 const value_type __slash =
'/';
1218 using _Alloc2 =
typename allocator_traits<_Allocator>::template
1219 rebind_alloc<value_type>;
1220 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1222 if (_M_type() == _Type::_Root_dir)
1223 __str.
assign(1, __slash);
1226 __str.
reserve(_M_pathname.size());
1227 bool __add_slash =
false;
1228 for (
auto& __elem : *
this)
1230#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1231 if (__elem._M_type() == _Type::_Root_dir)
1239 __str += basic_string_view<value_type>(__elem._M_pathname);
1240 __add_slash = __elem._M_type() == _Type::_Filename;
1244 if constexpr (is_same_v<_CharT, value_type>)
1247 return _S_str_convert<_CharT, _Traits>(__str, __a);
1251 path::generic_string()
const
1252 {
return generic_string<char>(); }
1254#if _GLIBCXX_USE_WCHAR_T
1256 path::generic_wstring()
const
1257 {
return generic_string<wchar_t>(); }
1260#ifdef _GLIBCXX_USE_CHAR8_T
1261 inline std::u8string
1262 path::generic_u8string()
const
1263 {
return generic_string<char8_t>(); }
1266 path::generic_u8string()
const
1267 {
return generic_string(); }
1271 path::generic_u16string()
const
1272 {
return generic_string<char16_t>(); }
1275 path::generic_u32string()
const
1276 {
return generic_string<char32_t>(); }
1279 path::compare(
const string_type& __s)
const noexcept
1280 {
return compare(basic_string_view<value_type>(__s)); }
1283 path::compare(
const value_type* __s)
const noexcept
1284 {
return compare(basic_string_view<value_type>(__s)); }
1287 path::filename()
const
1291 else if (_M_type() == _Type::_Filename)
1293 else if (_M_type() == _Type::_Multi)
1295 if (_M_pathname.back() == preferred_separator)
1297 auto __last = --
end();
1298 if (__last->_M_type() == _Type::_Filename)
1307 auto ext = _M_find_extension();
1308 if (ext.first && ext.second != 0)
1309 return path{ext.first->substr(0, ext.second)};
1314 path::extension()
const
1316 auto ext = _M_find_extension();
1317 if (ext.first && ext.second != string_type::npos)
1318 return path{ext.first->substr(ext.second)};
1323 path::has_stem() const noexcept
1325 auto ext = _M_find_extension();
1326 return ext.first && ext.second != 0;
1330 path::has_extension() const noexcept
1332 auto ext = _M_find_extension();
1333 return ext.first && ext.second != string_type::npos;
1337 path::is_absolute() const noexcept
1339#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1340 return has_root_name() && has_root_directory();
1342 return has_root_directory();
1346 inline path::iterator
1347 path::begin() const noexcept
1349 if (_M_type() == _Type::_Multi)
1350 return iterator(
this, _M_cmpts.begin());
1351 return iterator(
this,
empty());
1354 inline path::iterator
1355 path::end() const noexcept
1357 if (_M_type() == _Type::_Multi)
1358 return iterator(
this, _M_cmpts.end());
1359 return iterator(
this,
true);
1362 inline path::iterator&
1363 path::iterator::operator++() noexcept
1365 __glibcxx_assert(_M_path !=
nullptr);
1368 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1373 __glibcxx_assert(!_M_at_end);
1379 inline path::iterator&
1380 path::iterator::operator--() noexcept
1382 __glibcxx_assert(_M_path !=
nullptr);
1385 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1390 __glibcxx_assert(_M_at_end);
1396 inline path::iterator::reference
1397 path::iterator::operator*() const noexcept
1399 __glibcxx_assert(_M_path !=
nullptr);
1402 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1409 path::iterator::_M_equals(iterator __rhs)
const noexcept
1411 if (_M_path != __rhs._M_path)
1413 if (_M_path ==
nullptr)
1416 return _M_cur == __rhs._M_cur;
1417 return _M_at_end == __rhs._M_at_end;
1425 path::_S_compare(
const path& __lhs,
const path& __rhs)
noexcept
1426 {
return __lhs.compare(__rhs); }
1429_GLIBCXX_END_NAMESPACE_CXX11
1435distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1437{
return __path_iter_distance(__first, __last); }
1439template<
typename _Distance>
1441 advance(filesystem::path::iterator& __i, _Distance __n)
noexcept
1442 { __path_iter_advance(__i,
static_cast<ptrdiff_t
>(__n)); }
1444extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1451 struct hash<filesystem::path>
1454 operator()(
const filesystem::path& __p)
const noexcept
1455 {
return filesystem::hash_value(__p); }
1458#ifdef __glibcxx_format_path
1459 template<__format::__
char _CharT>
1460 struct formatter<filesystem::path, _CharT>
1462 formatter() =
default;
1464 constexpr typename basic_format_parse_context<_CharT>::iterator
1465 parse(basic_format_parse_context<_CharT>& __pc)
1467 auto __first = __pc.begin();
1468 const auto __last = __pc.end();
1469 __format::_Spec<_CharT> __spec{};
1471 auto __finalize = [
this, &__spec] {
1475 auto __finished = [&] {
1476 if (__first == __last || *__first ==
'}')
1487 __first = __spec._M_parse_fill_and_align(__first, __last);
1491 __first = __spec._M_parse_width(__first, __last, __pc);
1495 if (*__first ==
'?')
1497 __spec._M_debug =
true;
1503 if (*__first ==
'g')
1505 __spec._M_type = __format::_Pres_g;
1511 __format::__failed_to_parse_format_spec();
1514 template<
typename _Out>
1515 typename basic_format_context<_Out, _CharT>::iterator
1516 format(
const filesystem::path& __p,
1517 basic_format_context<_Out, _CharT>& __fc)
const
1519 using _ValueT = filesystem::path::value_type;
1520 using _ViewT = basic_string_view<_ValueT>;
1521 using _FmtStrT = __format::__formatter_str<_CharT>;
1524 filesystem::path::string_type __s;
1525 if (_M_spec._M_type == __format::_Pres_g)
1526 __sv = __s = __p.generic_string<_ValueT>();
1528 __sv = __p.native();
1530 auto __spec = _M_spec;
1532 __spec._M_type = __format::_Pres_none;
1534 if constexpr (is_same_v<_CharT, _ValueT>)
1535 return _FmtStrT(__spec).format(__sv, __fc);
1538 __format::_Str_sink<_ValueT> __sink;
1539 if (__spec._M_debug)
1541 using __format::_Term_quote;
1542 __format::__write_escaped(__sink.out(), __sv, _Term_quote);
1543 __sv = __sink.view();
1544 __spec._M_debug = 0;
1546 basic_string<_CharT> __out_str
1547 (std::from_range, __unicode::_Utf_view<_CharT, _ViewT>(__sv));
1548 return _FmtStrT(__spec).format(__out_str, __fc);
1553 set_debug_format() noexcept
1554 { _M_spec._M_debug =
true; }
1557 __format::_Spec<_CharT> _M_spec{};
1561_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
error_code make_error_code(future_errc __errc) noexcept
Overload of make_error_code for future_errc.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
basic_string< char > string
A string of char.
basic_string< char32_t > u32string
A string of char32_t.
basic_string< char16_t > u16string
A string of char16_t.
basic_string< wchar_t > wstring
A string of wchar_t.
directory_iterator end(directory_iterator) noexcept
Return a past-the-end directory_iterator.
path u8path(_InputIterator __first, _InputIterator __last)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Implementation details not part of the namespace std interface.
ISO C++ 2017 namespace for File System library.
Template class basic_istream.
Template class basic_ostream.
A non-owning reference to a string.
An exception type that includes an error_code value.
Managing sequences of characters and character-like objects.
constexpr void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
constexpr basic_string & assign(const basic_string &__str)
Set value to contents of another string.
Primary class template codecvt.
friend strong_ordering operator<=>(const path &__lhs, const path &__rhs) noexcept
Compare paths.
friend path operator/(const path &__lhs, const path &__rhs)
Append one path to another.
format
path::format is ignored in this implementation
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, path &__p)
Read a path from a stream.
friend bool operator==(const path &__lhs, const path &__rhs) noexcept
Compare paths.
const char * what() const noexcept
An iterator for the components of a path.
Bidirectional iterators support a superset of forward iterator operations.