30#ifndef _GLIBCXX_FS_PATH_H
31#define _GLIBCXX_FS_PATH_H 1
33#if __cplusplus >= 201703L
41#include <bits/iosfwd.h>
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;
465 _GLIBCXX26_DEPRECATED_SUGGEST(
"display_string' or 'native_encoded_string")
466 std::
string string() const;
467#if __glibcxx_format_path >= 202506L
471#if _GLIBCXX_USE_WCHAR_T
474#ifdef _GLIBCXX_USE_CHAR8_T
475 __attribute__((__abi_tag__(
"__u8")))
476 std::u8string u8string() const;
484 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
485 typename _Allocator = std::allocator<_CharT>>
486 std::basic_string<_CharT, _Traits, _Allocator>
487 generic_string(
const _Allocator& __a = _Allocator())
const;
489 _GLIBCXX26_DEPRECATED_SUGGEST(
"generic_display_string' or 'generic_native_encoded_string")
490 std::
string generic_string() const;
491#if __glibcxx_format_path >= 202506L
495#if _GLIBCXX_USE_WCHAR_T
498#ifdef _GLIBCXX_USE_CHAR8_T
499 __attribute__((__abi_tag__(
"__u8")))
500 std::u8string generic_u8string() const;
509 int compare(
const path& __p)
const noexcept;
510 int compare(
const string_type& __s)
const noexcept;
511 int compare(
const value_type* __s)
const noexcept;
512 int compare(basic_string_view<value_type> __s)
const noexcept;
516 path root_name()
const;
517 path root_directory()
const;
518 path root_path()
const;
519 path relative_path()
const;
520 path parent_path()
const;
521 path filename()
const;
523 path extension()
const;
527 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.empty(); }
528 bool has_root_name() const noexcept;
529 bool has_root_directory() const noexcept;
530 bool has_root_path() const noexcept;
531 bool has_relative_path() const noexcept;
532 bool has_parent_path() const noexcept;
533 bool has_filename() const noexcept;
534 bool has_stem() const noexcept;
535 bool has_extension() const noexcept;
536 bool is_absolute() const noexcept;
537 bool is_relative() const noexcept {
return !is_absolute(); }
540 path lexically_normal()
const;
541 path lexically_relative(
const path& base)
const;
542 path lexically_proximate(
const path& base)
const;
552 template<typename _CharT, typename _Traits>
556 __os << std::quoted(__p.string<_CharT, _Traits>());
561 template<
typename _CharT,
typename _Traits>
566 if (__is >> std::quoted(__tmp))
574 friend bool operator==(
const path& __lhs,
const path& __rhs)
noexcept
575 {
return path::_S_compare(__lhs, __rhs) == 0; }
577#if __cpp_lib_three_way_comparison
579 friend strong_ordering
580 operator<=>(
const path& __lhs,
const path& __rhs)
noexcept
581 {
return path::_S_compare(__lhs, __rhs) <=> 0; }
584 friend bool operator!=(
const path& __lhs,
const path& __rhs)
noexcept
585 {
return !(__lhs == __rhs); }
588 friend bool operator<(
const path& __lhs,
const path& __rhs)
noexcept
589 {
return __lhs.compare(__rhs) < 0; }
592 friend bool operator<=(
const path& __lhs,
const path& __rhs)
noexcept
593 {
return !(__rhs < __lhs); }
596 friend bool operator>(
const path& __lhs,
const path& __rhs)
noexcept
597 {
return __rhs < __lhs; }
600 friend bool operator>=(
const path& __lhs,
const path& __rhs)
noexcept
601 {
return !(__lhs < __rhs); }
605 friend path
operator/(
const path& __lhs,
const path& __rhs)
607 path __result(__lhs);
613 enum class _Type :
unsigned char {
614 _Multi = 0, _Root_name, _Root_dir, _Filename
619 enum class _Split { _Stem, _Extension };
621 void _M_append(basic_string_view<value_type>);
622 void _M_concat(basic_string_view<value_type>);
630 template<typename _Tp>
632 _S_convert(_Tp __str)
633 noexcept(is_same_v<typename _Tp::value_type, value_type>)
635 if constexpr (is_same_v<typename _Tp::value_type, value_type>)
637#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
638 else if constexpr (is_same_v<_Tp, std::u8string>)
642 return string_type(_S_convert(__str.data(),
643 __str.data() + __str.size()));
646 return _S_convert(__str.data(), __str.data() + __str.size());
649 template<
typename _E
charT>
651 _S_convert(
const _EcharT* __first,
const _EcharT* __last);
657 _S_convert_loc(
const char* __first,
const char* __last,
658 const std::locale& __loc);
660 template<
typename _Iter>
662 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
664 const auto __s = __detail::__string_from_range(__first, __last);
665 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
668 template<
typename _Tp>
670 _S_convert_loc(
const _Tp& __s,
const std::locale& __loc)
672 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
675 template<
typename _CharT,
typename _Traits,
typename _Allocator>
676 static basic_string<_CharT, _Traits, _Allocator>
677 _S_str_convert(basic_string_view<value_type>,
const _Allocator&);
680 __attribute__((__always_inline__))
682 _S_compare(
const path& __lhs,
const path& __rhs)
noexcept;
684 void _M_split_cmpts();
686 _Type _M_type() const noexcept {
return _M_cmpts.type(); }
688 string_type _M_pathname;
694 using value_type = _Cmpt;
695 using iterator = value_type*;
696 using const_iterator =
const value_type*;
700 _List(_List&&) =
default;
701 _List& operator=(
const _List&);
702 _List& operator=(_List&&) =
default;
705 _Type type() const noexcept
706 {
return _Type(
reinterpret_cast<__UINTPTR_TYPE__
>(_M_impl.get()) & 0x3); }
708 void type(_Type)
noexcept;
710 int size() const noexcept;
711 bool empty() const noexcept;
713 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
714 int capacity() const noexcept;
715 void reserve(
int,
bool);
720 iterator begin() noexcept;
721 iterator end() noexcept;
722 const_iterator begin() const noexcept;
723 const_iterator end() const noexcept;
725 value_type& front() noexcept;
726 value_type& back() noexcept;
727 const value_type& front() const noexcept;
728 const value_type& back() const noexcept;
731 void _M_erase_from(const_iterator __pos);
736 void operator()(_Impl*)
const noexcept;
738 unique_ptr<_Impl, _Impl_deleter> _M_impl;
744 template<
typename _E
charT>
struct _Codecvt;
750 inline void swap(
path& __lhs,
path& __rhs)
noexcept { __lhs.swap(__rhs); }
752 size_t hash_value(
const path& __p)
noexcept;
764 filesystem_error(
const string& __what_arg,
error_code __ec);
766 filesystem_error(
const string& __what_arg,
const path& __p1,
769 filesystem_error(
const string& __what_arg,
const path& __p1,
772 filesystem_error(
const filesystem_error&) =
default;
773 filesystem_error& operator=(
const filesystem_error&) =
default;
780 const path& path1()
const noexcept;
781 const path& path2()
const noexcept;
782 const char*
what() const noexcept;
786 std::__shared_ptr<const _Impl> _M_impl;
792 [[noreturn]]
inline void
793 __throw_conversion_error()
795 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
796 "Cannot convert character sequence",
800#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
801 template<
typename _Tp>
803 __wstr_from_utf8(
const _Tp& __str)
805 static_assert(std::is_same_v<typename _Tp::value_type, char>);
808 std::codecvt_utf8_utf16<wchar_t> __wcvt;
809 const auto __p = __str.data();
810 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
811 __detail::__throw_conversion_error();
826 template<
typename _InputIterator,
827 typename _Require = __detail::_Path2<_InputIterator>,
829 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
830 _GLIBCXX20_DEPRECATED_SUGGEST(
"path(u8string(first, last))")
832 u8path(_InputIterator __first, _InputIterator __last)
834#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
835 if constexpr (is_same_v<_CharT, char>)
836 return path{ __detail::__wstr_from_utf8(
837 __detail::__string_from_range(__first, __last)) };
839 return path{ __first, __last };
842 return path{ __first, __last };
852 template<
typename _Source,
853 typename _Require = __detail::_Path<_Source>,
854 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
855 _GLIBCXX20_DEPRECATED_SUGGEST(
"path((const char8_t*)&*source)")
859#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
860 if constexpr (is_same_v<_CharT, char>)
861 return path{ __detail::__wstr_from_utf8(
862 __detail::__effective_range(__source)) };
864 return path{ __source };
867 return path{ __source };
873 struct path::_Cmpt :
path
877 _Cmpt() : _M_pos(-1) { }
888 template<
typename _E
charT>
889 struct path::_Codecvt
902 struct path::_Codecvt<wchar_t>
903 : __conditional_t<sizeof(wchar_t) == sizeof(char32_t),
904 std::codecvt_utf8<wchar_t>,
905 std::codecvt_utf8_utf16<wchar_t>>
908 template<
typename _E
charT>
910 path::_S_convert(
const _EcharT* __f,
const _EcharT* __l)
912 static_assert(__detail::__is_encoded_char<_EcharT>);
914#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
915# define _GLIBCXX_CONV_FROM_UTF8(S) __detail::__wstr_from_utf8(S)
917# define _GLIBCXX_CONV_FROM_UTF8(S) S
920 if constexpr (is_same_v<_EcharT, value_type>)
921 return basic_string_view<value_type>(__f, __l - __f);
922#ifdef _GLIBCXX_USE_CHAR8_T
923 else if constexpr (is_same_v<_EcharT, char8_t>)
925 string_view __str(
reinterpret_cast<const char*
>(__f), __l - __f);
926 return _GLIBCXX_CONV_FROM_UTF8(__str);
929#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
930 else if constexpr (is_same_v<_EcharT, char>)
933 path::_Codecvt<wchar_t> __cvt;
934 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
940 path::_Codecvt<_EcharT> __cvt;
942 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
943 return _GLIBCXX_CONV_FROM_UTF8(__str);
945 __detail::__throw_conversion_error();
947#undef _GLIBCXX_CONV_FROM_UTF8
959 using difference_type = std::ptrdiff_t;
960 using value_type = path;
961 using reference =
const path&;
962 using pointer =
const path*;
965 iterator() noexcept : _M_path(
nullptr), _M_cur(), _M_at_end() { }
967 iterator(
const iterator&) =
default;
968 iterator& operator=(
const iterator&) =
default;
970 reference operator*()
const noexcept;
973 iterator& operator++()
noexcept;
975 iterator operator++(
int)
noexcept
976 {
auto __tmp = *
this; ++*
this;
return __tmp; }
978 iterator& operator--()
noexcept;
980 iterator operator--(
int)
noexcept
981 {
auto __tmp = *
this; --*
this;
return __tmp; }
984 operator==(
const iterator& __lhs,
const iterator& __rhs)
noexcept
985 {
return __lhs._M_equals(__rhs); }
988 operator!=(
const iterator& __lhs,
const iterator& __rhs)
noexcept
989 {
return !__lhs._M_equals(__rhs); }
995 _M_is_multi()
const noexcept
996 {
return _M_path->_M_type() == _Type::_Multi; }
998 friend difference_type
999 __path_iter_distance(
const iterator& __first,
const iterator& __last)
1002 __glibcxx_assert(__first._M_path !=
nullptr);
1003 __glibcxx_assert(__first._M_path == __last._M_path);
1004 if (__first._M_is_multi())
1006 else if (__first._M_at_end == __last._M_at_end)
1009 return __first._M_at_end ? -1 : 1;
1013 __path_iter_advance(iterator& __i, difference_type __n)
noexcept
1021 __glibcxx_assert(__i._M_path !=
nullptr);
1022 __glibcxx_assert(__i._M_is_multi());
1028 iterator(
const path* __path, path::_List::const_iterator __iter) noexcept
1029 : _M_path(__path), _M_cur(__iter), _M_at_end()
1032 iterator(
const path* __path,
bool __at_end) noexcept
1033 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
1036 bool _M_equals(iterator)
const noexcept;
1038 const path* _M_path;
1039 path::_List::const_iterator _M_cur;
1045 path::operator=(path&& __p)
noexcept
1047 if (&__p ==
this) [[__unlikely__]]
1050 _M_pathname =
std::move(__p._M_pathname);
1057 path::operator=(string_type&& __source)
1061 path::assign(string_type&& __source)
1062 {
return *
this = path(
std::move(__source)); }
1065 path::operator+=(
const string_type& __x)
1072 path::operator+=(
const value_type* __x)
1079 path::operator+=(value_type __x)
1081 _M_concat(basic_string_view<value_type>(&__x, 1));
1086 path::operator+=(basic_string_view<value_type> __x)
1092 template<
typename _CharT>
1093 inline __detail::_Path2<_CharT*>&
1094 path::operator+=(
const _CharT __x)
1096 _M_concat(_S_convert(&__x, &__x + 1));
1101 path::make_preferred()
1103#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1104 auto __pos = _M_pathname.find(L
'/');
1105 while (__pos != _M_pathname.npos)
1107 _M_pathname[__pos] = preferred_separator;
1108 __pos = _M_pathname.find(L
'/', __pos);
1114 inline void path::swap(path& __rhs)
noexcept
1116 _M_pathname.swap(__rhs._M_pathname);
1117 _M_cmpts.swap(__rhs._M_cmpts);
1121 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1122 std::basic_string<_CharT, _Traits, _Allocator>
1123 path::_S_str_convert(basic_string_view<value_type> __str,
1124 const _Allocator& __a)
1126 static_assert(!is_same_v<_CharT, value_type>);
1128 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1130 if (__str.size() == 0)
1131 return _WString(__a);
1133#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1134 string_view __u8str = __str;
1138 std::codecvt_utf8_utf16<value_type> __cvt;
1140 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1141 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1142 _String __u8str{_CharAlloc{__a}};
1143 const value_type* __wfirst = __str.data();
1144 const value_type* __wlast = __wfirst + __str.size();
1145 if (!__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt))
1146 __detail::__throw_conversion_error();
1147 if constexpr (is_same_v<_CharT, char>)
1152 const char* __first = __u8str.data();
1153 const char* __last = __first + __u8str.size();
1156#ifdef _GLIBCXX_USE_CHAR8_T
1157 if constexpr (is_same_v<_CharT, char8_t>)
1158 return _WString(__first, __last, __a);
1163 _WString __wstr(__a);
1164 path::_Codecvt<_CharT> __cvt;
1165 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1169 __detail::__throw_conversion_error();
1173 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1174 inline basic_string<_CharT, _Traits, _Allocator>
1175 path::string(
const _Allocator& __a)
const
1177 if constexpr (is_same_v<_CharT, value_type>)
1178 return { _M_pathname.c_str(), _M_pathname.length(), __a };
1180 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1186#if __glibcxx_format_path >= 202506L
1188 path::display_string()
const
1190#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1192 __unicode::_Utf_view<char, wstring_view>(native()));
1199 path::native_encoded_string()
const
1203#if _GLIBCXX_USE_WCHAR_T
1208#ifdef _GLIBCXX_USE_CHAR8_T
1209 inline std::u8string
1213 path::u8string()
const
1215#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1218 std::codecvt_utf8_utf16<value_type> __cvt;
1219 const value_type* __first = _M_pathname.data();
1220 const value_type* __last = __first + _M_pathname.size();
1221 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1223 __detail::__throw_conversion_error();
1236 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1237 inline std::basic_string<_CharT, _Traits, _Allocator>
1238 path::generic_string(
const _Allocator& __a)
const
1240#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1241 const value_type __slash = L
'/';
1243 const value_type __slash =
'/';
1245 using _Alloc2 =
typename allocator_traits<_Allocator>::template
1246 rebind_alloc<value_type>;
1247 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1249 if (_M_type() == _Type::_Root_dir)
1250 __str.
assign(1, __slash);
1253 __str.
reserve(_M_pathname.size());
1254 bool __add_slash =
false;
1255 for (
auto& __elem : *
this)
1257#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1258 if (__elem._M_type() == _Type::_Root_dir)
1266 __str += basic_string_view<value_type>(__elem._M_pathname);
1267 __add_slash = __elem._M_type() == _Type::_Filename;
1271 if constexpr (is_same_v<_CharT, value_type>)
1274 return _S_str_convert<_CharT, _Traits>(__str, __a);
1278 path::generic_string()
const
1279 {
return generic_string<char>(); }
1281#if __glibcxx_format_path >= 202506L
1283 path::generic_display_string()
const
1285#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1286 string_type __str = generic_string<wchar_t>();
1288 __unicode::_Utf_view<char, wstring_view>(__str));
1290 return generic_string<char>();
1295 path::generic_native_encoded_string()
const
1296 {
return generic_string<char>(); }
1299#if _GLIBCXX_USE_WCHAR_T
1301 path::generic_wstring()
const
1302 {
return generic_string<wchar_t>(); }
1305#ifdef _GLIBCXX_USE_CHAR8_T
1306 inline std::u8string
1307 path::generic_u8string()
const
1308 {
return generic_string<char8_t>(); }
1311 path::generic_u8string()
const
1312 {
return generic_string(); }
1316 path::generic_u16string()
const
1317 {
return generic_string<char16_t>(); }
1320 path::generic_u32string()
const
1321 {
return generic_string<char32_t>(); }
1324 path::compare(
const string_type& __s)
const noexcept
1325 {
return compare(basic_string_view<value_type>(__s)); }
1328 path::compare(
const value_type* __s)
const noexcept
1329 {
return compare(basic_string_view<value_type>(__s)); }
1332 path::filename()
const
1336 else if (_M_type() == _Type::_Filename)
1338 else if (_M_type() == _Type::_Multi)
1340 if (_M_pathname.back() == preferred_separator)
1342 auto __last = --
end();
1343 if (__last->_M_type() == _Type::_Filename)
1352 auto __ext = _M_find_extension();
1353 if (__ext.first && __ext.second != 0)
1354 return path{__ext.first->substr(0, __ext.second)};
1359 path::extension()
const
1361 auto __ext = _M_find_extension();
1362 if (__ext.first && __ext.second != string_type::npos)
1363 return path{__ext.first->substr(__ext.second)};
1368 path::has_stem() const noexcept
1370 auto __ext = _M_find_extension();
1371 return __ext.first && __ext.second != 0;
1375 path::has_extension() const noexcept
1377 auto __ext = _M_find_extension();
1378 return __ext.first && __ext.second != string_type::npos;
1382 path::is_absolute() const noexcept
1384#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1385 return has_root_name() && has_root_directory();
1387 return has_root_directory();
1391 inline path::iterator
1392 path::begin() const noexcept
1394 if (_M_type() == _Type::_Multi)
1395 return iterator(
this, _M_cmpts.begin());
1396 return iterator(
this,
empty());
1399 inline path::iterator
1400 path::end() const noexcept
1402 if (_M_type() == _Type::_Multi)
1403 return iterator(
this, _M_cmpts.end());
1404 return iterator(
this,
true);
1407 inline path::iterator&
1408 path::iterator::operator++() noexcept
1410 __glibcxx_assert(_M_path !=
nullptr);
1413 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1418 __glibcxx_assert(!_M_at_end);
1424 inline path::iterator&
1425 path::iterator::operator--() noexcept
1427 __glibcxx_assert(_M_path !=
nullptr);
1430 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1435 __glibcxx_assert(_M_at_end);
1441 inline path::iterator::reference
1442 path::iterator::operator*() const noexcept
1444 __glibcxx_assert(_M_path !=
nullptr);
1447 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1454 path::iterator::_M_equals(iterator __rhs)
const noexcept
1456 if (_M_path != __rhs._M_path)
1458 if (_M_path ==
nullptr)
1461 return _M_cur == __rhs._M_cur;
1462 return _M_at_end == __rhs._M_at_end;
1470 path::_S_compare(
const path& __lhs,
const path& __rhs)
noexcept
1471 {
return __lhs.compare(__rhs); }
1474_GLIBCXX_END_NAMESPACE_CXX11
1480distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1482{
return __path_iter_distance(__first, __last); }
1484template<
typename _Distance>
1486 advance(filesystem::path::iterator& __i, _Distance __n)
noexcept
1487 { __path_iter_advance(__i,
static_cast<ptrdiff_t
>(__n)); }
1489extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1496 struct hash<filesystem::path>
1499 operator()(
const filesystem::path& __p)
const noexcept
1500 {
return filesystem::hash_value(__p); }
1503#ifdef __glibcxx_format_path
1504 template<__format::__
char _CharT>
1505 struct formatter<filesystem::path, _CharT>
1507 formatter() =
default;
1509 constexpr typename basic_format_parse_context<_CharT>::iterator
1510 parse(basic_format_parse_context<_CharT>& __pc)
1512 auto __first = __pc.begin();
1513 const auto __last = __pc.end();
1514 __format::_Spec<_CharT> __spec{};
1516 auto __finalize = [
this, &__spec] {
1520 auto __finished = [&] {
1521 if (__first == __last || *__first ==
'}')
1532 __first = __spec._M_parse_fill_and_align(__first, __last);
1536 __first = __spec._M_parse_width(__first, __last, __pc);
1540 if (*__first ==
'?')
1542 __spec._M_debug =
true;
1548 if (*__first ==
'g')
1550 __spec._M_type = __format::_Pres_g;
1556 __format::__failed_to_parse_format_spec();
1559 template<
typename _Out>
1560 typename basic_format_context<_Out, _CharT>::iterator
1561 format(
const filesystem::path& __p,
1562 basic_format_context<_Out, _CharT>& __fc)
const
1564 using _ValueT = filesystem::path::value_type;
1565 using _ViewT = basic_string_view<_ValueT>;
1566 using _FmtStrT = __format::__formatter_str<_CharT>;
1569 filesystem::path::string_type __s;
1570 if (_M_spec._M_type == __format::_Pres_g)
1571 __sv = __s = __p.generic_string<_ValueT>();
1573 __sv = __p.native();
1575 auto __spec = _M_spec;
1577 __spec._M_type = __format::_Pres_none;
1579 if constexpr (is_same_v<_CharT, _ValueT>)
1580 return _FmtStrT(__spec).format(__sv, __fc);
1583 __format::_Str_sink<_ValueT> __sink;
1584 if (__spec._M_debug)
1586 using __format::_Term_quote;
1587 __format::__write_escaped(__sink.out(), __sv, _Term_quote);
1588 __sv = __sink.view();
1589 __spec._M_debug = 0;
1591 return _FmtStrT(__spec)._M_format_range(
1592 __unicode::_Utf_view<_CharT, _ViewT>(__sv), __fc);
1597 set_debug_format() noexcept
1598 { _M_spec._M_debug =
true; }
1601 __format::_Spec<_CharT> _M_spec{};
1605_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.
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.
Template class basic_ostream.
Bidirectional iterators support a superset of forward iterator operations.