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 57 namespace 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);
296 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 297 using value_type = wchar_t;
298 static constexpr value_type preferred_separator = L
'\\';
300 # ifdef _GLIBCXX_DOXYGEN 302 using value_type = __os_dependent__;
304 using value_type = char;
306 static constexpr value_type preferred_separator =
'/';
311 enum format :
unsigned char { native_format, generic_format, auto_format };
317 path(
const path& __p) =
default;
319 path(path&& __p) noexcept
320 : _M_pathname(
std::move(__p._M_pathname)),
326 { _M_split_cmpts(); }
328 template<
typename _Source,
329 typename _Require = __detail::_Path<_Source>>
330 path(_Source
const& __source,
format = auto_format)
331 : _M_pathname(_S_convert(__detail::__effective_range(__source)))
332 { _M_split_cmpts(); }
334 template<
typename _InputIterator,
335 typename _Require = __detail::_Path2<_InputIterator>>
336 path(_InputIterator __first, _InputIterator __last,
format = auto_format)
337 : _M_pathname(_S_convert(__detail::__string_from_range(__first, __last)))
338 { _M_split_cmpts(); }
340 template<
typename _Source,
341 typename _Require = __detail::_Path<_Source>,
342 typename _Require2 = __detail::__value_type_is_char<_Source>>
343 path(_Source
const& __src,
const locale& __loc,
format = auto_format)
344 : _M_pathname(_S_convert_loc(__detail::__effective_range(__src), __loc))
345 { _M_split_cmpts(); }
347 template<
typename _InputIterator,
348 typename _Require = __detail::_Path2<_InputIterator>,
349 typename _Req2 = __detail::__value_type_is_char<_InputIterator>>
350 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
352 : _M_pathname(_S_convert_loc(__first, __last, __loc))
353 { _M_split_cmpts(); }
359 path& operator=(
const path&);
360 path& operator=(path&&) noexcept;
364 template<
typename _Source>
365 __detail::_Path<_Source>&
366 operator=(_Source
const& __source)
367 {
return *
this = path(__source); }
369 template<
typename _Source>
370 __detail::_Path<_Source>&
371 assign(_Source
const& __source)
372 {
return *
this = path(__source); }
374 template<
typename _InputIterator>
375 __detail::_Path2<_InputIterator>&
376 assign(_InputIterator __first, _InputIterator __last)
377 {
return *
this = path(__first, __last); }
381 path& operator/=(
const path& __p);
383 template<
typename _Source>
384 __detail::_Path<_Source>&
385 operator/=(_Source
const& __source)
387 _M_append(_S_convert(__detail::__effective_range(__source)));
391 template<
typename _Source>
392 __detail::_Path<_Source>&
393 append(_Source
const& __source)
395 _M_append(_S_convert(__detail::__effective_range(__source)));
399 template<
typename _InputIterator>
400 __detail::_Path2<_InputIterator>&
401 append(_InputIterator __first, _InputIterator __last)
403 _M_append(_S_convert(__detail::__string_from_range(__first, __last)));
409 path& operator+=(
const path& __x);
411 path& operator+=(
const value_type* __x);
412 path& operator+=(value_type __x);
415 template<
typename _Source>
416 __detail::_Path<_Source>&
417 operator+=(_Source
const& __x) {
return concat(__x); }
419 template<
typename _CharT>
420 __detail::_Path2<_CharT*>&
421 operator+=(_CharT __x);
423 template<
typename _Source>
424 __detail::_Path<_Source>&
425 concat(_Source
const& __x)
427 _M_concat(_S_convert(__detail::__effective_range(__x)));
431 template<
typename _InputIterator>
432 __detail::_Path2<_InputIterator>&
433 concat(_InputIterator __first, _InputIterator __last)
435 _M_concat(_S_convert(__detail::__string_from_range(__first, __last)));
441 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
443 path& make_preferred();
444 path& remove_filename();
445 path& replace_filename(
const path& __replacement);
446 path& replace_extension(
const path& __replacement = path());
448 void swap(path& __rhs) noexcept;
452 const string_type& native()
const noexcept {
return _M_pathname; }
453 const value_type* c_str()
const noexcept {
return _M_pathname.c_str(); }
454 operator string_type()
const {
return _M_pathname; }
456 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
457 typename _Allocator = std::allocator<_CharT>>
459 string(
const _Allocator& __a = _Allocator())
const;
462 #if _GLIBCXX_USE_WCHAR_T 465 #ifdef _GLIBCXX_USE_CHAR8_T 466 __attribute__((__abi_tag__(
"__u8")))
467 std::u8string u8string()
const;
470 #endif // _GLIBCXX_USE_CHAR8_T 475 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
476 typename _Allocator = std::allocator<_CharT>>
478 generic_string(
const _Allocator& __a = _Allocator())
const;
481 #if _GLIBCXX_USE_WCHAR_T 484 #ifdef _GLIBCXX_USE_CHAR8_T 485 __attribute__((__abi_tag__(
"__u8")))
486 std::u8string generic_u8string()
const;
489 #endif // _GLIBCXX_USE_CHAR8_T 495 int compare(
const path& __p)
const noexcept;
496 int compare(
const string_type& __s)
const noexcept;
497 int compare(
const value_type* __s)
const noexcept;
502 path root_name()
const;
503 path root_directory()
const;
504 path root_path()
const;
505 path relative_path()
const;
506 path parent_path()
const;
507 path filename()
const;
509 path extension()
const;
513 [[nodiscard]]
bool empty()
const noexcept {
return _M_pathname.empty(); }
514 bool has_root_name()
const noexcept;
515 bool has_root_directory()
const noexcept;
516 bool has_root_path()
const noexcept;
517 bool has_relative_path()
const noexcept;
518 bool has_parent_path()
const noexcept;
519 bool has_filename()
const noexcept;
520 bool has_stem()
const noexcept;
521 bool has_extension()
const noexcept;
522 bool is_absolute()
const noexcept;
523 bool is_relative()
const noexcept {
return !is_absolute(); }
526 path lexically_normal()
const;
527 path lexically_relative(
const path& base)
const;
528 path lexically_proximate(
const path& base)
const;
538 template<
typename _CharT,
typename _Traits>
540 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const path& __p)
542 __os <<
std::quoted(__p.string<_CharT, _Traits>());
547 template<
typename _CharT,
typename _Traits>
560 friend bool operator==(
const path& __lhs,
const path& __rhs) noexcept
561 {
return path::_S_compare(__lhs, __rhs) == 0; }
563 #if __cpp_lib_three_way_comparison 565 friend strong_ordering
566 operator<=>(
const path& __lhs,
const path& __rhs) noexcept
567 {
return path::_S_compare(__lhs, __rhs) <=> 0; }
570 friend bool operator!=(
const path& __lhs,
const path& __rhs) noexcept
571 {
return !(__lhs == __rhs); }
574 friend bool operator<(
const path& __lhs,
const path& __rhs) noexcept
575 {
return __lhs.compare(__rhs) < 0; }
578 friend bool operator<=(
const path& __lhs,
const path& __rhs) noexcept
579 {
return !(__rhs < __lhs); }
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 !(__lhs < __rhs); }
591 friend path
operator/(
const path& __lhs,
const path& __rhs)
593 path __result(__lhs);
599 enum class _Type : unsigned char {
600 _Multi = 0, _Root_name, _Root_dir, _Filename
605 enum class _Split { _Stem, _Extension };
616 template<
typename _Tp>
618 _S_convert(_Tp __str)
619 noexcept(is_same_v<typename _Tp::value_type, value_type>)
621 if constexpr (is_same_v<typename _Tp::value_type, value_type>)
623 #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T 624 else if constexpr (is_same_v<_Tp, std::u8string>)
629 __str.data() + __str.size()));
632 return _S_convert(__str.data(), __str.data() + __str.size());
635 template<
typename _E
charT>
637 _S_convert(
const _EcharT* __first,
const _EcharT* __last);
643 _S_convert_loc(
const char* __first,
const char* __last,
646 template<
typename _Iter>
648 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
650 const auto __s = __detail::__string_from_range(__first, __last);
651 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
654 template<
typename _Tp>
656 _S_convert_loc(
const _Tp& __s,
const std::locale& __loc)
658 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
661 template<
typename _CharT,
typename _Traits,
typename _Allocator>
666 __attribute__((__always_inline__))
668 _S_compare(
const path& __lhs,
const path& __rhs) noexcept;
670 void _M_split_cmpts();
672 _Type _M_type()
const noexcept {
return _M_cmpts.type(); }
680 using value_type = _Cmpt;
686 _List(_List&&) =
default;
687 _List& operator=(
const _List&);
688 _List& operator=(_List&&) =
default;
691 _Type type()
const noexcept
692 {
return _Type(reinterpret_cast<uintptr_t>(_M_impl.get()) & 0x3); }
694 void type(_Type) noexcept;
696 int size()
const noexcept;
697 bool empty()
const noexcept;
699 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
700 int capacity()
const noexcept;
701 void reserve(
int,
bool);
711 value_type& front() noexcept;
712 value_type& back() noexcept;
713 const value_type& front()
const noexcept;
714 const value_type& back()
const noexcept;
722 void operator()(_Impl*)
const noexcept;
730 template<
typename _E
charT>
struct _Codecvt;
736 #if __cpp_concepts >= 201907L 739 swap(same_as<path>
auto& __lhs, same_as<path>
auto& __rhs) noexcept
740 { __lhs.swap(__rhs); }
742 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
745 size_t hash_value(
const path& __p) noexcept;
773 const path& path1()
const noexcept;
774 const path& path2()
const noexcept;
775 const char* what()
const noexcept;
779 std::__shared_ptr<const _Impl> _M_impl;
785 [[noreturn]]
inline void 786 __throw_conversion_error()
789 "Cannot convert character sequence",
793 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 794 template<
typename _Tp>
796 __wstr_from_utf8(
const _Tp& __str)
798 static_assert(std::is_same_v<typename _Tp::value_type, char>);
801 std::codecvt_utf8_utf16<wchar_t> __wcvt;
802 const auto __p = __str.data();
803 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
804 __detail::__throw_conversion_error();
819 template<
typename _InputIterator,
820 typename _Require = __detail::_Path2<_InputIterator>,
822 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
824 u8path(_InputIterator __first, _InputIterator __last)
826 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 827 if constexpr (is_same_v<_CharT, char>)
828 return path{ __detail::__wstr_from_utf8(
829 __detail::__string_from_range(__first, __last)) };
831 return path{ __first, __last };
834 return path{ __first, __last };
844 template<
typename _Source,
845 typename _Require = __detail::_Path<_Source>,
846 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
850 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 851 if constexpr (is_same_v<_CharT, char>)
852 return path{ __detail::__wstr_from_utf8(
853 __detail::__effective_range(__source)) };
855 return path{ __source };
858 return path{ __source };
864 struct path::_Cmpt : path
868 _Cmpt() : _M_pos(-1) { }
879 template<
typename _E
charT>
880 struct path::_Codecvt
893 struct path::_Codecvt<wchar_t>
894 : __conditional_t<sizeof(wchar_t) == sizeof(char32_t),
895 std::codecvt_utf8<wchar_t>,
896 std::codecvt_utf8_utf16<wchar_t>>
899 template<
typename _E
charT>
901 path::_S_convert(
const _EcharT* __f,
const _EcharT* __l)
903 static_assert(__detail::__is_encoded_char<_EcharT>);
905 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 906 # define _GLIBCXX_CONV_FROM_UTF8(S) __detail::__wstr_from_utf8(S) 908 # define _GLIBCXX_CONV_FROM_UTF8(S) S 911 if constexpr (is_same_v<_EcharT, value_type>)
913 #ifdef _GLIBCXX_USE_CHAR8_T 914 else if constexpr (is_same_v<_EcharT, char8_t>)
916 string_view __str(reinterpret_cast<const char*>(__f), __l - __f);
917 return _GLIBCXX_CONV_FROM_UTF8(__str);
920 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 921 else if constexpr (is_same_v<_EcharT, char>)
924 path::_Codecvt<wchar_t> __cvt;
925 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
931 path::_Codecvt<_EcharT> __cvt;
933 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
934 return _GLIBCXX_CONV_FROM_UTF8(__str);
936 __detail::__throw_conversion_error();
938 #undef _GLIBCXX_CONV_FROM_UTF8 950 using difference_type = std::ptrdiff_t;
956 iterator() noexcept : _M_path(
nullptr), _M_cur(), _M_at_end() { }
967 {
auto __tmp = *
this; ++*
this;
return __tmp; }
972 {
auto __tmp = *
this; --*
this;
return __tmp; }
976 {
return __lhs._M_equals(__rhs); }
980 {
return !__lhs._M_equals(__rhs); }
986 _M_is_multi()
const noexcept
987 {
return _M_path->_M_type() == _Type::_Multi; }
989 friend difference_type
993 __glibcxx_assert(__first._M_path !=
nullptr);
994 __glibcxx_assert(__first._M_path == __last._M_path);
995 if (__first._M_is_multi())
997 else if (__first._M_at_end == __last._M_at_end)
1000 return __first._M_at_end ? -1 : 1;
1004 __path_iter_advance(
iterator& __i, difference_type __n) noexcept
1012 __glibcxx_assert(__i._M_path !=
nullptr);
1013 __glibcxx_assert(__i._M_is_multi());
1019 iterator(
const path* __path, path::_List::const_iterator __iter) noexcept
1020 : _M_path(__path), _M_cur(__iter), _M_at_end()
1023 iterator(
const path* __path,
bool __at_end) noexcept
1024 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
1027 bool _M_equals(
iterator)
const noexcept;
1029 const path* _M_path;
1030 path::_List::const_iterator _M_cur;
1036 path::operator=(path&& __p) noexcept
1038 if (&__p ==
this) [[__unlikely__]]
1041 _M_pathname =
std::move(__p._M_pathname);
1049 {
return *
this = path(
std::move(__source)); }
1053 {
return *
this = path(
std::move(__source)); }
1083 template<
typename _CharT>
1084 inline __detail::_Path2<_CharT*>&
1085 path::operator+=(
const _CharT __x)
1087 _M_concat(_S_convert(&__x, &__x + 1));
1092 path::make_preferred()
1094 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1095 auto __pos = _M_pathname.find(L
'/');
1096 while (__pos != _M_pathname.npos)
1098 _M_pathname[__pos] = preferred_separator;
1099 __pos = _M_pathname.find(L
'/', __pos);
1105 inline void path::swap(path& __rhs) noexcept
1107 _M_pathname.swap(__rhs._M_pathname);
1108 _M_cmpts.swap(__rhs._M_cmpts);
1112 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1115 const _Allocator& __a)
1117 static_assert(!is_same_v<_CharT, value_type>);
1121 if (__str.size() == 0)
1122 return _WString(__a);
1124 #ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1129 std::codecvt_utf8_utf16<value_type> __cvt;
1131 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1133 _String __u8str{_CharAlloc{__a}};
1135 const value_type* __wlast = __wfirst + __str.size();
1136 if (!__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt))
1137 __detail::__throw_conversion_error();
1138 if constexpr (is_same_v<_CharT, char>)
1143 const char* __first = __u8str.data();
1144 const char* __last = __first + __u8str.size();
1147 #ifdef _GLIBCXX_USE_CHAR8_T 1148 if constexpr (is_same_v<_CharT, char8_t>)
1149 return _WString(__first, __last, __a);
1154 _WString __wstr(__a);
1155 path::_Codecvt<_CharT> __cvt;
1156 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1160 __detail::__throw_conversion_error();
1164 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1168 if constexpr (is_same_v<_CharT, value_type>)
1169 return { _M_pathname.
c_str(), _M_pathname.length(), __a };
1171 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1177 #if _GLIBCXX_USE_WCHAR_T 1182 #ifdef _GLIBCXX_USE_CHAR8_T 1183 inline std::u8string
1187 path::u8string()
const 1189 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1192 std::codecvt_utf8_utf16<value_type> __cvt;
1193 const value_type* __first = _M_pathname.data();
1194 const value_type* __last = __first + _M_pathname.size();
1195 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1197 __detail::__throw_conversion_error();
1202 #endif // _GLIBCXX_USE_CHAR8_T 1210 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1212 path::generic_string(
const _Allocator& __a)
const 1214 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1220 rebind_alloc<value_type>;
1223 if (_M_type() == _Type::_Root_dir)
1224 __str.
assign(1, __slash);
1227 __str.
reserve(_M_pathname.size());
1228 bool __add_slash =
false;
1229 for (
auto& __elem : *
this)
1231 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1232 if (__elem._M_type() == _Type::_Root_dir)
1241 __add_slash = __elem._M_type() == _Type::_Filename;
1245 if constexpr (is_same_v<_CharT, value_type>)
1248 return _S_str_convert<_CharT, _Traits>(__str, __a);
1252 path::generic_string()
const 1253 {
return generic_string<char>(); }
1255 #if _GLIBCXX_USE_WCHAR_T 1257 path::generic_wstring()
const 1258 {
return generic_string<wchar_t>(); }
1261 #ifdef _GLIBCXX_USE_CHAR8_T 1262 inline std::u8string
1263 path::generic_u8string()
const 1264 {
return generic_string<char8_t>(); }
1267 path::generic_u8string()
const 1268 {
return generic_string(); }
1272 path::generic_u16string()
const 1273 {
return generic_string<char16_t>(); }
1276 path::generic_u32string()
const 1277 {
return generic_string<char32_t>(); }
1280 path::compare(
const string_type& __s)
const noexcept
1284 path::compare(
const value_type* __s)
const noexcept
1288 path::filename()
const 1292 else if (_M_type() == _Type::_Filename)
1294 else if (_M_type() == _Type::_Multi)
1296 if (_M_pathname.back() == preferred_separator)
1298 auto __last = --
end();
1299 if (__last->_M_type() == _Type::_Filename)
1308 auto ext = _M_find_extension();
1309 if (ext.first && ext.second != 0)
1310 return path{ext.first->substr(0, ext.second)};
1315 path::extension()
const 1317 auto ext = _M_find_extension();
1318 if (ext.first && ext.second != string_type::npos)
1319 return path{ext.first->substr(ext.second)};
1324 path::has_stem()
const noexcept
1326 auto ext = _M_find_extension();
1327 return ext.first && ext.second != 0;
1331 path::has_extension()
const noexcept
1333 auto ext = _M_find_extension();
1334 return ext.first && ext.second != string_type::npos;
1338 path::is_absolute()
const noexcept
1340 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 1341 return has_root_name() && has_root_directory();
1343 return has_root_directory();
1348 path::begin()
const noexcept
1350 if (_M_type() == _Type::_Multi)
1351 return iterator(
this, _M_cmpts.begin());
1356 path::end()
const noexcept
1358 if (_M_type() == _Type::_Multi)
1359 return iterator(
this, _M_cmpts.end());
1364 path::iterator::operator++() noexcept
1366 __glibcxx_assert(_M_path !=
nullptr);
1369 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1374 __glibcxx_assert(!_M_at_end);
1381 path::iterator::operator--() noexcept
1383 __glibcxx_assert(_M_path !=
nullptr);
1386 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1391 __glibcxx_assert(_M_at_end);
1400 __glibcxx_assert(_M_path !=
nullptr);
1403 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1410 path::iterator::_M_equals(
iterator __rhs)
const noexcept
1412 if (_M_path != __rhs._M_path)
1414 if (_M_path ==
nullptr)
1417 return _M_cur == __rhs._M_cur;
1418 return _M_at_end == __rhs._M_at_end;
1426 path::_S_compare(
const path& __lhs,
const path& __rhs) noexcept
1427 {
return __lhs.compare(__rhs); }
1430 _GLIBCXX_END_NAMESPACE_CXX11
1438 {
return __path_iter_distance(__first, __last); }
1440 template<
typename _Distance>
1443 { __path_iter_advance(__i, static_cast<ptrdiff_t>(__n)); }
1445 extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1456 {
return filesystem::hash_value(__p); }
1459 _GLIBCXX_END_NAMESPACE_VERSION
1464 #endif // _GLIBCXX_FS_PATH_H basic_string< char16_t > u16string
A string of char16_t.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
void swap(same_as< path > auto &__lhs, same_as< path > auto &__rhs) noexcept
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.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Template class basic_ostream.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
friend bool operator<=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
path u8path(const _Source &__source)
Uniform interface to all allocator types.
format
path::format is ignored in this implementation
An exception type that includes an error_code value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
friend path operator/(const path &__lhs, const path &__rhs)
Append one path to another.
path u8path(_InputIterator __first, _InputIterator __last)
friend bool operator!=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
error_code make_error_code(future_errc __errc) noexcept
Overload of make_error_code for future_errc.
Exception type thrown by the Filesystem library.
basic_string< char32_t > u32string
A string of char32_t.
auto quoted(const _CharT *__string, _CharT __delim=_CharT('"'), _CharT __escape = _CharT('\))
Manipulator for quoted strings.
ISO C++ entities toplevel namespace is std.
friend bool operator<(const path &__lhs, const path &__rhs) noexcept
Compare paths.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Primary class template codecvt.NB: Generic, mostly useless implementation.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
basic_string< char > string
A string of char.
A non-owning reference to a string.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Struct holding two objects of arbitrary type.
Bidirectional iterators support a superset of forward iterator operations.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Template class basic_istream.
An iterator for the components of a path.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
Traits class for iterators.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
basic_string< wchar_t > wstring
A string of wchar_t.
friend bool operator>(const path &__lhs, const path &__rhs) noexcept
Compare paths.
friend bool operator>=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Primary class template hash.