30#ifndef _GLIBCXX_FS_PATH_H
31#define _GLIBCXX_FS_PATH_H 1
33#if __cplusplus >= 201703L
46#include <bits/shared_ptr.h>
49#if __cplusplus > 201703L
53#if defined(_WIN32) && !defined(__CYGWIN__)
54# define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1
57namespace std _GLIBCXX_VISIBILITY(default)
59_GLIBCXX_BEGIN_NAMESPACE_VERSION
63_GLIBCXX_BEGIN_NAMESPACE_CXX11
72 template<
typename _CharT>
73 inline constexpr bool __is_encoded_char =
false;
75 inline constexpr bool __is_encoded_char<char> =
true;
76#ifdef _GLIBCXX_USE_CHAR8_T
78 inline constexpr bool __is_encoded_char<char8_t> =
true;
80#if _GLIBCXX_USE_WCHAR_T
82 inline constexpr bool __is_encoded_char<wchar_t> =
true;
85 inline constexpr bool __is_encoded_char<char16_t> =
true;
87 inline constexpr bool __is_encoded_char<char32_t> =
true;
89#if __cpp_concepts >= 201907L
90 template<
typename _Iter>
93 template<
typename _Iter>
98 template<>
struct __safe_iterator_traits<void*> { };
99 template<>
struct __safe_iterator_traits<const void*> { };
100 template<>
struct __safe_iterator_traits<volatile void*> { };
101 template<>
struct __safe_iterator_traits<const volatile void*> { };
104 template<
typename _Iter_traits,
typename =
void>
105 inline constexpr bool __is_path_iter_src =
false;
107 template<
typename _Iter_traits>
108 inline constexpr bool
109 __is_path_iter_src<_Iter_traits, void_t<typename _Iter_traits::value_type>>
110 = __is_encoded_char<typename _Iter_traits::value_type>;
112 template<
typename _Source>
113 inline constexpr bool __is_path_src
114 = __is_path_iter_src<iterator_traits<decay_t<_Source>>>;
117 inline constexpr bool __is_path_src<path> =
false;
120 inline constexpr bool __is_path_src<volatile path> =
false;
123 inline constexpr bool __is_path_src<void*> =
false;
126 inline constexpr bool __is_path_src<const void*> =
false;
129 inline constexpr bool __is_path_src<volatile void*> =
false;
132 inline constexpr bool __is_path_src<const volatile void*> =
false;
134 template<
typename _CharT,
typename _Traits,
typename _Alloc>
135 inline constexpr bool
136 __is_path_src<basic_string<_CharT, _Traits, _Alloc>>
137 = __is_encoded_char<_CharT>;
139 template<
typename _CharT,
typename _Traits>
140 inline constexpr bool
141 __is_path_src<basic_string_view<_CharT, _Traits>>
142 = __is_encoded_char<_CharT>;
145 template<
typename _Tp>
146 using _Path = enable_if_t<__is_path_src<_Tp>, path>;
149 template<
typename _Iter,
typename _Tr = __safe_iterator_traits<_Iter>>
150 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>, path>;
152#if __cpp_lib_concepts
153 template<
typename _Iter>
154 constexpr bool __is_contiguous = std::contiguous_iterator<_Iter>;
156 template<
typename _Iter>
157 constexpr bool __is_contiguous =
false;
160 template<
typename _Tp>
161 constexpr bool __is_contiguous<_Tp*> =
true;
163 template<
typename _Tp,
typename _Seq>
165 __is_contiguous<__gnu_cxx::__normal_iterator<_Tp*, _Seq>> =
true;
167#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
169 template<
typename _E
charT>
171 = __conditional_t<is_same_v<_EcharT, char8_t>, char, _EcharT>;
173 template<
typename _E
charT>
174 using __unified_u8_t = _EcharT;
181 template<
typename _CharT,
typename _Traits,
typename _Alloc>
182 inline basic_string_view<_CharT>
183 __effective_range(
const basic_string<_CharT, _Traits, _Alloc>& __source)
187 template<
typename _CharT,
typename _Traits>
188 inline basic_string_view<_CharT>
189 __effective_range(
const basic_string_view<_CharT, _Traits>& __source)
194 template<
typename _Source>
196 __effective_range(
const _Source& __source)
199 using _Iter =
decltype(std::__niter_base(__source));
200 using value_type =
typename iterator_traits<_Iter>::value_type;
202 if constexpr (__is_contiguous<_Iter>)
203 return basic_string_view<value_type>{&*__source};
208 basic_string<__unified_u8_t<value_type>> __str;
209 _Source __it = __source;
210 for (value_type __ch = *__it; __ch != value_type(); __ch = *++__it)
211 __str.push_back(__ch);
217 template<
typename _Source>
218 struct __source_value_type_impl
221 =
typename __safe_iterator_traits<decay_t<_Source>>::value_type;
224 template<
typename _CharT,
typename _Traits,
typename _Alloc>
225 struct __source_value_type_impl<basic_string<_CharT, _Traits, _Alloc>>
230 template<
typename _CharT,
typename _Traits>
231 struct __source_value_type_impl<basic_string_view<_CharT, _Traits>>
237 template<
typename _Source>
238 using __source_value_t =
typename __source_value_type_impl<_Source>::type;
243 template<
typename _Tp,
typename _Val = __source_value_t<_Tp>>
244 using __value_type_is_char
249 template<
typename _Tp,
typename _Val = __source_value_t<_Tp>>
250 using __value_type_is_char_or_char8_t
252#ifdef _GLIBCXX_USE_CHAR8_T
253 || std::is_same_v<_Val, char8_t>
258 template<
typename _InputIterator>
260 __string_from_range(_InputIterator __first, _InputIterator __last)
264 static_assert(__is_encoded_char<_EcharT>);
266 if constexpr (__is_contiguous<_InputIterator>)
269 if (
auto __len = __last - __first) [[__likely__]]
270 return basic_string_view<_EcharT>(&*__first, __len);
271 return basic_string_view<_EcharT>();
276 return basic_string<__unified_u8_t<_EcharT>>(__first, __last);
292#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
293 using value_type = wchar_t;
294 static constexpr value_type preferred_separator = L
'\\';
296# ifdef _GLIBCXX_DOXYGEN
298 using value_type = __os_dependent__;
300 using value_type = char;
302 static constexpr value_type preferred_separator =
'/';
307 enum format :
unsigned char { native_format, generic_format, auto_format };
313 path(
const path& __p) =
default;
315 path(path&& __p) noexcept
316 : _M_pathname(
std::move(__p._M_pathname)),
320 path(string_type&& __source,
format = auto_format)
321 : _M_pathname(
std::
move(__source))
322 { _M_split_cmpts(); }
324 template<
typename _Source,
325 typename _Require = __detail::_Path<_Source>>
326 path(_Source
const& __source,
format = auto_format)
327 : _M_pathname(_S_convert(__detail::__effective_range(__source)))
328 { _M_split_cmpts(); }
330 template<
typename _InputIterator,
331 typename _Require = __detail::_Path2<_InputIterator>>
332 path(_InputIterator __first, _InputIterator __last,
format = auto_format)
333 : _M_pathname(_S_convert(__detail::__string_from_range(__first, __last)))
334 { _M_split_cmpts(); }
336 template<
typename _Source,
337 typename _Require = __detail::_Path<_Source>,
338 typename _Require2 = __detail::__value_type_is_char<_Source>>
339 path(_Source
const& __src,
const locale& __loc,
format = auto_format)
340 : _M_pathname(_S_convert_loc(__detail::__effective_range(__src), __loc))
341 { _M_split_cmpts(); }
343 template<
typename _InputIterator,
344 typename _Require = __detail::_Path2<_InputIterator>,
345 typename _Req2 = __detail::__value_type_is_char<_InputIterator>>
346 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
348 : _M_pathname(_S_convert_loc(__first, __last, __loc))
349 { _M_split_cmpts(); }
355 path& operator=(
const path&);
356 path& operator=(path&&) noexcept;
357 path& operator=(string_type&& __source);
358 path& assign(string_type&& __source);
360 template<typename _Source>
361 __detail::_Path<_Source>&
362 operator=(_Source const& __source)
363 {
return *
this = path(__source); }
365 template<
typename _Source>
366 __detail::_Path<_Source>&
367 assign(_Source
const& __source)
368 {
return *
this = path(__source); }
370 template<
typename _InputIterator>
371 __detail::_Path2<_InputIterator>&
372 assign(_InputIterator __first, _InputIterator __last)
373 {
return *
this = path(__first, __last); }
377 path& operator/=(
const path& __p);
379 template<
typename _Source>
380 __detail::_Path<_Source>&
381 operator/=(_Source
const& __source)
383 _M_append(_S_convert(__detail::__effective_range(__source)));
387 template<
typename _Source>
388 __detail::_Path<_Source>&
389 append(_Source
const& __source)
391 _M_append(_S_convert(__detail::__effective_range(__source)));
395 template<
typename _InputIterator>
396 __detail::_Path2<_InputIterator>&
397 append(_InputIterator __first, _InputIterator __last)
399 _M_append(_S_convert(__detail::__string_from_range(__first, __last)));
405 path& operator+=(
const path& __x);
406 path& operator+=(
const string_type& __x);
407 path& operator+=(
const value_type* __x);
408 path& operator+=(value_type __x);
409 path& operator+=(basic_string_view<value_type> __x);
411 template<
typename _Source>
412 __detail::_Path<_Source>&
413 operator+=(_Source
const& __x) {
return concat(__x); }
415 template<
typename _CharT>
416 __detail::_Path2<_CharT*>&
417 operator+=(_CharT __x);
419 template<
typename _Source>
420 __detail::_Path<_Source>&
421 concat(_Source
const& __x)
423 _M_concat(_S_convert(__detail::__effective_range(__x)));
427 template<
typename _InputIterator>
428 __detail::_Path2<_InputIterator>&
429 concat(_InputIterator __first, _InputIterator __last)
431 _M_concat(_S_convert(__detail::__string_from_range(__first, __last)));
437 void clear() noexcept { _M_pathname.
clear(); _M_split_cmpts(); }
439 path& make_preferred();
440 path& remove_filename();
441 path& replace_filename(
const path& __replacement);
442 path& replace_extension(
const path& __replacement = path());
444 void swap(path& __rhs)
noexcept;
448 const string_type& native() const noexcept {
return _M_pathname; }
449 const value_type* c_str() const noexcept {
return _M_pathname.
c_str(); }
450 operator string_type()
const {
return _M_pathname; }
452 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
453 typename _Allocator = std::allocator<_CharT>>
455 string(
const _Allocator& __a = _Allocator())
const;
458#if _GLIBCXX_USE_WCHAR_T
461#ifdef _GLIBCXX_USE_CHAR8_T
462 __attribute__((__abi_tag__(
"__u8")))
463 std::u8string u8string() const;
471 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
472 typename _Allocator = std::allocator<_CharT>>
474 generic_string(
const _Allocator& __a = _Allocator())
const;
477#if _GLIBCXX_USE_WCHAR_T
480#ifdef _GLIBCXX_USE_CHAR8_T
481 __attribute__((__abi_tag__(
"__u8")))
482 std::u8string generic_u8string() const;
491 int compare(
const path& __p)
const noexcept;
492 int compare(
const string_type& __s)
const noexcept;
493 int compare(
const value_type* __s)
const noexcept;
494 int compare(basic_string_view<value_type> __s)
const noexcept;
498 path root_name()
const;
499 path root_directory()
const;
500 path root_path()
const;
501 path relative_path()
const;
502 path parent_path()
const;
503 path filename()
const;
505 path extension()
const;
509 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.
empty(); }
510 bool has_root_name() const noexcept;
511 bool has_root_directory() const noexcept;
512 bool has_root_path() const noexcept;
513 bool has_relative_path() const noexcept;
514 bool has_parent_path() const noexcept;
515 bool has_filename() const noexcept;
516 bool has_stem() const noexcept;
517 bool has_extension() const noexcept;
518 bool is_absolute() const noexcept;
519 bool is_relative() const noexcept {
return !is_absolute(); }
522 path lexically_normal()
const;
523 path lexically_relative(
const path& base)
const;
524 path lexically_proximate(
const path& base)
const;
528 using const_iterator = iterator;
530 iterator begin() const noexcept;
531 iterator end() const noexcept;
534 template<typename _CharT, typename _Traits>
538 __os <<
std::quoted(__p.string<_CharT, _Traits>());
543 template<
typename _CharT,
typename _Traits>
557 {
return path::_S_compare(__lhs, __rhs) == 0; }
559#if __cpp_lib_three_way_comparison
561 friend strong_ordering
562 operator<=>(
const path& __lhs,
const path& __rhs)
noexcept
563 {
return path::_S_compare(__lhs, __rhs) <=> 0; }
567 {
return !(__lhs == __rhs); }
571 {
return __lhs.compare(__rhs) < 0; }
575 {
return !(__rhs < __lhs); }
579 {
return __rhs < __lhs; }
583 {
return !(__lhs < __rhs); }
589 path __result(__lhs);
595 enum class _Type :
unsigned char {
596 _Multi = 0, _Root_name, _Root_dir, _Filename
602 __glibcxx_assert(__type != _Type::_Multi);
603 _M_cmpts.type(__type);
606 enum class _Split { _Stem, _Extension };
608 void _M_append(basic_string_view<value_type>);
609 void _M_concat(basic_string_view<value_type>);
611 pair<const string_type*, size_t> _M_find_extension() const noexcept;
617 template<typename _Tp>
619 _S_convert(_Tp __str)
620 noexcept(is_same_v<typename _Tp::value_type, value_type>)
622 if constexpr (is_same_v<typename _Tp::value_type, value_type>)
624#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
625 else if constexpr (is_same_v<_Tp, std::u8string>)
629 return string_type(_S_convert(__str.data(),
630 __str.data() + __str.size()));
633 return _S_convert(__str.data(), __str.data() + __str.size());
636 template<
typename _E
charT>
638 _S_convert(
const _EcharT* __first,
const _EcharT* __last);
644 _S_convert_loc(
const char* __first,
const char* __last,
647 template<
typename _Iter>
649 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
651 const auto __s = __detail::__string_from_range(__first, __last);
652 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
655 template<
typename _Tp>
657 _S_convert_loc(
const _Tp& __s,
const std::locale& __loc)
659 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
662 template<
typename _CharT,
typename _Traits,
typename _Allocator>
663 static basic_string<_CharT, _Traits, _Allocator>
664 _S_str_convert(basic_string_view<value_type>,
const _Allocator&);
667 __attribute__((__always_inline__))
669 _S_compare(
const path& __lhs,
const path& __rhs)
noexcept;
671 void _M_split_cmpts();
673 _Type _M_type() const noexcept {
return _M_cmpts.type(); }
675 string_type _M_pathname;
681 using value_type = _Cmpt;
682 using iterator = value_type*;
683 using const_iterator =
const value_type*;
687 _List(_List&&) =
default;
688 _List& operator=(
const _List&);
689 _List& operator=(_List&&) =
default;
692 _Type type() const noexcept
693 {
return _Type(
reinterpret_cast<uintptr_t
>(_M_impl.get()) & 0x3); }
695 void type(_Type)
noexcept;
697 int size() const noexcept;
698 bool empty() const noexcept;
700 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
701 int capacity() const noexcept;
702 void reserve(
int,
bool);
707 iterator begin() noexcept;
708 iterator end() noexcept;
709 const_iterator begin() const noexcept;
710 const_iterator end() const noexcept;
712 value_type& front() noexcept;
713 value_type& back() noexcept;
714 const value_type& front() const noexcept;
715 const value_type& back() const noexcept;
718 void _M_erase_from(const_iterator __pos);
723 void operator()(_Impl*)
const noexcept;
725 unique_ptr<_Impl, _Impl_deleter> _M_impl;
731 template<
typename _E
charT>
struct _Codecvt;
737 inline void swap(path& __lhs, path& __rhs)
noexcept { __lhs.swap(__rhs); }
739 size_t hash_value(
const path& __p)
noexcept;
763 const path& path1()
const noexcept;
764 const path& path2()
const noexcept;
765 const char*
what() const noexcept;
769 std::__shared_ptr<const _Impl> _M_impl;
775 [[noreturn]]
inline void
776 __throw_conversion_error()
779 "Cannot convert character sequence",
783#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
784 template<
typename _Tp>
786 __wstr_from_utf8(
const _Tp& __str)
788 static_assert(std::is_same_v<typename _Tp::value_type, char>);
791 std::codecvt_utf8_utf16<wchar_t> __wcvt;
792 const auto __p = __str.
data();
793 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
794 __detail::__throw_conversion_error();
807 template<
typename _InputIterator,
808 typename _Require = __detail::_Path2<_InputIterator>,
810 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
812 u8path(_InputIterator __first, _InputIterator __last)
814#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
815 if constexpr (is_same_v<_CharT, char>)
816 return path{ __detail::__wstr_from_utf8(
817 __detail::__string_from_range(__first, __last)) };
819 return path{ __first, __last };
822 return path{ __first, __last };
830 template<
typename _Source,
831 typename _Require = __detail::_Path<_Source>,
832 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
836#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
837 if constexpr (is_same_v<_CharT, char>)
838 return path{ __detail::__wstr_from_utf8(
839 __detail::__effective_range(__source)) };
841 return path{ __source };
844 return path{ __source };
850 struct path::_Cmpt :
path
853 :
path(__s, __t), _M_pos(__pos) { }
855 _Cmpt() : _M_pos(-1) { }
866 template<
typename _E
charT>
867 struct path::_Codecvt
880 struct path::_Codecvt<wchar_t>
881 : __conditional_t<sizeof(wchar_t) == sizeof(char32_t),
882 std::codecvt_utf8<wchar_t>,
883 std::codecvt_utf8_utf16<wchar_t>>
886 template<
typename _E
charT>
888 path::_S_convert(
const _EcharT* __f,
const _EcharT* __l)
890 static_assert(__detail::__is_encoded_char<_EcharT>);
892#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
893# define _GLIBCXX_CONV_FROM_UTF8(S) __detail::__wstr_from_utf8(S)
895# define _GLIBCXX_CONV_FROM_UTF8(S) S
898 if constexpr (is_same_v<_EcharT, value_type>)
899 return basic_string_view<value_type>(__f, __l - __f);
900#ifdef _GLIBCXX_USE_CHAR8_T
901 else if constexpr (is_same_v<_EcharT, char8_t>)
903 string_view __str(
reinterpret_cast<const char*
>(__f), __l - __f);
904 return _GLIBCXX_CONV_FROM_UTF8(__str);
907#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
908 else if constexpr (is_same_v<_EcharT, char>)
911 path::_Codecvt<wchar_t> __cvt;
912 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
918 path::_Codecvt<_EcharT> __cvt;
920 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
921 return _GLIBCXX_CONV_FROM_UTF8(__str);
923 __detail::__throw_conversion_error();
925#undef _GLIBCXX_CONV_FROM_UTF8
933 using difference_type = std::ptrdiff_t;
939 iterator() noexcept : _M_path(
nullptr), _M_cur(), _M_at_end() { }
950 {
auto __tmp = *
this; ++*
this;
return __tmp; }
955 {
auto __tmp = *
this; --*
this;
return __tmp; }
959 {
return __lhs._M_equals(__rhs); }
963 {
return !__lhs._M_equals(__rhs); }
969 _M_is_multi()
const noexcept
970 {
return _M_path->_M_type() == _Type::_Multi; }
972 friend difference_type
976 __glibcxx_assert(__first._M_path !=
nullptr);
977 __glibcxx_assert(__first._M_path == __last._M_path);
978 if (__first._M_is_multi())
980 else if (__first._M_at_end == __last._M_at_end)
983 return __first._M_at_end ? -1 : 1;
987 __path_iter_advance(
iterator& __i, difference_type __n)
noexcept
995 __glibcxx_assert(__i._M_path !=
nullptr);
996 __glibcxx_assert(__i._M_is_multi());
1002 iterator(
const path* __path, path::_List::const_iterator __iter) noexcept
1003 : _M_path(__path), _M_cur(__iter), _M_at_end()
1007 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
1010 bool _M_equals(
iterator)
const noexcept;
1012 const path* _M_path;
1013 path::_List::const_iterator _M_cur;
1019 path::operator=(
path&& __p)
noexcept
1021 if (&__p ==
this) [[__unlikely__]]
1024 _M_pathname =
std::move(__p._M_pathname);
1031 path::operator=(string_type&& __source)
1035 path::assign(string_type&& __source)
1036 {
return *
this = path(
std::move(__source)); }
1039 path::operator+=(
const string_type& __x)
1046 path::operator+=(
const value_type* __x)
1053 path::operator+=(value_type __x)
1055 _M_concat(basic_string_view<value_type>(&__x, 1));
1060 path::operator+=(basic_string_view<value_type> __x)
1066 template<
typename _CharT>
1067 inline __detail::_Path2<_CharT*>&
1068 path::operator+=(
const _CharT __x)
1070 _M_concat(_S_convert(&__x, &__x + 1));
1075 path::make_preferred()
1077#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1078 auto __pos = _M_pathname.find(L
'/');
1079 while (__pos != _M_pathname.npos)
1081 _M_pathname[__pos] = preferred_separator;
1082 __pos = _M_pathname.find(L
'/', __pos);
1088 inline void path::swap(path& __rhs)
noexcept
1090 _M_pathname.swap(__rhs._M_pathname);
1091 _M_cmpts.swap(__rhs._M_cmpts);
1095 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1097 path::_S_str_convert(basic_string_view<value_type> __str,
1098 const _Allocator& __a)
1100 static_assert(!is_same_v<_CharT, value_type>);
1102 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1104 if (__str.size() == 0)
1105 return _WString(__a);
1107#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1108 string_view __u8str = __str;
1112 std::codecvt_utf8_utf16<value_type> __cvt;
1114 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1115 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1116 _String __u8str{_CharAlloc{__a}};
1117 const value_type* __wfirst = __str.data();
1118 const value_type* __wlast = __wfirst + __str.size();
1119 if (!__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt))
1120 __detail::__throw_conversion_error();
1121 if constexpr (is_same_v<_CharT, char>)
1126 const char* __first = __u8str.data();
1127 const char* __last = __first + __u8str.size();
1130#ifdef _GLIBCXX_USE_CHAR8_T
1131 if constexpr (is_same_v<_CharT, char8_t>)
1132 return _WString(__first, __last, __a);
1137 _WString __wstr(__a);
1138 path::_Codecvt<_CharT> __cvt;
1139 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1143 __detail::__throw_conversion_error();
1147 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1148 inline basic_string<_CharT, _Traits, _Allocator>
1151 if constexpr (is_same_v<_CharT, value_type>)
1152 return { _M_pathname.
c_str(), _M_pathname.length(), __a };
1154 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1160#if _GLIBCXX_USE_WCHAR_T
1165#ifdef _GLIBCXX_USE_CHAR8_T
1166 inline std::u8string
1167 path::u8string()
const {
return string<char8_t>(); }
1170 path::u8string()
const
1172#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1175 std::codecvt_utf8_utf16<value_type> __cvt;
1176 const value_type* __first = _M_pathname.
data();
1177 const value_type* __last = __first + _M_pathname.size();
1178 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1180 __detail::__throw_conversion_error();
1193 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1195 path::generic_string(
const _Allocator& __a)
const
1197#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1198 const value_type __slash = L
'/';
1200 const value_type __slash =
'/';
1202 using _Alloc2 =
typename allocator_traits<_Allocator>::template
1203 rebind_alloc<value_type>;
1204 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1206 if (_M_type() == _Type::_Root_dir)
1207 __str.
assign(1, __slash);
1210 __str.
reserve(_M_pathname.size());
1211 bool __add_slash =
false;
1212 for (
auto& __elem : *
this)
1214#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1215 if (__elem._M_type() == _Type::_Root_dir)
1223 __str += basic_string_view<value_type>(__elem._M_pathname);
1224 __add_slash = __elem._M_type() == _Type::_Filename;
1228 if constexpr (is_same_v<_CharT, value_type>)
1231 return _S_str_convert<_CharT, _Traits>(__str, __a);
1235 path::generic_string()
const
1236 {
return generic_string<char>(); }
1238#if _GLIBCXX_USE_WCHAR_T
1240 path::generic_wstring()
const
1241 {
return generic_string<wchar_t>(); }
1244#ifdef _GLIBCXX_USE_CHAR8_T
1245 inline std::u8string
1246 path::generic_u8string()
const
1247 {
return generic_string<char8_t>(); }
1250 path::generic_u8string()
const
1251 {
return generic_string(); }
1255 path::generic_u16string()
const
1256 {
return generic_string<char16_t>(); }
1259 path::generic_u32string()
const
1260 {
return generic_string<char32_t>(); }
1263 path::compare(
const string_type& __s)
const noexcept
1264 {
return compare(basic_string_view<value_type>(__s)); }
1267 path::compare(
const value_type* __s)
const noexcept
1268 {
return compare(basic_string_view<value_type>(__s)); }
1271 path::filename()
const
1275 else if (_M_type() == _Type::_Filename)
1277 else if (_M_type() == _Type::_Multi)
1279 if (_M_pathname.back() == preferred_separator)
1281 auto __last = --
end();
1282 if (__last->_M_type() == _Type::_Filename)
1291 auto ext = _M_find_extension();
1292 if (ext.first && ext.second != 0)
1293 return path{ext.first->substr(0, ext.second)};
1298 path::extension()
const
1300 auto ext = _M_find_extension();
1301 if (ext.first && ext.second != string_type::npos)
1302 return path{ext.first->substr(ext.second)};
1307 path::has_stem() const noexcept
1309 auto ext = _M_find_extension();
1310 return ext.first && ext.second != 0;
1314 path::has_extension() const noexcept
1316 auto ext = _M_find_extension();
1317 return ext.first && ext.second != string_type::npos;
1321 path::is_absolute() const noexcept
1323#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1324 return has_root_name() && has_root_directory();
1326 return has_root_directory();
1330 inline path::iterator
1331 path::begin() const noexcept
1333 if (_M_type() == _Type::_Multi)
1334 return iterator(
this, _M_cmpts.begin());
1335 return iterator(
this,
empty());
1338 inline path::iterator
1339 path::end() const noexcept
1341 if (_M_type() == _Type::_Multi)
1342 return iterator(
this, _M_cmpts.end());
1343 return iterator(
this,
true);
1346 inline path::iterator&
1347 path::iterator::operator++() noexcept
1349 __glibcxx_assert(_M_path !=
nullptr);
1352 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1357 __glibcxx_assert(!_M_at_end);
1363 inline path::iterator&
1364 path::iterator::operator--() noexcept
1366 __glibcxx_assert(_M_path !=
nullptr);
1369 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1374 __glibcxx_assert(_M_at_end);
1380 inline path::iterator::reference
1383 __glibcxx_assert(_M_path !=
nullptr);
1386 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1393 path::iterator::_M_equals(iterator __rhs)
const noexcept
1395 if (_M_path != __rhs._M_path)
1397 if (_M_path ==
nullptr)
1400 return _M_cur == __rhs._M_cur;
1401 return _M_at_end == __rhs._M_at_end;
1409 path::_S_compare(
const path& __lhs,
const path& __rhs)
noexcept
1410 {
return __lhs.compare(__rhs); }
1413_GLIBCXX_END_NAMESPACE_CXX11
1419distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1421{
return __path_iter_distance(__first, __last); }
1423template<
typename _Distance>
1425 advance(filesystem::path::iterator& __i, _Distance __n)
noexcept
1426 { __path_iter_advance(__i,
static_cast<ptrdiff_t
>(__n)); }
1428extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1435 struct hash<filesystem::path>
1438 operator()(
const filesystem::path& __p)
const noexcept
1439 {
return filesystem::hash_value(__p); }
1442_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
path u8path(_InputIterator __first, _InputIterator __last)
path u8path(const _Source &__source)
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.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
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.
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 auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
auto quoted(const _CharT *__string, _CharT __delim=_CharT('"'), _CharT __escape = _CharT('\\'))
Manipulator for quoted strings.
Template class basic_istream.
Template class basic_ostream.
A non-owning reference to a string.
An exception type that includes an error_code value.
Primary class template codecvt.
const _CharT * data() const noexcept
Return const pointer to contents.
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
bool empty() const noexcept
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Traits class for iterators.
friend bool operator!=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
friend bool operator<=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
friend bool 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 bool operator>=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
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.
friend bool operator==(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Exception type thrown by the Filesystem library.
const char * what() const noexcept
An iterator for the components of a path.
Container class for localization functionality.
Bidirectional iterators support a superset of forward iterator operations.