30 #ifndef _GLIBCXX_FS_PATH_H 31 #define _GLIBCXX_FS_PATH_H 1 33 #if __cplusplus >= 201703L 36 #include <type_traits> 42 #include <system_error> 47 #if defined(_WIN32) && !defined(__CYGWIN__) 48 # define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1 52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
58 _GLIBCXX_BEGIN_NAMESPACE_CXX11
68 template<
typename _CharT>
71 template<
typename _Iter,
72 typename _Iter_traits = std::iterator_traits<_Iter>>
73 using __is_path_iter_src
74 = __and_<__is_encoded_char<typename _Iter_traits::value_type>,
76 typename _Iter_traits::iterator_category>>;
78 template<
typename _Iter>
79 static __is_path_iter_src<_Iter>
80 __is_path_src(_Iter,
int);
82 template<
typename _CharT,
typename _Traits,
typename _Alloc>
83 static __is_encoded_char<_CharT>
84 __is_path_src(
const basic_string<_CharT, _Traits, _Alloc>&,
int);
86 template<
typename _CharT,
typename _Traits>
87 static __is_encoded_char<_CharT>
88 __is_path_src(
const basic_string_view<_CharT, _Traits>&,
int);
90 template<
typename _Unknown>
92 __is_path_src(
const _Unknown&, ...);
94 template<
typename _Tp1,
typename _Tp2>
95 struct __constructible_from;
97 template<
typename _Iter>
98 struct __constructible_from<_Iter, _Iter>
99 : __is_path_iter_src<_Iter>
102 template<
typename _Source>
103 struct __constructible_from<_Source, void>
104 : decltype(__is_path_src(std::declval<_Source>(), 0))
107 template<
typename _Tp1,
typename _Tp2 =
void>
108 using _Path =
typename 110 __not_<is_void<remove_pointer_t<_Tp1>>>,
111 __constructible_from<_Tp1, _Tp2>>::value,
114 template<
typename _Source>
116 _S_range_begin(_Source __begin) {
return __begin; }
118 struct __null_terminated { };
120 template<
typename _Source>
121 static __null_terminated
122 _S_range_end(_Source) {
return {}; }
124 template<
typename _CharT,
typename _Traits,
typename _Alloc>
126 _S_range_begin(
const basic_string<_CharT, _Traits, _Alloc>& __str)
127 {
return __str.data(); }
129 template<
typename _CharT,
typename _Traits,
typename _Alloc>
131 _S_range_end(
const basic_string<_CharT, _Traits, _Alloc>& __str)
132 {
return __str.data() + __str.size(); }
134 template<
typename _CharT,
typename _Traits>
136 _S_range_begin(
const basic_string_view<_CharT, _Traits>& __str)
137 {
return __str.data(); }
139 template<
typename _CharT,
typename _Traits>
141 _S_range_end(
const basic_string_view<_CharT, _Traits>& __str)
142 {
return __str.data() + __str.size(); }
144 template<
typename _Tp,
145 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
146 typename _Val =
typename std::iterator_traits<_Iter>::value_type>
147 using __value_type_is_char
151 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 152 typedef wchar_t value_type;
153 static constexpr value_type preferred_separator = L
'\\';
155 typedef char value_type;
156 static constexpr value_type preferred_separator =
'/';
160 enum format { native_format, generic_format, auto_format };
166 path(
const path& __p) =
default;
168 path(path&& __p) noexcept
169 : _M_pathname(std::move(__p._M_pathname)), _M_type(__p._M_type)
171 if (_M_type == _Type::_Multi)
176 path(string_type&& __source, format = auto_format)
177 : _M_pathname(
std::move(__source))
178 { _M_split_cmpts(); }
180 template<
typename _Source,
181 typename _Require = _Path<_Source>>
182 path(_Source
const& __source, format = auto_format)
183 : _M_pathname(_S_convert(_S_range_begin(__source),
184 _S_range_end(__source)))
185 { _M_split_cmpts(); }
187 template<
typename _InputIterator,
188 typename _Require = _Path<_InputIterator, _InputIterator>>
189 path(_InputIterator __first, _InputIterator __last, format = auto_format)
190 : _M_pathname(_S_convert(__first, __last))
191 { _M_split_cmpts(); }
193 template<
typename _Source,
194 typename _Require = _Path<_Source>,
195 typename _Require2 = __value_type_is_char<_Source>>
196 path(_Source
const& __source,
const locale& __loc, format = auto_format)
197 : _M_pathname(_S_convert_loc(_S_range_begin(__source),
198 _S_range_end(__source), __loc))
199 { _M_split_cmpts(); }
201 template<
typename _InputIterator,
202 typename _Require = _Path<_InputIterator, _InputIterator>,
203 typename _Require2 = __value_type_is_char<_InputIterator>>
204 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
205 format = auto_format)
206 : _M_pathname(_S_convert_loc(__first, __last, __loc))
207 { _M_split_cmpts(); }
213 path& operator=(
const path& __p) =
default;
214 path& operator=(path&& __p) noexcept;
215 path& operator=(string_type&& __source);
216 path& assign(string_type&& __source);
218 template<
typename _Source>
220 operator=(_Source
const& __source)
221 {
return *
this = path(__source); }
223 template<
typename _Source>
225 assign(_Source
const& __source)
226 {
return *
this = path(__source); }
228 template<
typename _InputIterator>
229 _Path<_InputIterator, _InputIterator>&
230 assign(_InputIterator __first, _InputIterator __last)
231 {
return *
this = path(__first, __last); }
235 path& operator/=(
const path& __p)
237 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 238 if (__p.is_absolute()
239 || (__p.has_root_name() && __p.root_name() != root_name()))
243 string_type __pathname;
244 if (__p.has_root_directory())
245 __pathname = root_name().native();
246 else if (has_filename() || (!has_root_directory() && is_absolute()))
247 __pathname = _M_pathname + preferred_separator;
248 __pathname += __p.relative_path().native();
249 _M_pathname.swap(__pathname);
254 if (__p.is_absolute())
258 if (has_filename() || (_M_type == _Type::_Root_name))
259 _M_pathname += preferred_separator;
260 _M_pathname += __p.native();
267 template <
class _Source>
269 operator/=(_Source
const& __source)
270 {
return _M_append(path(__source)); }
272 template<
typename _Source>
274 append(_Source
const& __source)
275 {
return _M_append(path(__source)); }
277 template<
typename _InputIterator>
278 _Path<_InputIterator, _InputIterator>&
279 append(_InputIterator __first, _InputIterator __last)
280 {
return _M_append(path(__first, __last)); }
284 path& operator+=(
const path& __x);
285 path& operator+=(
const string_type& __x);
286 path& operator+=(
const value_type* __x);
287 path& operator+=(value_type __x);
288 path& operator+=(basic_string_view<value_type> __x);
290 template<
typename _Source>
292 operator+=(_Source
const& __x) {
return concat(__x); }
294 template<
typename _CharT>
295 _Path<_CharT*, _CharT*>&
296 operator+=(_CharT __x);
298 template<
typename _Source>
300 concat(_Source
const& __x)
301 {
return *
this += _S_convert(_S_range_begin(__x), _S_range_end(__x)); }
303 template<
typename _InputIterator>
304 _Path<_InputIterator, _InputIterator>&
305 concat(_InputIterator __first, _InputIterator __last)
306 {
return *
this += _S_convert(__first, __last); }
310 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
312 path& make_preferred();
313 path& remove_filename();
314 path& replace_filename(
const path& __replacement);
315 path& replace_extension(
const path& __replacement = path());
317 void swap(path& __rhs) noexcept;
321 const string_type& native() const noexcept {
return _M_pathname; }
322 const value_type* c_str() const noexcept {
return _M_pathname.c_str(); }
323 operator string_type()
const {
return _M_pathname; }
325 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
326 typename _Allocator = std::allocator<_CharT>>
328 string(
const _Allocator& __a = _Allocator())
const;
331 #if _GLIBCXX_USE_WCHAR_T 339 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
340 typename _Allocator = std::allocator<_CharT>>
342 generic_string(
const _Allocator& __a = _Allocator())
const;
345 #if _GLIBCXX_USE_WCHAR_T 354 int compare(
const path& __p)
const noexcept;
355 int compare(
const string_type& __s)
const;
356 int compare(
const value_type* __s)
const;
357 int compare(
const basic_string_view<value_type> __s)
const;
361 path root_name()
const;
362 path root_directory()
const;
363 path root_path()
const;
364 path relative_path()
const;
365 path parent_path()
const;
366 path filename()
const;
368 path extension()
const;
372 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.empty(); }
373 bool has_root_name()
const;
374 bool has_root_directory()
const;
375 bool has_root_path()
const;
376 bool has_relative_path()
const;
377 bool has_parent_path()
const;
378 bool has_filename()
const;
379 bool has_stem()
const;
380 bool has_extension()
const;
381 bool is_absolute()
const {
return has_root_directory(); }
382 bool is_relative()
const {
return !is_absolute(); }
385 path lexically_normal()
const;
386 path lexically_relative(
const path& base)
const;
387 path lexically_proximate(
const path& base)
const;
391 typedef iterator const_iterator;
393 iterator
begin()
const;
394 iterator
end()
const;
397 enum class _Type : unsigned char {
398 _Multi, _Root_name, _Root_dir, _Filename
401 path(string_type __str, _Type __type) : _M_pathname(__str), _M_type(__type)
403 __glibcxx_assert(_M_type != _Type::_Multi);
406 enum class _Split { _Stem, _Extension };
411 if (__p.is_absolute())
412 operator=(std::move(__p));
413 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 414 else if (__p.has_root_name() && __p.root_name() != root_name())
415 operator=(std::move(__p));
418 operator/=(const_cast<const path&>(__p));
422 pair<const string_type*, size_t> _M_find_extension()
const;
424 template<
typename _CharT>
428 _S_convert(value_type* __src, __null_terminated)
429 {
return string_type(__src); }
432 _S_convert(
const value_type* __src, __null_terminated)
433 {
return string_type(__src); }
435 template<
typename _Iter>
437 _S_convert(_Iter __first, _Iter __last)
439 using __value_type =
typename std::iterator_traits<_Iter>::value_type;
440 return _Cvt<typename remove_cv<__value_type>::type>::
441 _S_convert(__first, __last);
444 template<
typename _InputIterator>
446 _S_convert(_InputIterator __src, __null_terminated)
448 using _Tp =
typename std::iterator_traits<_InputIterator>::value_type;
450 for (; *__src != _Tp{}; ++__src)
456 _S_convert_loc(
const char* __first,
const char* __last,
459 template<
typename _Iter>
461 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
464 return _S_convert_loc(__str.data(), __str.data()+__str.size(), __loc);
467 template<
typename _InputIterator>
469 _S_convert_loc(_InputIterator __src, __null_terminated,
473 while (*__src !=
'\0')
475 return _S_convert_loc(__tmp.
data(), __tmp.
data()+__tmp.
size(), __loc);
478 template<
typename _CharT,
typename _Traits,
typename _Allocator>
479 static basic_string<_CharT, _Traits, _Allocator>
480 _S_str_convert(
const string_type&,
const _Allocator& __a);
482 static bool _S_is_dir_sep(value_type __ch)
484 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 485 return __ch == L
'/' || __ch == preferred_separator;
491 void _M_split_cmpts();
493 void _M_add_root_name(
size_t __n);
494 void _M_add_root_dir(
size_t __pos);
495 void _M_add_filename(
size_t __pos,
size_t __n);
497 string_type _M_pathname;
500 using _List = _GLIBCXX_STD_C::vector<_Cmpt>;
502 _Type _M_type = _Type::_Filename;
507 {
using value_type = char; };
511 {
using value_type = wchar_t; };
515 {
using value_type = char16_t; };
519 {
using value_type = char32_t; };
521 template<
typename _Tp>
522 struct path::__is_encoded_char<const _Tp> : __is_encoded_char<_Tp> { };
524 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
529 inline bool operator<(
const path& __lhs,
const path& __rhs) noexcept
530 {
return __lhs.compare(__rhs) < 0; }
533 inline bool operator<=(
const path& __lhs,
const path& __rhs) noexcept
534 {
return !(__rhs < __lhs); }
537 inline bool operator>(
const path& __lhs,
const path& __rhs) noexcept
538 {
return __rhs < __lhs; }
541 inline bool operator>=(
const path& __lhs,
const path& __rhs) noexcept
542 {
return !(__lhs < __rhs); }
545 inline bool operator==(
const path& __lhs,
const path& __rhs) noexcept
546 {
return __lhs.compare(__rhs) == 0; }
549 inline bool operator!=(
const path& __lhs,
const path& __rhs) noexcept
550 {
return !(__lhs == __rhs); }
553 inline path
operator/(
const path& __lhs,
const path& __rhs)
555 path __result(__lhs);
561 template<
typename _CharT,
typename _Traits>
562 basic_ostream<_CharT, _Traits>&
563 operator<<(basic_ostream<_CharT, _Traits>& __os,
const path& __p)
565 auto __tmp = __p.string<_CharT, _Traits>();
566 using __quoted_string
568 __os << __quoted_string{__tmp,
'"',
'\\'};
573 template<
typename _CharT,
typename _Traits>
574 basic_istream<_CharT, _Traits>&
575 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
577 basic_string<_CharT, _Traits> __tmp;
578 using __quoted_string
580 if (__is >> __quoted_string{ __tmp,
'"',
'\\' })
581 __p = std::move(__tmp);
585 template<
typename _Source>
587 u8path(
const _Source& __source)
590 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 592 return std::filesystem::u8path(__u8str.begin(), __u8str.end());
594 return path{ __source };
598 template<
typename _InputIterator>
600 u8path(_InputIterator __first, _InputIterator __last)
603 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 604 codecvt_utf8<value_type> __cvt;
606 if (__str_codecvt_in(__first, __last, __tmp, __cvt))
607 return path{ __tmp };
611 return path{ __first, __last };
618 filesystem_error(
const string& __what_arg, error_code __ec)
619 : system_error(__ec, __what_arg) { }
621 filesystem_error(
const string& __what_arg,
const path& __p1,
623 : system_error(__ec, __what_arg), _M_path1(__p1) { }
625 filesystem_error(
const string& __what_arg,
const path& __p1,
626 const path& __p2, error_code __ec)
627 : system_error(__ec, __what_arg), _M_path1(__p1), _M_path2(__p2)
632 const path& path1() const noexcept {
return _M_path1; }
633 const path& path2() const noexcept {
return _M_path2; }
634 const char* what() const noexcept {
return _M_what.c_str(); }
644 struct path::_Cmpt : path
646 _Cmpt(string_type __s, _Type __t,
size_t __pos)
647 : path(
std::move(__s), __t), _M_pos(__pos) { }
649 _Cmpt() : _M_pos(-1) { }
656 struct path::_Cvt<path::value_type>
658 template<
typename _Iter>
660 _S_convert(_Iter __first, _Iter __last)
661 {
return string_type{__first, __last}; }
664 template<
typename _CharT>
667 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 669 _S_wconvert(
const char* __f,
const char* __l,
true_type)
672 const auto& __cvt = std::use_facet<_Cvt>(
std::locale{});
674 if (__str_codecvt_in(__f, __l, __wstr, __cvt))
676 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
677 "Cannot convert character sequence",
678 std::make_error_code(errc::illegal_byte_sequence)));
682 _S_wconvert(
const _CharT* __f,
const _CharT* __l,
false_type)
684 std::codecvt_utf8<_CharT> __cvt;
686 if (__str_codecvt_out(__f, __l, __str, __cvt))
688 const char* __f2 = __str.
data();
689 const char* __l2 = __f2 + __str.
size();
690 std::codecvt_utf8<wchar_t> __wcvt;
692 if (__str_codecvt_in(__f2, __l2, __wstr, __wcvt))
695 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
696 "Cannot convert character sequence",
697 std::make_error_code(errc::illegal_byte_sequence)));
701 _S_convert(
const _CharT* __f,
const _CharT* __l)
703 return _S_wconvert(__f, __l, is_same<_CharT, char>{});
707 _S_convert(
const _CharT* __f,
const _CharT* __l)
709 std::codecvt_utf8<_CharT> __cvt;
711 if (__str_codecvt_out(__f, __l, __str, __cvt))
713 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
714 "Cannot convert character sequence",
715 std::make_error_code(errc::illegal_byte_sequence)));
720 _S_convert(_CharT* __f, _CharT* __l)
722 return _S_convert(const_cast<const _CharT*>(__f),
723 const_cast<const _CharT*>(__l));
726 template<
typename _Iter>
728 _S_convert(_Iter __first, _Iter __last)
731 return _S_convert(__str.
data(), __str.
data() + __str.
size());
734 template<
typename _Iter,
typename _Cont>
736 _S_convert(__gnu_cxx::__normal_iterator<_Iter, _Cont> __first,
737 __gnu_cxx::__normal_iterator<_Iter, _Cont> __last)
738 {
return _S_convert(__first.base(), __last.base()); }
745 using difference_type = std::ptrdiff_t;
746 using value_type = path;
747 using reference =
const path&;
748 using pointer =
const path*;
751 iterator() : _M_path(nullptr), _M_cur(), _M_at_end() { }
753 iterator(
const iterator&) =
default;
754 iterator& operator=(
const iterator&) =
default;
759 iterator& operator++();
760 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
762 iterator& operator--();
763 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
765 friend bool operator==(
const iterator& __lhs,
const iterator& __rhs)
766 {
return __lhs._M_equals(__rhs); }
768 friend bool operator!=(
const iterator& __lhs,
const iterator& __rhs)
769 {
return !__lhs._M_equals(__rhs); }
774 iterator(
const path* __path, path::_List::const_iterator __iter)
775 : _M_path(__path), _M_cur(__iter), _M_at_end()
778 iterator(
const path* __path,
bool __at_end)
779 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
782 bool _M_equals(iterator)
const;
785 path::_List::const_iterator _M_cur;
791 path::operator=(path&& __p) noexcept
796 _M_pathname = std::move(__p._M_pathname);
797 _M_cmpts = std::move(__p._M_cmpts);
798 _M_type = __p._M_type;
804 path::operator=(string_type&& __source)
805 {
return *
this = path(std::move(__source)); }
808 path::assign(string_type&& __source)
809 {
return *
this = path(std::move(__source)); }
812 path::operator+=(
const path& __p)
814 return operator+=(__p.native());
818 path::operator+=(
const string_type& __x)
826 path::operator+=(
const value_type* __x)
834 path::operator+=(value_type __x)
842 path::operator+=(basic_string_view<value_type> __x)
844 _M_pathname.append(__x.data(), __x.size());
849 template<
typename _CharT>
850 inline path::_Path<_CharT*, _CharT*>&
851 path::operator+=(_CharT __x)
854 return concat(__addr, __addr + 1);
858 path::make_preferred()
860 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 861 std::replace(_M_pathname.begin(), _M_pathname.end(), L
'/',
862 preferred_separator);
867 inline void path::swap(path& __rhs) noexcept
869 _M_pathname.swap(__rhs._M_pathname);
870 _M_cmpts.swap(__rhs._M_cmpts);
871 std::swap(_M_type, __rhs._M_type);
874 template<
typename _CharT,
typename _Traits,
typename _Allocator>
876 path::_S_str_convert(
const string_type& __str,
const _Allocator& __a)
878 if (__str.size() == 0)
881 const value_type* __first = __str.data();
882 const value_type* __last = __first + __str.size();
884 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 885 using _CharAlloc = __alloc_rebind<_Allocator, char>;
886 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
887 using _WString = basic_string<_CharT, _Traits, _Allocator>;
890 codecvt_utf8<value_type> __cvt;
891 _String __u8str{_CharAlloc{__a}};
892 if (__str_codecvt_out(__first, __last, __u8str, __cvt))
894 if constexpr (is_same_v<_CharT, char>)
900 codecvt_utf8<_CharT> __cvt;
901 const char* __f = __u8str.
data();
902 const char* __l = __f + __u8str.size();
903 if (__str_codecvt_in(__f, __l, __wstr, __cvt))
908 codecvt_utf8<_CharT> __cvt;
909 basic_string<_CharT, _Traits, _Allocator> __wstr{__a};
910 if (__str_codecvt_in(__first, __last, __wstr, __cvt))
913 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
914 "Cannot convert character sequence",
915 std::make_error_code(errc::illegal_byte_sequence)));
918 template<
typename _CharT,
typename _Traits,
typename _Allocator>
919 inline basic_string<_CharT, _Traits, _Allocator>
922 if constexpr (is_same_v<_CharT, value_type>)
923 #if _GLIBCXX_USE_CXX11_ABI 924 return { _M_pathname, __a };
926 return { _M_pathname, string_type::size_type(0), __a };
929 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
935 #if _GLIBCXX_USE_WCHAR_T 941 path::u8string()
const 943 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 946 codecvt_utf8<value_type> __cvt;
947 const value_type* __first = _M_pathname.
data();
948 const value_type* __last = __first + _M_pathname.size();
949 if (__str_codecvt_out(__first, __last, __str, __cvt))
951 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
952 "Cannot convert character sequence",
953 std::make_error_code(errc::illegal_byte_sequence)));
965 template<
typename _CharT,
typename _Traits,
typename _Allocator>
967 path::generic_string(
const _Allocator& __a)
const 969 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS 970 const value_type __slash = L
'/';
972 const value_type __slash =
'/';
974 string_type __str(__a);
976 if (_M_type == _Type::_Root_dir)
980 __str.
reserve(_M_pathname.size());
981 bool __add_slash =
false;
982 for (
auto& __elem : *
this)
986 __str += __elem._M_pathname;
987 __add_slash = __elem._M_type == _Type::_Filename;
991 if constexpr (is_same_v<_CharT, value_type>)
994 return _S_str_convert<_CharT, _Traits>(__str, __a);
998 path::generic_string()
const 999 {
return generic_string<char>(); }
1001 #if _GLIBCXX_USE_WCHAR_T 1003 path::generic_wstring()
const 1004 {
return generic_string<wchar_t>(); }
1008 path::generic_u8string()
const 1009 {
return generic_string(); }
1012 path::generic_u16string()
const 1013 {
return generic_string<char16_t>(); }
1016 path::generic_u32string()
const 1017 {
return generic_string<char32_t>(); }
1020 path::compare(
const string_type& __s)
const {
return compare(path(__s)); }
1023 path::compare(
const value_type* __s)
const {
return compare(path(__s)); }
1026 path::compare(basic_string_view<value_type> __s)
const 1027 {
return compare(path(__s)); }
1030 path::filename()
const 1034 else if (_M_type == _Type::_Filename)
1036 else if (_M_type == _Type::_Multi)
1038 if (_M_pathname.back() == preferred_separator)
1040 auto& __last = *--
end();
1041 if (__last._M_type == _Type::_Filename)
1050 auto ext = _M_find_extension();
1051 if (ext.first && ext.second != 0)
1052 return path{ext.first->substr(0, ext.second)};
1057 path::extension()
const 1059 auto ext = _M_find_extension();
1060 if (ext.first && ext.second != string_type::npos)
1061 return path{ext.first->substr(ext.second)};
1066 path::has_stem()
const 1068 auto ext = _M_find_extension();
1069 return ext.first && ext.second != 0;
1073 path::has_extension()
const 1075 auto ext = _M_find_extension();
1076 return ext.first && ext.second != string_type::npos;
1079 inline path::iterator
1082 if (_M_type == _Type::_Multi)
1083 return iterator(
this, _M_cmpts.begin());
1084 return iterator(
this, empty());
1087 inline path::iterator
1090 if (_M_type == _Type::_Multi)
1091 return iterator(
this, _M_cmpts.end());
1092 return iterator(
this,
true);
1095 inline path::iterator&
1096 path::iterator::operator++()
1098 __glibcxx_assert(_M_path !=
nullptr);
1099 if (_M_path->_M_type == _Type::_Multi)
1101 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1106 __glibcxx_assert(!_M_at_end);
1112 inline path::iterator&
1113 path::iterator::operator--()
1115 __glibcxx_assert(_M_path !=
nullptr);
1116 if (_M_path->_M_type == _Type::_Multi)
1118 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1123 __glibcxx_assert(_M_at_end);
1129 inline path::iterator::reference
1130 path::iterator::operator*()
const 1132 __glibcxx_assert(_M_path !=
nullptr);
1133 if (_M_path->_M_type == _Type::_Multi)
1135 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1142 path::iterator::_M_equals(iterator __rhs)
const 1144 if (_M_path != __rhs._M_path)
1146 if (_M_path ==
nullptr)
1148 if (_M_path->_M_type == path::_Type::_Multi)
1149 return _M_cur == __rhs._M_cur;
1150 return _M_at_end == __rhs._M_at_end;
1154 _GLIBCXX_END_NAMESPACE_CXX11
1157 _GLIBCXX_END_NAMESPACE_VERSION
1162 #endif // _GLIBCXX_FS_PATH_H Class codecvt<wchar_t, char, mbstate_t> specialization.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Thrown to indicate error code of underlying system.
Bidirectional iterators support a superset of forward iterator operations.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
Struct for delimited strings.
Define a member typedef type only if a boolean constant is true.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string< wchar_t > wstring
A string of wchar_t.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
void push_back(_CharT __c)
Append a single character.
ISO C++ entities toplevel namespace is std.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__old_value, const _Tp &__new_value)
Replace each occurrence of one value in a sequence with another value.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
basic_string< char32_t > u32string
A string of char32_t.
size_t hash_value(const path &__p) noexcept
Compare paths.
path u8path(const _Source &__source)
Compare paths.
basic_string< char16_t > u16string
A string of char16_t.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
static const locale & classic()
Return reference to the C locale.
basic_string< char > string
A string of char.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
const _CharT * data() const noexcept
Return const pointer to contents.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.