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 struct __is_path_iter_src
109 template<
typename _Iter_traits>
110 struct __is_path_iter_src<_Iter_traits,
111 void_t<typename _Iter_traits::value_type>>
112 :
bool_constant<__is_encoded_char<typename _Iter_traits::value_type>>
115 template<
typename _Source>
116 inline constexpr
bool __is_path_src
117 = __is_path_iter_src<iterator_traits<decay_t<_Source>>>::value;
120 inline constexpr
bool __is_path_src<path> =
false;
123 inline constexpr
bool __is_path_src<volatile path> =
false;
126 inline constexpr
bool __is_path_src<void*> =
false;
129 inline constexpr
bool __is_path_src<const void*> =
false;
132 inline constexpr
bool __is_path_src<volatile void*> =
false;
135 inline constexpr
bool __is_path_src<const volatile void*> =
false;
137 template<
typename _CharT,
typename _Traits,
typename _Alloc>
138 inline constexpr
bool
139 __is_path_src<basic_string<_CharT, _Traits, _Alloc>>
140 = __is_encoded_char<_CharT>;
142 template<
typename _CharT,
typename _Traits>
143 inline constexpr
bool
144 __is_path_src<basic_string_view<_CharT, _Traits>>
145 = __is_encoded_char<_CharT>;
148 template<
typename _Tp>
149 using _Path = enable_if_t<__is_path_src<_Tp>, path>;
152 template<
typename _Iter,
typename _Tr = __safe_iterator_traits<_Iter>>
153 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>::value, path>;
155 #if __cpp_lib_concepts
156 template<
typename _Iter>
157 constexpr
bool __is_contiguous = std::contiguous_iterator<_Iter>;
159 template<
typename _Iter>
160 constexpr
bool __is_contiguous =
false;
163 template<
typename _Tp>
164 constexpr
bool __is_contiguous<_Tp*> =
true;
166 template<
typename _Tp,
typename _Seq>
168 __is_contiguous<__gnu_cxx::__normal_iterator<_Tp*, _Seq>> =
true;
170 #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
172 template<
typename _E
charT>
174 = __conditional_t<is_same_v<_EcharT, char8_t>, char, _EcharT>;
176 template<
typename _E
charT>
177 using __unified_u8_t = _EcharT;
184 template<
typename _CharT,
typename _Traits,
typename _Alloc>
185 inline basic_string_view<_CharT>
186 __effective_range(
const basic_string<_CharT, _Traits, _Alloc>& __source)
190 template<
typename _CharT,
typename _Traits>
191 inline basic_string_view<_CharT>
192 __effective_range(
const basic_string_view<_CharT, _Traits>& __source)
197 template<
typename _Source>
199 __effective_range(
const _Source& __source)
202 using _Iter = decltype(std::__niter_base(__source));
203 using value_type =
typename iterator_traits<_Iter>::value_type;
205 if constexpr (__is_contiguous<_Iter>)
206 return basic_string_view<value_type>{&*__source};
211 basic_string<__unified_u8_t<value_type>> __str;
212 _Source __it = __source;
213 for (value_type __ch = *__it; __ch != value_type(); __ch = *++__it)
214 __str.push_back(__ch);
220 template<
typename _Source>
221 struct __source_value_type_impl
224 =
typename __safe_iterator_traits<decay_t<_Source>>::value_type;
227 template<
typename _CharT,
typename _Traits,
typename _Alloc>
228 struct __source_value_type_impl<basic_string<_CharT, _Traits, _Alloc>>
233 template<
typename _CharT,
typename _Traits>
234 struct __source_value_type_impl<basic_string_view<_CharT, _Traits>>
240 template<
typename _Source>
241 using __source_value_t =
typename __source_value_type_impl<_Source>::type;
246 template<
typename _Tp,
typename _Val = __source_value_t<_Tp>>
247 using __value_type_is_char
252 template<
typename _Tp,
typename _Val = __source_value_t<_Tp>>
253 using __value_type_is_char_or_char8_t
255 #ifdef _GLIBCXX_USE_CHAR8_T
256 || std::is_same_v<_Val, char8_t>
261 template<
typename _InputIterator>
263 __string_from_range(_InputIterator __first, _InputIterator __last)
267 static_assert(__is_encoded_char<_EcharT>);
269 if constexpr (__is_contiguous<_InputIterator>)
272 if (
auto __len = __last - __first) [[__likely__]]
273 return basic_string_view<_EcharT>(&*__first, __len);
274 return basic_string_view<_EcharT>();
279 return basic_string<__unified_u8_t<_EcharT>>(__first, __last);
295 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
296 using value_type = wchar_t;
297 static constexpr value_type preferred_separator = L
'\\';
299 # ifdef _GLIBCXX_DOXYGEN
301 using value_type = __os_dependent__;
303 using value_type = char;
305 static constexpr value_type preferred_separator =
'/';
310 enum format :
unsigned char { native_format, generic_format, auto_format };
316 path(
const path& __p) =
default;
318 path(path&& __p) noexcept
319 : _M_pathname(
std::move(__p._M_pathname)),
323 path(string_type&& __source,
format = auto_format)
324 : _M_pathname(
std::
move(__source))
325 { _M_split_cmpts(); }
327 template<
typename _Source,
328 typename _Require = __detail::_Path<_Source>>
329 path(_Source
const& __source,
format = auto_format)
330 : _M_pathname(_S_convert(__detail::__effective_range(__source)))
331 { _M_split_cmpts(); }
333 template<
typename _InputIterator,
334 typename _Require = __detail::_Path2<_InputIterator>>
335 path(_InputIterator __first, _InputIterator __last,
format = auto_format)
336 : _M_pathname(_S_convert(__detail::__string_from_range(__first, __last)))
337 { _M_split_cmpts(); }
339 template<
typename _Source,
340 typename _Require = __detail::_Path<_Source>,
341 typename _Require2 = __detail::__value_type_is_char<_Source>>
342 path(_Source
const& __src,
const locale& __loc,
format = auto_format)
343 : _M_pathname(_S_convert_loc(__detail::__effective_range(__src), __loc))
344 { _M_split_cmpts(); }
346 template<
typename _InputIterator,
347 typename _Require = __detail::_Path2<_InputIterator>,
348 typename _Req2 = __detail::__value_type_is_char<_InputIterator>>
349 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
351 : _M_pathname(_S_convert_loc(__first, __last, __loc))
352 { _M_split_cmpts(); }
358 path& operator=(
const path&);
359 path& operator=(path&&) noexcept;
360 path& operator=(string_type&& __source);
361 path& assign(string_type&& __source);
363 template<typename _Source>
364 __detail::_Path<_Source>&
365 operator=(_Source const& __source)
366 {
return *
this = path(__source); }
368 template<
typename _Source>
369 __detail::_Path<_Source>&
370 assign(_Source
const& __source)
371 {
return *
this = path(__source); }
373 template<
typename _InputIterator>
374 __detail::_Path2<_InputIterator>&
375 assign(_InputIterator __first, _InputIterator __last)
376 {
return *
this = path(__first, __last); }
380 path& operator/=(
const path& __p);
382 template<
typename _Source>
383 __detail::_Path<_Source>&
384 operator/=(_Source
const& __source)
386 _M_append(_S_convert(__detail::__effective_range(__source)));
390 template<
typename _Source>
391 __detail::_Path<_Source>&
392 append(_Source
const& __source)
394 _M_append(_S_convert(__detail::__effective_range(__source)));
398 template<
typename _InputIterator>
399 __detail::_Path2<_InputIterator>&
400 append(_InputIterator __first, _InputIterator __last)
402 _M_append(_S_convert(__detail::__string_from_range(__first, __last)));
408 path& operator+=(
const path& __x);
409 path& operator+=(
const string_type& __x);
410 path& operator+=(
const value_type* __x);
411 path& operator+=(value_type __x);
412 path& operator+=(basic_string_view<value_type> __x);
414 template<
typename _Source>
415 __detail::_Path<_Source>&
416 operator+=(_Source
const& __x) {
return concat(__x); }
418 template<
typename _CharT>
419 __detail::_Path2<_CharT*>&
420 operator+=(_CharT __x);
422 template<
typename _Source>
423 __detail::_Path<_Source>&
424 concat(_Source
const& __x)
426 _M_concat(_S_convert(__detail::__effective_range(__x)));
430 template<
typename _InputIterator>
431 __detail::_Path2<_InputIterator>&
432 concat(_InputIterator __first, _InputIterator __last)
434 _M_concat(_S_convert(__detail::__string_from_range(__first, __last)));
440 void clear() noexcept { _M_pathname.
clear(); _M_split_cmpts(); }
442 path& make_preferred();
443 path& remove_filename();
444 path& replace_filename(
const path& __replacement);
445 path& replace_extension(
const path& __replacement = path());
447 void swap(path& __rhs) noexcept;
451 const string_type& native() const noexcept {
return _M_pathname; }
452 const value_type* c_str() const noexcept {
return _M_pathname.
c_str(); }
453 operator string_type()
const {
return _M_pathname; }
455 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
456 typename _Allocator = std::allocator<_CharT>>
458 string(
const _Allocator& __a = _Allocator())
const;
461 #if _GLIBCXX_USE_WCHAR_T
464 #ifdef _GLIBCXX_USE_CHAR8_T
465 __attribute__((__abi_tag__(
"__u8")))
466 std::u8string u8string() const;
474 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
475 typename _Allocator = std::allocator<_CharT>>
477 generic_string(
const _Allocator& __a = _Allocator())
const;
480 #if _GLIBCXX_USE_WCHAR_T
483 #ifdef _GLIBCXX_USE_CHAR8_T
484 __attribute__((__abi_tag__(
"__u8")))
485 std::u8string generic_u8string() const;
494 int compare(
const path& __p)
const noexcept;
495 int compare(
const string_type& __s)
const noexcept;
496 int compare(
const value_type* __s)
const noexcept;
497 int compare(basic_string_view<value_type> __s)
const noexcept;
501 path root_name()
const;
502 path root_directory()
const;
503 path root_path()
const;
504 path relative_path()
const;
505 path parent_path()
const;
506 path filename()
const;
508 path extension()
const;
512 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.
empty(); }
513 bool has_root_name() const noexcept;
514 bool has_root_directory() const noexcept;
515 bool has_root_path() const noexcept;
516 bool has_relative_path() const noexcept;
517 bool has_parent_path() const noexcept;
518 bool has_filename() const noexcept;
519 bool has_stem() const noexcept;
520 bool has_extension() const noexcept;
521 bool is_absolute() const noexcept;
522 bool is_relative() const noexcept {
return !is_absolute(); }
525 path lexically_normal()
const;
526 path lexically_relative(
const path& base)
const;
527 path lexically_proximate(
const path& base)
const;
531 using const_iterator = iterator;
533 iterator begin() const noexcept;
534 iterator end() const noexcept;
537 template<typename _CharT, typename _Traits>
541 __os <<
std::quoted(__p.string<_CharT, _Traits>());
546 template<
typename _CharT,
typename _Traits>
560 {
return path::_S_compare(__lhs, __rhs) == 0; }
562 #if __cpp_lib_three_way_comparison
564 friend strong_ordering
565 operator<=>(
const path& __lhs,
const path& __rhs) noexcept
566 {
return path::_S_compare(__lhs, __rhs) <=> 0; }
570 {
return !(__lhs == __rhs); }
574 {
return __lhs.compare(__rhs) < 0; }
578 {
return !(__rhs < __lhs); }
582 {
return __rhs < __lhs; }
586 {
return !(__lhs < __rhs); }
592 path __result(__lhs);
598 enum class _Type : unsigned char {
599 _Multi = 0, _Root_name, _Root_dir, _Filename
605 __glibcxx_assert(__type != _Type::_Multi);
606 _M_cmpts.type(__type);
609 enum class _Split { _Stem, _Extension };
611 void _M_append(basic_string_view<value_type>);
612 void _M_concat(basic_string_view<value_type>);
614 pair<const string_type*, size_t> _M_find_extension() const noexcept;
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,
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_t
>(_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;
738 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
740 size_t hash_value(
const path& __p) noexcept;
764 const path& path1()
const noexcept;
765 const path& path2()
const noexcept;
766 const char*
what() const noexcept;
770 std::__shared_ptr<const _Impl> _M_impl;
776 [[noreturn]]
inline void
777 __throw_conversion_error()
780 "Cannot convert character sequence",
781 std::make_error_code(errc::illegal_byte_sequence)));
784 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
785 template<
typename _Tp>
787 __wstr_from_utf8(
const _Tp& __str)
789 static_assert(std::is_same_v<typename _Tp::value_type, char>);
792 std::codecvt_utf8_utf16<wchar_t> __wcvt;
793 const auto __p = __str.
data();
794 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
795 __detail::__throw_conversion_error();
808 template<
typename _InputIterator,
809 typename _Require = __detail::_Path2<_InputIterator>,
811 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
813 u8path(_InputIterator __first, _InputIterator __last)
815 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
816 if constexpr (is_same_v<_CharT, char>)
817 return path{ __detail::__wstr_from_utf8(
818 __detail::__string_from_range(__first, __last)) };
820 return path{ __first, __last };
823 return path{ __first, __last };
831 template<
typename _Source,
832 typename _Require = __detail::_Path<_Source>,
833 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
837 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
838 if constexpr (is_same_v<_CharT, char>)
839 return path{ __detail::__wstr_from_utf8(
840 __detail::__effective_range(__source)) };
842 return path{ __source };
845 return path{ __source };
851 struct path::_Cmpt :
path
854 :
path(__s, __t), _M_pos(__pos) { }
856 _Cmpt() : _M_pos(-1) { }
861 template<
typename _E
charT>
863 path::_S_convert(
const _EcharT* __f,
const _EcharT* __l)
865 static_assert(__detail::__is_encoded_char<_EcharT>);
867 if constexpr (is_same_v<_EcharT, value_type>)
868 return basic_string_view<value_type>(__f, __l - __f);
869 #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
870 else if constexpr (is_same_v<_EcharT, char8_t>)
872 return string_view(
reinterpret_cast<const char*
>(__f), __l - __f);
876 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
878 if constexpr (is_same_v<_EcharT, char>)
880 struct _UCvt :
std::codecvt<wchar_t, char, std::mbstate_t>
882 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
885 #ifdef _GLIBCXX_USE_CHAR8_T
886 else if constexpr (is_same_v<_EcharT, char8_t>)
888 const auto __f2 =
reinterpret_cast<const char*
>(__f);
889 return __detail::__wstr_from_utf8(string_view(__f2, __l - __f));
894 struct _UCvt :
std::codecvt<_EcharT, char, std::mbstate_t>
897 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
898 return __detail::__wstr_from_utf8(__str);
901 struct _UCvt :
std::codecvt<_EcharT, char, std::mbstate_t>
904 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
907 __detail::__throw_conversion_error();
917 using difference_type = std::ptrdiff_t;
923 iterator() noexcept : _M_path(
nullptr), _M_cur(), _M_at_end() { }
934 {
auto __tmp = *
this; ++*
this;
return __tmp; }
939 {
auto __tmp = *
this; --*
this;
return __tmp; }
943 {
return __lhs._M_equals(__rhs); }
947 {
return !__lhs._M_equals(__rhs); }
953 _M_is_multi()
const noexcept
954 {
return _M_path->_M_type() == _Type::_Multi; }
956 friend difference_type
960 __glibcxx_assert(__first._M_path !=
nullptr);
961 __glibcxx_assert(__first._M_path == __last._M_path);
962 if (__first._M_is_multi())
964 else if (__first._M_at_end == __last._M_at_end)
967 return __first._M_at_end ? -1 : 1;
971 __path_iter_advance(
iterator& __i, difference_type __n) noexcept
979 __glibcxx_assert(__i._M_path !=
nullptr);
980 __glibcxx_assert(__i._M_is_multi());
986 iterator(
const path* __path, path::_List::const_iterator __iter) noexcept
987 : _M_path(__path), _M_cur(__iter), _M_at_end()
991 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
994 bool _M_equals(
iterator)
const noexcept;
997 path::_List::const_iterator _M_cur;
1003 path::operator=(
path&& __p) noexcept
1005 if (&__p ==
this) [[__unlikely__]]
1008 _M_pathname =
std::move(__p._M_pathname);
1015 path::operator=(string_type&& __source)
1019 path::assign(string_type&& __source)
1020 {
return *
this = path(
std::move(__source)); }
1023 path::operator+=(
const string_type& __x)
1030 path::operator+=(
const value_type* __x)
1037 path::operator+=(value_type __x)
1039 _M_concat(basic_string_view<value_type>(&__x, 1));
1044 path::operator+=(basic_string_view<value_type> __x)
1050 template<
typename _CharT>
1051 inline __detail::_Path2<_CharT*>&
1052 path::operator+=(
const _CharT __x)
1054 _M_concat(_S_convert(&__x, &__x + 1));
1059 path::make_preferred()
1061 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1062 auto __pos = _M_pathname.find(L
'/');
1063 while (__pos != _M_pathname.npos)
1065 _M_pathname[__pos] = preferred_separator;
1066 __pos = _M_pathname.find(L
'/', __pos);
1072 inline void path::swap(path& __rhs) noexcept
1074 _M_pathname.swap(__rhs._M_pathname);
1075 _M_cmpts.swap(__rhs._M_cmpts);
1079 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1081 path::_S_str_convert(basic_string_view<value_type> __str,
1082 const _Allocator& __a)
1084 static_assert(!is_same_v<_CharT, value_type>);
1086 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1088 if (__str.size() == 0)
1089 return _WString(__a);
1091 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1094 std::codecvt_utf8_utf16<value_type> __cvt;
1096 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1097 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1098 _String __u8str{_CharAlloc{__a}};
1099 const value_type* __wfirst = __str.data();
1100 const value_type* __wlast = __wfirst + __str.size();
1101 if (__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt)) {
1102 if constexpr (is_same_v<_CharT, char>)
1106 const char* __first = __u8str.data();
1107 const char* __last = __first + __u8str.size();
1109 const value_type* __first = __str.data();
1110 const value_type* __last = __first + __str.size();
1114 #ifdef _GLIBCXX_USE_CHAR8_T
1115 if constexpr (is_same_v<_CharT, char8_t>)
1116 return _WString(__first, __last, __a);
1121 _WString __wstr(__a);
1122 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t> { } __cvt;
1123 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1127 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1130 __detail::__throw_conversion_error();
1134 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1135 inline basic_string<_CharT, _Traits, _Allocator>
1136 path::string(
const _Allocator& __a)
const
1138 if constexpr (is_same_v<_CharT, value_type>)
1139 return { _M_pathname.c_str(), _M_pathname.length(), __a };
1141 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1145 path::string()
const {
return string<char>(); }
1147 #if _GLIBCXX_USE_WCHAR_T
1149 path::wstring()
const {
return string<wchar_t>(); }
1152 #ifdef _GLIBCXX_USE_CHAR8_T
1153 inline std::u8string
1154 path::u8string()
const {
return string<char8_t>(); }
1157 path::u8string()
const
1159 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1162 std::codecvt_utf8_utf16<value_type> __cvt;
1163 const value_type* __first = _M_pathname.
data();
1164 const value_type* __last = __first + _M_pathname.size();
1165 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1167 __detail::__throw_conversion_error();
1175 path::u16string()
const {
return string<char16_t>(); }
1178 path::u32string()
const {
return string<char32_t>(); }
1180 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1182 path::generic_string(
const _Allocator& __a)
const
1184 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1185 const value_type __slash = L
'/';
1187 const value_type __slash =
'/';
1189 using _Alloc2 =
typename allocator_traits<_Allocator>::template
1190 rebind_alloc<value_type>;
1191 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1193 if (_M_type() == _Type::_Root_dir)
1194 __str.
assign(1, __slash);
1197 __str.
reserve(_M_pathname.size());
1198 bool __add_slash =
false;
1199 for (
auto& __elem : *
this)
1201 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1202 if (__elem._M_type() == _Type::_Root_dir)
1210 __str += basic_string_view<value_type>(__elem._M_pathname);
1211 __add_slash = __elem._M_type() == _Type::_Filename;
1215 if constexpr (is_same_v<_CharT, value_type>)
1218 return _S_str_convert<_CharT, _Traits>(__str, __a);
1222 path::generic_string()
const
1223 {
return generic_string<char>(); }
1225 #if _GLIBCXX_USE_WCHAR_T
1227 path::generic_wstring()
const
1228 {
return generic_string<wchar_t>(); }
1231 #ifdef _GLIBCXX_USE_CHAR8_T
1232 inline std::u8string
1233 path::generic_u8string()
const
1234 {
return generic_string<char8_t>(); }
1237 path::generic_u8string()
const
1238 {
return generic_string(); }
1242 path::generic_u16string()
const
1243 {
return generic_string<char16_t>(); }
1246 path::generic_u32string()
const
1247 {
return generic_string<char32_t>(); }
1250 path::compare(
const string_type& __s)
const noexcept
1251 {
return compare(basic_string_view<value_type>(__s)); }
1254 path::compare(
const value_type* __s)
const noexcept
1255 {
return compare(basic_string_view<value_type>(__s)); }
1258 path::filename()
const
1262 else if (_M_type() == _Type::_Filename)
1264 else if (_M_type() == _Type::_Multi)
1266 if (_M_pathname.back() == preferred_separator)
1268 auto& __last = *--
end();
1269 if (__last._M_type() == _Type::_Filename)
1278 auto ext = _M_find_extension();
1279 if (ext.first && ext.second != 0)
1280 return path{ext.first->substr(0, ext.second)};
1285 path::extension()
const
1287 auto ext = _M_find_extension();
1288 if (ext.first && ext.second != string_type::npos)
1289 return path{ext.first->substr(ext.second)};
1294 path::has_stem() const noexcept
1296 auto ext = _M_find_extension();
1297 return ext.first && ext.second != 0;
1301 path::has_extension() const noexcept
1303 auto ext = _M_find_extension();
1304 return ext.first && ext.second != string_type::npos;
1308 path::is_absolute() const noexcept
1310 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1311 return has_root_name() && has_root_directory();
1313 return has_root_directory();
1317 inline path::iterator
1318 path::begin() const noexcept
1320 if (_M_type() == _Type::_Multi)
1321 return iterator(
this, _M_cmpts.begin());
1322 return iterator(
this,
empty());
1325 inline path::iterator
1326 path::end() const noexcept
1328 if (_M_type() == _Type::_Multi)
1329 return iterator(
this, _M_cmpts.end());
1330 return iterator(
this,
true);
1333 inline path::iterator&
1334 path::iterator::operator++() noexcept
1336 __glibcxx_assert(_M_path !=
nullptr);
1339 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1344 __glibcxx_assert(!_M_at_end);
1350 inline path::iterator&
1351 path::iterator::operator--() noexcept
1353 __glibcxx_assert(_M_path !=
nullptr);
1356 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1361 __glibcxx_assert(_M_at_end);
1367 inline path::iterator::reference
1368 path::iterator::operator*() const noexcept
1370 __glibcxx_assert(_M_path !=
nullptr);
1373 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1380 path::iterator::_M_equals(iterator __rhs)
const noexcept
1382 if (_M_path != __rhs._M_path)
1384 if (_M_path ==
nullptr)
1387 return _M_cur == __rhs._M_cur;
1388 return _M_at_end == __rhs._M_at_end;
1396 path::_S_compare(
const path& __lhs,
const path& __rhs) noexcept
1397 {
return __lhs.compare(__rhs); }
1400 _GLIBCXX_END_NAMESPACE_CXX11
1406 distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1408 {
return __path_iter_distance(__first, __last); }
1410 template<
typename _Distance>
1412 advance(filesystem::path::iterator& __i, _Distance __n) noexcept
1413 { __path_iter_advance(__i,
static_cast<ptrdiff_t
>(__n)); }
1415 extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1422 struct hash<filesystem::path>
1425 operator()(
const filesystem::path& __p)
const noexcept
1426 {
return filesystem::hash_value(__p); }
1429 _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)
integral_constant< bool, __v > bool_constant
Alias template for compile-time boolean constant types.
void void_t
A metafunction that always yields void, used for detecting valid types.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
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.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
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 * c_str() const noexcept
Return const pointer to null-terminated 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.
const _CharT * data() const noexcept
Return const pointer to contents.
bool empty() const noexcept
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 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.
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.