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<_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;
169 : _M_pathname(std::move(__p._M_pathname)), _M_type(__p._M_type)
175 path(string_type&& __source, format = auto_format)
176 : _M_pathname(std::move(__source))
177 { _M_split_cmpts(); }
179 template<
typename _Source,
180 typename _Require = _Path<_Source>>
181 path(_Source
const& __source, format = auto_format)
182 : _M_pathname(_S_convert(_S_range_begin(__source),
183 _S_range_end(__source)))
184 { _M_split_cmpts(); }
186 template<
typename _InputIterator,
187 typename _Require = _Path<_InputIterator, _InputIterator>>
188 path(_InputIterator __first, _InputIterator __last, format = auto_format)
189 : _M_pathname(_S_convert(__first, __last))
190 { _M_split_cmpts(); }
192 template<
typename _Source,
193 typename _Require = _Path<_Source>,
194 typename _Require2 = __value_type_is_char<_Source>>
195 path(_Source
const& __source,
const locale& __loc, format = auto_format)
196 : _M_pathname(_S_convert_loc(_S_range_begin(__source),
197 _S_range_end(__source), __loc))
198 { _M_split_cmpts(); }
200 template<
typename _InputIterator,
201 typename _Require = _Path<_InputIterator, _InputIterator>,
202 typename _Require2 = __value_type_is_char<_InputIterator>>
203 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
204 format = auto_format)
205 : _M_pathname(_S_convert_loc(__first, __last, __loc))
206 { _M_split_cmpts(); }
212 path& operator=(
const path& __p) =
default;
213 path& operator=(path&& __p)
noexcept;
214 path& operator=(string_type&& __source);
215 path& assign(string_type&& __source);
217 template<typename _Source>
219 operator=(_Source const& __source)
220 {
return *
this = path(__source); }
222 template<
typename _Source>
224 assign(_Source
const& __source)
225 {
return *
this = path(__source); }
227 template<
typename _InputIterator>
228 _Path<_InputIterator, _InputIterator>&
229 assign(_InputIterator __first, _InputIterator __last)
230 {
return *
this = path(__first, __last); }
234 path& operator/=(
const path& __p)
236 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
237 if (__p.is_absolute()
238 || (__p.has_root_name() && __p.root_name() != root_name()))
242 string_type __pathname;
243 if (__p.has_root_directory())
244 __pathname = root_name().native();
245 else if (has_filename() || (!has_root_directory() && is_absolute()))
246 __pathname = _M_pathname + preferred_separator;
247 __pathname += __p.relative_path().native();
248 _M_pathname.swap(__pathname);
253 if (__p.is_absolute())
257 if (has_filename() || (_M_type == _Type::_Root_name))
258 _M_pathname += preferred_separator;
259 _M_pathname += __p.native();
266 template <
class _Source>
268 operator/=(_Source
const& __source)
269 {
return _M_append(path(__source)); }
271 template<
typename _Source>
273 append(_Source
const& __source)
274 {
return _M_append(path(__source)); }
276 template<
typename _InputIterator>
277 _Path<_InputIterator, _InputIterator>&
278 append(_InputIterator __first, _InputIterator __last)
279 {
return _M_append(path(__first, __last)); }
283 path& operator+=(
const path& __x);
284 path& operator+=(
const string_type& __x);
285 path& operator+=(
const value_type* __x);
286 path& operator+=(value_type __x);
287 path& operator+=(basic_string_view<value_type> __x);
289 template<
typename _Source>
291 operator+=(_Source
const& __x) {
return concat(__x); }
293 template<
typename _CharT>
294 _Path<_CharT*, _CharT*>&
295 operator+=(_CharT __x);
297 template<
typename _Source>
299 concat(_Source
const& __x)
300 {
return *
this += _S_convert(_S_range_begin(__x), _S_range_end(__x)); }
302 template<
typename _InputIterator>
303 _Path<_InputIterator, _InputIterator>&
304 concat(_InputIterator __first, _InputIterator __last)
305 {
return *
this += _S_convert(__first, __last); }
309 void clear()
noexcept { _M_pathname.clear(); _M_split_cmpts(); }
311 path& make_preferred();
312 path& remove_filename();
313 path& replace_filename(
const path& __replacement);
314 path& replace_extension(
const path& __replacement = path());
320 const string_type& native() const
noexcept {
return _M_pathname; }
321 const value_type* c_str() const
noexcept {
return _M_pathname.c_str(); }
322 operator string_type()
const {
return _M_pathname; }
324 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
325 typename _Allocator = std::allocator<_CharT>>
327 string(
const _Allocator& __a = _Allocator())
const;
330 #if _GLIBCXX_USE_WCHAR_T
338 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
339 typename _Allocator = std::allocator<_CharT>>
341 generic_string(
const _Allocator& __a = _Allocator())
const;
344 #if _GLIBCXX_USE_WCHAR_T
353 int compare(
const path& __p)
const noexcept;
354 int compare(
const string_type& __s)
const;
355 int compare(
const value_type* __s)
const;
356 int compare(
const basic_string_view<value_type> __s)
const;
360 path root_name()
const;
361 path root_directory()
const;
362 path root_path()
const;
363 path relative_path()
const;
364 path parent_path()
const;
365 path filename()
const;
367 path extension()
const;
371 [[nodiscard]]
bool empty() const
noexcept {
return _M_pathname.empty(); }
372 bool has_root_name()
const;
373 bool has_root_directory()
const;
374 bool has_root_path()
const;
375 bool has_relative_path()
const;
376 bool has_parent_path()
const;
377 bool has_filename()
const;
378 bool has_stem()
const;
379 bool has_extension()
const;
380 bool is_absolute()
const {
return has_root_directory(); }
381 bool is_relative()
const {
return !is_absolute(); }
384 path lexically_normal()
const;
385 path lexically_relative(
const path& base)
const;
386 path lexically_proximate(
const path& base)
const;
390 typedef iterator const_iterator;
392 iterator
begin()
const;
393 iterator
end()
const;
396 enum class _Type : unsigned char {
397 _Multi, _Root_name, _Root_dir, _Filename
400 path(string_type __str, _Type __type) : _M_pathname(__str), _M_type(__type)
402 __glibcxx_assert(_M_type != _Type::_Multi);
405 enum class _Split { _Stem, _Extension };
410 if (__p.is_absolute())
411 operator=(std::move(__p));
412 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
413 else if (__p.has_root_name() && __p.root_name() != root_name())
414 operator=(std::move(__p));
417 operator/=(const_cast<const path&>(__p));
421 pair<const string_type*, size_t> _M_find_extension()
const;
423 template<
typename _CharT>
427 _S_convert(value_type* __src, __null_terminated)
428 {
return string_type(__src); }
431 _S_convert(
const value_type* __src, __null_terminated)
432 {
return string_type(__src); }
434 template<
typename _Iter>
436 _S_convert(_Iter __first, _Iter __last)
438 using __value_type =
typename std::iterator_traits<_Iter>::value_type;
439 return _Cvt<typename remove_cv<__value_type>::type>::
440 _S_convert(__first, __last);
443 template<
typename _InputIterator>
445 _S_convert(_InputIterator __src, __null_terminated)
447 using _Tp =
typename std::iterator_traits<_InputIterator>::value_type;
449 for (; *__src != _Tp{}; ++__src)
455 _S_convert_loc(
const char* __first,
const char* __last,
458 template<
typename _Iter>
460 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
463 return _S_convert_loc(__str.data(), __str.data()+__str.size(), __loc);
466 template<
typename _InputIterator>
468 _S_convert_loc(_InputIterator __src, __null_terminated,
472 while (*__src !=
'\0')
474 return _S_convert_loc(__tmp.
data(), __tmp.
data()+__tmp.
size(), __loc);
477 template<
typename _CharT,
typename _Traits,
typename _Allocator>
478 static basic_string<_CharT, _Traits, _Allocator>
479 _S_str_convert(
const string_type&,
const _Allocator& __a);
481 bool _S_is_dir_sep(value_type __ch)
483 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
484 return __ch == L
'/' || __ch == preferred_separator;
490 void _M_split_cmpts();
492 void _M_add_root_name(
size_t __n);
493 void _M_add_root_dir(
size_t __pos);
494 void _M_add_filename(
size_t __pos,
size_t __n);
496 string_type _M_pathname;
499 using _List = _GLIBCXX_STD_C::vector<_Cmpt>;
501 _Type _M_type = _Type::_Filename;
506 {
using value_type = char; };
510 {
using value_type = wchar_t; };
514 {
using value_type = char16_t; };
518 {
using value_type = char32_t; };
520 template<
typename _Tp>
521 struct path::__is_encoded_char<const _Tp> : __is_encoded_char<_Tp> { };
523 inline void swap(path& __lhs, path& __rhs)
noexcept { __lhs.swap(__rhs); }
525 size_t hash_value(
const path& __p)
noexcept;
528 inline bool operator<(
const path& __lhs,
const path& __rhs)
noexcept
529 {
return __lhs.compare(__rhs) < 0; }
532 inline bool operator<=(
const path& __lhs,
const path& __rhs)
noexcept
533 {
return !(__rhs < __lhs); }
536 inline bool operator>(
const path& __lhs,
const path& __rhs)
noexcept
537 {
return __rhs < __lhs; }
540 inline bool operator>=(
const path& __lhs,
const path& __rhs)
noexcept
541 {
return !(__lhs < __rhs); }
544 inline bool operator==(
const path& __lhs,
const path& __rhs)
noexcept
545 {
return __lhs.compare(__rhs) == 0; }
548 inline bool operator!=(
const path& __lhs,
const path& __rhs)
noexcept
549 {
return !(__lhs == __rhs); }
552 inline path
operator/(
const path& __lhs,
const path& __rhs)
554 path __result(__lhs);
560 template<
typename _CharT,
typename _Traits>
561 basic_ostream<_CharT, _Traits>&
562 operator<<(basic_ostream<_CharT, _Traits>& __os,
const path& __p)
564 auto __tmp = __p.string<_CharT, _Traits>();
565 using __quoted_string
567 __os << __quoted_string{__tmp,
'"',
'\\'};
572 template<
typename _CharT,
typename _Traits>
573 basic_istream<_CharT, _Traits>&
574 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
576 basic_string<_CharT, _Traits> __tmp;
577 using __quoted_string
579 if (__is >> __quoted_string{ __tmp,
'"',
'\\' })
580 __p = std::move(__tmp);
584 template<
typename _Source>
586 u8path(
const _Source& __source)
589 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
591 return std::filesystem::u8path(__u8str.begin(), __u8str.end());
593 return path{ __source };
597 template<
typename _InputIterator>
599 u8path(_InputIterator __first, _InputIterator __last)
602 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
603 codecvt_utf8<value_type> __cvt;
605 if (__str_codecvt_in(__first, __last, __tmp, __cvt))
606 return path{ __tmp };
610 return path{ __first, __last };
617 filesystem_error(
const string& __what_arg, error_code __ec)
618 : system_error(__ec, __what_arg) { }
620 filesystem_error(
const string& __what_arg,
const path& __p1,
622 : system_error(__ec, __what_arg), _M_path1(__p1) { }
624 filesystem_error(
const string& __what_arg,
const path& __p1,
625 const path& __p2, error_code __ec)
626 : system_error(__ec, __what_arg), _M_path1(__p1), _M_path2(__p2)
631 const path& path1() const
noexcept {
return _M_path1; }
632 const path& path2() const
noexcept {
return _M_path2; }
633 const char* what() const
noexcept {
return _M_what.c_str(); }
643 struct path::_Cmpt : path
645 _Cmpt(string_type __s, _Type __t,
size_t __pos)
646 : path(std::move(__s), __t), _M_pos(__pos) { }
648 _Cmpt() : _M_pos(-1) { }
655 struct path::_Cvt<path::value_type>
657 template<
typename _Iter>
659 _S_convert(_Iter __first, _Iter __last)
660 {
return string_type{__first, __last}; }
663 template<
typename _CharT>
666 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
668 _S_wconvert(
const char* __f,
const char* __l,
true_type)
671 const auto& __cvt = std::use_facet<_Cvt>(
std::locale{});
673 if (__str_codecvt_in(__f, __l, __wstr, __cvt))
675 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
676 "Cannot convert character sequence",
677 std::make_error_code(errc::illegal_byte_sequence)));
681 _S_wconvert(
const _CharT* __f,
const _CharT* __l,
false_type)
683 std::codecvt_utf8<_CharT> __cvt;
685 if (__str_codecvt_out(__f, __l, __str, __cvt))
687 const char* __f2 = __str.
data();
688 const char* __l2 = __f2 + __str.
size();
689 std::codecvt_utf8<wchar_t> __wcvt;
691 if (__str_codecvt_in(__f2, __l2, __wstr, __wcvt))
694 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
695 "Cannot convert character sequence",
696 std::make_error_code(errc::illegal_byte_sequence)));
700 _S_convert(
const _CharT* __f,
const _CharT* __l)
702 return _S_wconvert(__f, __l, is_same<_CharT, char>{});
706 _S_convert(
const _CharT* __f,
const _CharT* __l)
708 std::codecvt_utf8<_CharT> __cvt;
710 if (__str_codecvt_out(__f, __l, __str, __cvt))
712 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
713 "Cannot convert character sequence",
714 std::make_error_code(errc::illegal_byte_sequence)));
719 _S_convert(_CharT* __f, _CharT* __l)
721 return _S_convert(const_cast<const _CharT*>(__f),
722 const_cast<const _CharT*>(__l));
725 template<
typename _Iter>
727 _S_convert(_Iter __first, _Iter __last)
730 return _S_convert(__str.
data(), __str.
data() + __str.
size());
733 template<
typename _Iter,
typename _Cont>
735 _S_convert(__gnu_cxx::__normal_iterator<_Iter, _Cont> __first,
736 __gnu_cxx::__normal_iterator<_Iter, _Cont> __last)
737 {
return _S_convert(__first.base(), __last.base()); }
744 using difference_type = std::ptrdiff_t;
745 using value_type = path;
746 using reference =
const path&;
747 using pointer =
const path*;
750 iterator() : _M_path(nullptr), _M_cur(), _M_at_end() { }
752 iterator(
const iterator&) =
default;
753 iterator& operator=(
const iterator&) =
default;
758 iterator& operator++();
759 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
761 iterator& operator--();
762 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
764 friend bool operator==(
const iterator& __lhs,
const iterator& __rhs)
765 {
return __lhs._M_equals(__rhs); }
767 friend bool operator!=(
const iterator& __lhs,
const iterator& __rhs)
768 {
return !__lhs._M_equals(__rhs); }
773 iterator(
const path* __path, path::_List::const_iterator __iter)
774 : _M_path(__path), _M_cur(__iter), _M_at_end()
777 iterator(
const path* __path,
bool __at_end)
778 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
781 bool _M_equals(iterator)
const;
784 path::_List::const_iterator _M_cur;
790 path::operator=(path&& __p)
noexcept
792 _M_pathname = std::move(__p._M_pathname);
793 _M_cmpts = std::move(__p._M_cmpts);
794 _M_type = __p._M_type;
800 path::operator=(string_type&& __source)
801 {
return *
this = path(std::move(__source)); }
804 path::assign(string_type&& __source)
805 {
return *
this = path(std::move(__source)); }
808 path::operator+=(
const path& __p)
810 return operator+=(__p.native());
814 path::operator+=(
const string_type& __x)
822 path::operator+=(
const value_type* __x)
830 path::operator+=(value_type __x)
838 path::operator+=(basic_string_view<value_type> __x)
840 _M_pathname.append(__x.data(), __x.size());
845 template<
typename _CharT>
846 inline path::_Path<_CharT*, _CharT*>&
847 path::operator+=(_CharT __x)
850 return concat(__addr, __addr + 1);
854 path::make_preferred()
856 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
857 std::replace(_M_pathname.begin(), _M_pathname.end(), L
'/',
858 preferred_separator);
863 inline void path::swap(path& __rhs) noexcept
865 _M_pathname.swap(__rhs._M_pathname);
866 _M_cmpts.swap(__rhs._M_cmpts);
867 std::swap(_M_type, __rhs._M_type);
870 template<
typename _CharT,
typename _Traits,
typename _Allocator>
872 path::_S_str_convert(
const string_type& __str,
const _Allocator& __a)
874 if (__str.size() == 0)
877 const value_type* __first = __str.data();
878 const value_type* __last = __first + __str.size();
880 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
881 using _CharAlloc = __alloc_rebind<_Allocator, char>;
882 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
883 using _WString = basic_string<_CharT, _Traits, _Allocator>;
886 codecvt_utf8<value_type> __cvt;
887 _String __u8str{_CharAlloc{__a}};
888 if (__str_codecvt_out(__first, __last, __u8str, __cvt))
890 if constexpr (is_same_v<_CharT, char>)
896 codecvt_utf8<_CharT> __cvt;
897 const char* __f = __u8str.
data();
898 const char* __l = __f + __u8str.size();
899 if (__str_codecvt_in(__f, __l, __wstr, __cvt))
904 codecvt_utf8<_CharT> __cvt;
905 basic_string<_CharT, _Traits, _Allocator> __wstr{__a};
906 if (__str_codecvt_in(__first, __last, __wstr, __cvt))
909 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
910 "Cannot convert character sequence",
911 std::make_error_code(errc::illegal_byte_sequence)));
914 template<
typename _CharT,
typename _Traits,
typename _Allocator>
915 inline basic_string<_CharT, _Traits, _Allocator>
918 if constexpr (is_same_v<_CharT, value_type>)
919 #if _GLIBCXX_USE_CXX11_ABI
920 return { _M_pathname, __a };
922 return { _M_pathname, string_type::size_type(0), __a };
925 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
931 #if _GLIBCXX_USE_WCHAR_T
937 path::u8string()
const
939 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
942 codecvt_utf8<value_type> __cvt;
943 const value_type* __first = _M_pathname.
data();
944 const value_type* __last = __first + _M_pathname.size();
945 if (__str_codecvt_out(__first, __last, __str, __cvt))
947 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
948 "Cannot convert character sequence",
949 std::make_error_code(errc::illegal_byte_sequence)));
961 template<
typename _CharT,
typename _Traits,
typename _Allocator>
963 path::generic_string(
const _Allocator& __a)
const
965 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
966 const value_type __slash = L
'/';
968 const value_type __slash =
'/';
970 string_type __str(__a);
972 if (_M_type == _Type::_Root_dir)
976 __str.
reserve(_M_pathname.size());
977 bool __add_slash =
false;
978 for (
auto& __elem : *
this)
982 __str += __elem._M_pathname;
983 __add_slash = __elem._M_type == _Type::_Filename;
987 if constexpr (is_same_v<_CharT, value_type>)
990 return _S_str_convert<_CharT, _Traits>(__str, __a);
994 path::generic_string()
const
995 {
return generic_string<char>(); }
997 #if _GLIBCXX_USE_WCHAR_T
999 path::generic_wstring()
const
1000 {
return generic_string<wchar_t>(); }
1004 path::generic_u8string()
const
1005 {
return generic_string(); }
1008 path::generic_u16string()
const
1009 {
return generic_string<char16_t>(); }
1012 path::generic_u32string()
const
1013 {
return generic_string<char32_t>(); }
1016 path::compare(
const string_type& __s)
const {
return compare(path(__s)); }
1019 path::compare(
const value_type* __s)
const {
return compare(path(__s)); }
1022 path::compare(basic_string_view<value_type> __s)
const
1023 {
return compare(path(__s)); }
1026 path::filename()
const
1030 else if (_M_type == _Type::_Filename)
1032 else if (_M_type == _Type::_Multi)
1034 if (_M_pathname.back() == preferred_separator)
1036 auto& __last = *--
end();
1037 if (__last._M_type == _Type::_Filename)
1046 auto ext = _M_find_extension();
1047 if (ext.first && ext.second != 0)
1048 return path{ext.first->substr(0, ext.second)};
1053 path::extension()
const
1055 auto ext = _M_find_extension();
1056 if (ext.first && ext.second != string_type::npos)
1057 return path{ext.first->substr(ext.second)};
1062 path::has_stem()
const
1064 auto ext = _M_find_extension();
1065 return ext.first && ext.second != 0;
1069 path::has_extension()
const
1071 auto ext = _M_find_extension();
1072 return ext.first && ext.second != string_type::npos;
1075 inline path::iterator
1078 if (_M_type == _Type::_Multi)
1079 return iterator(
this, _M_cmpts.begin());
1080 return iterator(
this, empty());
1083 inline path::iterator
1086 if (_M_type == _Type::_Multi)
1087 return iterator(
this, _M_cmpts.end());
1088 return iterator(
this,
true);
1091 inline path::iterator&
1092 path::iterator::operator++()
1094 __glibcxx_assert(_M_path !=
nullptr);
1095 if (_M_path->_M_type == _Type::_Multi)
1097 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1102 __glibcxx_assert(!_M_at_end);
1108 inline path::iterator&
1109 path::iterator::operator--()
1111 __glibcxx_assert(_M_path !=
nullptr);
1112 if (_M_path->_M_type == _Type::_Multi)
1114 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1119 __glibcxx_assert(_M_at_end);
1125 inline path::iterator::reference
1126 path::iterator::operator*()
const
1128 __glibcxx_assert(_M_path !=
nullptr);
1129 if (_M_path->_M_type == _Type::_Multi)
1131 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1138 path::iterator::_M_equals(iterator __rhs)
const
1140 if (_M_path != __rhs._M_path)
1142 if (_M_path ==
nullptr)
1144 if (_M_path->_M_type == path::_Type::_Multi)
1145 return _M_cur == __rhs._M_cur;
1146 return _M_at_end == __rhs._M_at_end;
1150 _GLIBCXX_END_NAMESPACE_CXX11
1153 _GLIBCXX_END_NAMESPACE_VERSION
1158 #endif // _GLIBCXX_FS_PATH_H
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Class codecvt<wchar_t, char, mbstate_t> specialization.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
Container class for localization functionality.The locale class is first a class wrapper for C librar...
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
basic_string< wchar_t > wstring
A string of wchar_t.
enable_if< ::__array_traits< _Tp, _Nm >::_Is_swappable::value >::type noexcept(noexcept(__one.swap(__two)))
swap
static const locale & classic()
Return reference to the C locale.
Bidirectional iterators support a superset of forward iterator operations.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
const _CharT * data() const noexcept
Return const pointer to contents.
complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
Define a member typedef type only if a boolean constant is true.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
basic_string< char > string
A string of char.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Thrown to indicate error code of underlying system.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
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.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
basic_string< char16_t > u16string
A string of char16_t.
basic_string< char32_t > u32string
A string of char32_t.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
Struct for delimited strings.
void push_back(_CharT __c)
Append a single character.