30 #ifndef _GLIBCXX_FS_PATH_H
31 #define _GLIBCXX_FS_PATH_H 1
33 #if __cplusplus >= 201703L
36 #include <type_traits>
41 #include <string_view>
42 #include <system_error>
46 #include <bits/shared_ptr.h>
49 #if __cplusplus > 201703L
53 #if defined(_WIN32) && !defined(__CYGWIN__)
54 # define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1
58 namespace std _GLIBCXX_VISIBILITY(default)
60 _GLIBCXX_BEGIN_NAMESPACE_VERSION
64 _GLIBCXX_BEGIN_NAMESPACE_CXX11
75 template<
typename _CharT>
76 using __is_encoded_char = __is_one_of<remove_const_t<_CharT>,
78 #ifdef _GLIBCXX_USE_CHAR8_T
81 #if _GLIBCXX_USE_WCHAR_T
86 template<
typename _Iter,
88 using __is_path_iter_src
89 = __and_<__is_encoded_char<typename _Iter_traits::value_type>,
91 typename _Iter_traits::iterator_category>>;
93 template<
typename _Iter>
94 static __is_path_iter_src<_Iter>
95 __is_path_src(_Iter,
int);
97 template<
typename _CharT,
typename _Traits,
typename _Alloc>
98 static __is_encoded_char<_CharT>
99 __is_path_src(
const basic_string<_CharT, _Traits, _Alloc>&,
int);
101 template<
typename _CharT,
typename _Traits>
102 static __is_encoded_char<_CharT>
103 __is_path_src(
const basic_string_view<_CharT, _Traits>&,
int);
105 template<
typename _Unknown>
107 __is_path_src(
const _Unknown&, ...);
109 template<
typename _Tp1,
typename _Tp2>
110 struct __constructible_from;
112 template<
typename _Iter>
113 struct __constructible_from<_Iter, _Iter>
114 : __is_path_iter_src<_Iter>
117 template<
typename _Source>
118 struct __constructible_from<_Source, void>
119 : decltype(__is_path_src(std::declval<const _Source&>(), 0))
122 template<
typename _Tp1,
typename _Tp2 =
void>
123 using _Path =
typename
125 __not_<is_void<remove_pointer_t<_Tp1>>>,
126 __constructible_from<_Tp1, _Tp2>>::value,
129 template<
typename _Source>
131 _S_range_begin(_Source __begin) {
return __begin; }
133 struct __null_terminated { };
135 template<
typename _Source>
137 _S_range_end(_Source) {
return {}; }
139 template<
typename _CharT,
typename _Traits,
typename _Alloc>
141 _S_range_begin(
const basic_string<_CharT, _Traits, _Alloc>& __str)
142 {
return __str.data(); }
144 template<
typename _CharT,
typename _Traits,
typename _Alloc>
146 _S_range_end(
const basic_string<_CharT, _Traits, _Alloc>& __str)
147 {
return __str.data() + __str.size(); }
149 template<
typename _CharT,
typename _Traits>
151 _S_range_begin(
const basic_string_view<_CharT, _Traits>& __str)
152 {
return __str.data(); }
154 template<
typename _CharT,
typename _Traits>
156 _S_range_end(
const basic_string_view<_CharT, _Traits>& __str)
157 {
return __str.data() + __str.size(); }
159 template<
typename _Tp,
160 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
163 using __value_type_is_char
167 template<
typename _Tp,
168 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
171 using __value_type_is_char_or_char8_t
174 #ifdef _GLIBCXX_USE_CHAR8_T
187 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
188 using value_type = wchar_t;
189 static constexpr value_type preferred_separator = L
'\\';
191 # ifdef _GLIBCXX_DOXYGEN
193 using value_type = __os_dependent__;
195 using value_type = char;
197 static constexpr value_type preferred_separator =
'/';
202 enum format :
unsigned char { native_format, generic_format, auto_format };
208 path(
const path& __p) =
default;
211 #if _GLIBCXX_USE_CXX11_ABI || _GLIBCXX_FULLY_DYNAMIC_STRING == 0
214 : _M_pathname(
std::move(__p._M_pathname)),
218 path(string_type&& __source, format = auto_format)
219 : _M_pathname(
std::
move(__source))
220 { _M_split_cmpts(); }
222 template<
typename _Source,
223 typename _Require = __detail::_Path<_Source>>
224 path(_Source
const& __source, format = auto_format)
225 : _M_pathname(_S_convert(__detail::_S_range_begin(__source),
226 __detail::_S_range_end(__source)))
227 { _M_split_cmpts(); }
229 template<
typename _InputIterator,
230 typename _Require = __detail::_Path<_InputIterator, _InputIterator>>
231 path(_InputIterator __first, _InputIterator __last, format = auto_format)
232 : _M_pathname(_S_convert(__first, __last))
233 { _M_split_cmpts(); }
235 template<
typename _Source,
236 typename _Require = __detail::_Path<_Source>,
237 typename _Require2 = __detail::__value_type_is_char<_Source>>
238 path(_Source
const& __source,
const locale& __loc, format = auto_format)
239 : _M_pathname(_S_convert_loc(__detail::_S_range_begin(__source),
240 __detail::_S_range_end(__source), __loc))
241 { _M_split_cmpts(); }
243 template<
typename _InputIterator,
244 typename _Require = __detail::_Path<_InputIterator, _InputIterator>,
245 typename _Require2 = __detail::__value_type_is_char<_InputIterator>>
246 path(_InputIterator __first, _InputIterator __last,
const locale& __loc,
247 format = auto_format)
248 : _M_pathname(_S_convert_loc(__first, __last, __loc))
249 { _M_split_cmpts(); }
255 path& operator=(
const path&);
256 path& operator=(path&&) noexcept;
257 path& operator=(string_type&& __source);
258 path& assign(string_type&& __source);
260 template<typename _Source>
261 __detail::_Path<_Source>&
262 operator=(_Source const& __source)
263 {
return *
this = path(__source); }
265 template<
typename _Source>
266 __detail::_Path<_Source>&
267 assign(_Source
const& __source)
268 {
return *
this = path(__source); }
270 template<
typename _InputIterator>
271 __detail::_Path<_InputIterator, _InputIterator>&
272 assign(_InputIterator __first, _InputIterator __last)
273 {
return *
this = path(__first, __last); }
277 path& operator/=(
const path& __p);
279 template<
typename _Source>
280 __detail::_Path<_Source>&
281 operator/=(_Source
const& __source)
283 _M_append(_S_convert(__detail::_S_range_begin(__source),
284 __detail::_S_range_end(__source)));
288 template<
typename _Source>
289 __detail::_Path<_Source>&
290 append(_Source
const& __source)
292 _M_append(_S_convert(__detail::_S_range_begin(__source),
293 __detail::_S_range_end(__source)));
297 template<
typename _InputIterator>
298 __detail::_Path<_InputIterator, _InputIterator>&
299 append(_InputIterator __first, _InputIterator __last)
301 _M_append(_S_convert(__first, __last));
307 path& operator+=(
const path& __x);
308 path& operator+=(
const string_type& __x);
309 path& operator+=(
const value_type* __x);
310 path& operator+=(value_type __x);
311 path& operator+=(basic_string_view<value_type> __x);
313 template<
typename _Source>
314 __detail::_Path<_Source>&
315 operator+=(_Source
const& __x) {
return concat(__x); }
317 template<
typename _CharT>
318 __detail::_Path<_CharT*, _CharT*>&
319 operator+=(_CharT __x);
321 template<
typename _Source>
322 __detail::_Path<_Source>&
323 concat(_Source
const& __x)
325 _M_concat(_S_convert(__detail::_S_range_begin(__x),
326 __detail::_S_range_end(__x)));
330 template<
typename _InputIterator>
331 __detail::_Path<_InputIterator, _InputIterator>&
332 concat(_InputIterator __first, _InputIterator __last)
334 _M_concat(_S_convert(__first, __last));
340 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
342 path& make_preferred();
343 path& remove_filename();
344 path& replace_filename(
const path& __replacement);
345 path& replace_extension(
const path& __replacement = path());
347 void swap(path& __rhs) noexcept;
351 const string_type& native() const noexcept {
return _M_pathname; }
352 const value_type* c_str() const noexcept {
return _M_pathname.c_str(); }
353 operator string_type()
const {
return _M_pathname; }
355 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
356 typename _Allocator = std::allocator<_CharT>>
358 string(
const _Allocator& __a = _Allocator())
const;
361 #if _GLIBCXX_USE_WCHAR_T
364 #ifdef _GLIBCXX_USE_CHAR8_T
365 __attribute__((__abi_tag__(
"__u8")))
366 std::u8string u8string() const;
374 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
375 typename _Allocator = std::allocator<_CharT>>
377 generic_string(
const _Allocator& __a = _Allocator())
const;
380 #if _GLIBCXX_USE_WCHAR_T
383 #ifdef _GLIBCXX_USE_CHAR8_T
384 __attribute__((__abi_tag__(
"__u8")))
385 std::u8string generic_u8string() const;
394 int compare(
const path& __p)
const noexcept;
395 int compare(
const string_type& __s)
const noexcept;
396 int compare(
const value_type* __s)
const noexcept;
397 int compare(basic_string_view<value_type> __s)
const noexcept;
401 path root_name()
const;
402 path root_directory()
const;
403 path root_path()
const;
404 path relative_path()
const;
405 path parent_path()
const;
406 path filename()
const;
408 path extension()
const;
412 [[nodiscard]]
bool empty() const noexcept {
return _M_pathname.empty(); }
413 bool has_root_name() const noexcept;
414 bool has_root_directory() const noexcept;
415 bool has_root_path() const noexcept;
416 bool has_relative_path() const noexcept;
417 bool has_parent_path() const noexcept;
418 bool has_filename() const noexcept;
419 bool has_stem() const noexcept;
420 bool has_extension() const noexcept;
421 bool is_absolute() const noexcept;
422 bool is_relative() const noexcept {
return !is_absolute(); }
425 path lexically_normal()
const;
426 path lexically_relative(
const path& base)
const;
427 path lexically_proximate(
const path& base)
const;
431 using const_iterator = iterator;
433 iterator
begin()
const;
434 iterator
end()
const;
437 template<
typename _CharT,
typename _Traits>
441 __os <<
std::quoted(__p.string<_CharT, _Traits>());
446 template<
typename _CharT,
typename _Traits>
459 friend bool operator==(
const path& __lhs,
const path& __rhs) noexcept
460 {
return __lhs.compare(__rhs) == 0; }
462 #if __cpp_lib_three_way_comparison
464 friend strong_ordering
465 operator<=>(
const path& __lhs,
const path& __rhs) noexcept
466 {
return __lhs.compare(__rhs) <=> 0; }
469 friend bool operator!=(
const path& __lhs,
const path& __rhs) noexcept
470 {
return !(__lhs == __rhs); }
473 friend bool operator<(
const path& __lhs,
const path& __rhs) noexcept
474 {
return __lhs.compare(__rhs) < 0; }
477 friend bool operator<=(
const path& __lhs,
const path& __rhs) noexcept
478 {
return !(__rhs < __lhs); }
481 friend bool operator>(
const path& __lhs,
const path& __rhs) noexcept
482 {
return __rhs < __lhs; }
485 friend bool operator>=(
const path& __lhs,
const path& __rhs) noexcept
486 {
return !(__lhs < __rhs); }
490 friend path
operator/(
const path& __lhs,
const path& __rhs)
492 path __result(__lhs);
499 template<
typename _InputIterator,
504 _S_string_from_iter(_InputIterator __source)
507 for (_CharT __ch = *__source; __ch != _CharT(); __ch = *++__source)
514 enum class _Type : unsigned char {
515 _Multi = 0, _Root_name, _Root_dir, _Filename
518 path(basic_string_view<value_type> __str, _Type __type)
521 __glibcxx_assert(__type != _Type::_Multi);
522 _M_cmpts.type(__type);
525 enum class _Split { _Stem, _Extension };
527 void _M_append(basic_string_view<value_type>);
528 void _M_concat(basic_string_view<value_type>);
530 pair<const string_type*, size_t> _M_find_extension() const noexcept;
532 template<typename _CharT>
535 static basic_string_view<value_type>
536 _S_convert(value_type* __src, __detail::__null_terminated)
539 static basic_string_view<value_type>
540 _S_convert(
const value_type* __src, __detail::__null_terminated)
543 static basic_string_view<value_type>
544 _S_convert(value_type* __first, value_type* __last)
545 {
return {__first, __last - __first}; }
547 static basic_string_view<value_type>
548 _S_convert(
const value_type* __first,
const value_type* __last)
549 {
return {__first, __last - __first}; }
551 template<
typename _Iter>
553 _S_convert(_Iter __first, _Iter __last)
556 return _Cvt<typename remove_cv<__value_type>::type>::
557 _S_convert(__first, __last);
560 template<
typename _InputIterator>
562 _S_convert(_InputIterator __src, __detail::__null_terminated)
565 auto __s = _S_string_from_iter(__src);
567 return string_type(_S_convert(__s.data(), __s.data() + __s.size()));
571 _S_convert_loc(
const char* __first,
const char* __last,
574 template<
typename _Iter>
576 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
579 return _S_convert_loc(__str.data(), __str.data()+__str.size(), __loc);
582 template<
typename _InputIterator>
584 _S_convert_loc(_InputIterator __src, __detail::__null_terminated,
587 const std::string __s = _S_string_from_iter(__src);
588 return _S_convert_loc(__s.
data(), __s.
data() + __s.
size(), __loc);
591 template<
typename _CharT,
typename _Traits,
typename _Allocator>
592 static basic_string<_CharT, _Traits, _Allocator>
593 _S_str_convert(basic_string_view<value_type>,
const _Allocator&);
595 void _M_split_cmpts();
597 _Type _M_type() const noexcept {
return _M_cmpts.type(); }
599 string_type _M_pathname;
605 using value_type = _Cmpt;
606 using iterator = value_type*;
607 using const_iterator =
const value_type*;
611 _List(_List&&) =
default;
612 _List& operator=(
const _List&);
613 _List& operator=(_List&&) =
default;
616 _Type type() const noexcept
617 {
return _Type(
reinterpret_cast<uintptr_t
>(_M_impl.get()) & 0x3); }
619 void type(_Type) noexcept;
621 int size() const noexcept;
622 bool empty() const noexcept;
624 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
625 int capacity() const noexcept;
626 void reserve(
int,
bool);
631 iterator
begin() noexcept;
632 iterator
end() noexcept;
633 const_iterator
begin() const noexcept;
634 const_iterator
end() const noexcept;
636 value_type& front() noexcept;
637 value_type& back() noexcept;
638 const value_type& front() const noexcept;
639 const value_type& back() const noexcept;
642 void _M_erase_from(const_iterator __pos);
647 void operator()(_Impl*)
const noexcept;
649 unique_ptr<_Impl, _Impl_deleter> _M_impl;
658 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
660 size_t hash_value(
const path& __p) noexcept;
668 filesystem_error(
const string& __what_arg, error_code __ec);
670 filesystem_error(
const string& __what_arg,
const path& __p1,
673 filesystem_error(
const string& __what_arg,
const path& __p1,
674 const path& __p2, error_code __ec);
676 filesystem_error(
const filesystem_error&) =
default;
677 filesystem_error& operator=(
const filesystem_error&) =
default;
684 const path& path1() const noexcept;
685 const path& path2() const noexcept;
686 const
char* what() const noexcept;
690 std::__shared_ptr<const _Impl> _M_impl;
697 template<typename _InputIterator,
698 typename _Require = __detail::_Path<_InputIterator, _InputIterator>,
700 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
702 u8path(_InputIterator __first, _InputIterator __last)
704 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
705 if constexpr (is_same_v<_CharT, char>)
708 std::codecvt_utf8_utf16<path::value_type> __cvt;
709 path::string_type __tmp;
710 if constexpr (is_pointer_v<_InputIterator>)
712 if (__str_codecvt_in_all(__first, __last, __tmp, __cvt))
713 return path{ __tmp };
718 const char*
const __p = __u8str.
data();
719 if (__str_codecvt_in_all(__p, __p + __u8str.size(), __tmp, __cvt))
720 return path{ __tmp };
722 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
723 "Cannot convert character sequence",
724 std::make_error_code(errc::illegal_byte_sequence)));
727 return path{ __first, __last };
730 return path{ __first, __last };
738 template<
typename _Source,
739 typename _Require = __detail::_Path<_Source>,
740 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
742 u8path(
const _Source& __source)
744 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
745 if constexpr (is_same_v<_CharT, char>)
747 if constexpr (is_convertible_v<const _Source&, std::string_view>)
749 const std::string_view __s = __source;
750 return filesystem::u8path(__s.data(), __s.data() + __s.size());
754 std::string __s = path::_S_string_from_iter(__source);
755 return filesystem::u8path(__s.
data(), __s.
data() + __s.
size());
759 return path{ __source };
761 return path{ __source };
767 struct path::_Cmpt : path
769 _Cmpt(basic_string_view<value_type> __s, _Type __t,
size_t __pos)
770 : path(__s, __t), _M_pos(__pos) { }
772 _Cmpt() : _M_pos(-1) { }
779 struct path::_Cvt<path::value_type>
781 template<
typename _Iter>
783 _S_convert(_Iter __first, _Iter __last)
784 {
return string_type{__first, __last}; }
787 #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
790 struct path::_Cvt<char8_t>
792 template<
typename _Iter>
794 _S_convert(_Iter __first, _Iter __last)
795 {
return string_type(__first, __last); }
799 template<
typename _CharT>
803 _S_convert(
const _CharT* __f,
const _CharT* __l)
805 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
807 if constexpr (is_same_v<_CharT, char>)
809 struct _UCvt :
std::codecvt<wchar_t, char, std::mbstate_t>
811 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
814 #ifdef _GLIBCXX_USE_CHAR8_T
815 else if constexpr (is_same_v<_CharT, char8_t>)
817 const char* __f2 = (
const char*)__f;
818 const char* __l2 = (
const char*)__l;
819 std::codecvt_utf8_utf16<wchar_t> __wcvt;
820 if (__str_codecvt_in_all(__f2, __l2, __wstr, __wcvt))
826 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
829 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
831 const char* __f2 = __str.
data();
832 const char* __l2 = __f2 + __str.
size();
833 std::codecvt_utf8_utf16<wchar_t> __wcvt;
834 if (__str_codecvt_in_all(__f2, __l2, __wstr, __wcvt))
839 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
842 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
845 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
846 "Cannot convert character sequence",
847 std::make_error_code(errc::illegal_byte_sequence)));
851 _S_convert(_CharT* __f, _CharT* __l)
853 return _S_convert(
const_cast<const _CharT*
>(__f),
854 const_cast<const _CharT*
>(__l));
857 template<
typename _Iter>
859 _S_convert(_Iter __first, _Iter __last)
862 return _S_convert(__str.
data(), __str.
data() + __str.
size());
865 template<
typename _Iter,
typename _Cont>
867 _S_convert(__gnu_cxx::__normal_iterator<_Iter, _Cont> __first,
868 __gnu_cxx::__normal_iterator<_Iter, _Cont> __last)
869 {
return _S_convert(__first.base(), __last.base()); }
878 using difference_type = std::ptrdiff_t;
879 using value_type = path;
880 using reference =
const path&;
881 using pointer =
const path*;
884 iterator() : _M_path(nullptr), _M_cur(), _M_at_end() { }
886 iterator(
const iterator&) =
default;
887 iterator& operator=(
const iterator&) =
default;
892 iterator& operator++();
893 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
895 iterator& operator--();
896 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
898 friend bool operator==(
const iterator& __lhs,
const iterator& __rhs)
899 {
return __lhs._M_equals(__rhs); }
901 friend bool operator!=(
const iterator& __lhs,
const iterator& __rhs)
902 {
return !__lhs._M_equals(__rhs); }
907 bool _M_is_multi()
const {
return _M_path->_M_type() == _Type::_Multi; }
909 friend difference_type
910 __path_iter_distance(
const iterator& __first,
const iterator& __last)
912 __glibcxx_assert(__first._M_path !=
nullptr);
913 __glibcxx_assert(__first._M_path == __last._M_path);
914 if (__first._M_is_multi())
916 else if (__first._M_at_end == __last._M_at_end)
919 return __first._M_at_end ? -1 : 1;
923 __path_iter_advance(iterator& __i, difference_type __n)
931 __glibcxx_assert(__i._M_path !=
nullptr);
932 __glibcxx_assert(__i._M_is_multi());
938 iterator(
const path* __path, path::_List::const_iterator __iter)
939 : _M_path(__path), _M_cur(__iter), _M_at_end()
942 iterator(
const path* __path,
bool __at_end)
943 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
946 bool _M_equals(iterator)
const;
949 path::_List::const_iterator _M_cur;
955 path::operator=(path&& __p) noexcept
957 if (&__p ==
this) [[__unlikely__]]
960 _M_pathname =
std::move(__p._M_pathname);
967 path::operator=(string_type&& __source)
968 {
return *
this = path(
std::move(__source)); }
971 path::assign(string_type&& __source)
972 {
return *
this = path(
std::move(__source)); }
975 path::operator+=(
const string_type& __x)
982 path::operator+=(
const value_type* __x)
989 path::operator+=(value_type __x)
991 _M_concat(basic_string_view<value_type>(&__x, 1));
996 path::operator+=(basic_string_view<value_type> __x)
1002 template<
typename _CharT>
1003 inline __detail::_Path<_CharT*, _CharT*>&
1004 path::operator+=(_CharT __x)
1007 return concat(__addr, __addr + 1);
1011 path::make_preferred()
1013 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1014 std::replace(_M_pathname.begin(), _M_pathname.end(), L
'/',
1015 preferred_separator);
1020 inline void path::swap(path& __rhs) noexcept
1022 _M_pathname.swap(__rhs._M_pathname);
1023 _M_cmpts.swap(__rhs._M_cmpts);
1027 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1029 path::_S_str_convert(basic_string_view<value_type> __str,
1030 const _Allocator& __a)
1032 static_assert(!is_same_v<_CharT, value_type>);
1034 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1036 if (__str.size() == 0)
1037 return _WString(__a);
1039 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1042 std::codecvt_utf8_utf16<value_type> __cvt;
1044 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1045 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1046 _String __u8str{_CharAlloc{__a}};
1047 const value_type* __wfirst = __str.data();
1048 const value_type* __wlast = __wfirst + __str.size();
1049 if (__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt)) {
1050 if constexpr (is_same_v<_CharT, char>)
1054 const char* __first = __u8str.data();
1055 const char* __last = __first + __u8str.size();
1057 const value_type* __first = __str.data();
1058 const value_type* __last = __first + __str.size();
1062 #ifdef _GLIBCXX_USE_CHAR8_T
1063 if constexpr (is_same_v<_CharT, char8_t>)
1064 return _WString(__first, __last, __a);
1069 _WString __wstr(__a);
1070 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t> { } __cvt;
1071 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1075 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1078 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1079 "Cannot convert character sequence",
1080 std::make_error_code(errc::illegal_byte_sequence)));
1084 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1085 inline basic_string<_CharT, _Traits, _Allocator>
1088 if constexpr (is_same_v<_CharT, value_type>)
1089 return { _M_pathname.
c_str(), _M_pathname.length(), __a };
1091 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1097 #if _GLIBCXX_USE_WCHAR_T
1102 #ifdef _GLIBCXX_USE_CHAR8_T
1103 inline std::u8string
1104 path::u8string()
const {
return string<char8_t>(); }
1107 path::u8string()
const
1109 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1112 std::codecvt_utf8_utf16<value_type> __cvt;
1113 const value_type* __first = _M_pathname.
data();
1114 const value_type* __last = __first + _M_pathname.size();
1115 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1117 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1118 "Cannot convert character sequence",
1119 std::make_error_code(errc::illegal_byte_sequence)));
1132 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1134 path::generic_string(
const _Allocator& __a)
const
1136 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1137 const value_type __slash = L
'/';
1139 const value_type __slash =
'/';
1141 using _Alloc2 =
typename allocator_traits<_Allocator>::template
1142 rebind_alloc<value_type>;
1143 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1145 if (_M_type() == _Type::_Root_dir)
1146 __str.
assign(1, __slash);
1149 __str.
reserve(_M_pathname.size());
1150 bool __add_slash =
false;
1151 for (
auto& __elem : *
this)
1153 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1154 if (__elem._M_type() == _Type::_Root_dir)
1162 __str += basic_string_view<value_type>(__elem._M_pathname);
1163 __add_slash = __elem._M_type() == _Type::_Filename;
1167 if constexpr (is_same_v<_CharT, value_type>)
1170 return _S_str_convert<_CharT, _Traits>(__str, __a);
1174 path::generic_string()
const
1175 {
return generic_string<char>(); }
1177 #if _GLIBCXX_USE_WCHAR_T
1179 path::generic_wstring()
const
1180 {
return generic_string<wchar_t>(); }
1183 #ifdef _GLIBCXX_USE_CHAR8_T
1184 inline std::u8string
1185 path::generic_u8string()
const
1186 {
return generic_string<char8_t>(); }
1189 path::generic_u8string()
const
1190 {
return generic_string(); }
1194 path::generic_u16string()
const
1195 {
return generic_string<char16_t>(); }
1198 path::generic_u32string()
const
1199 {
return generic_string<char32_t>(); }
1202 path::compare(
const string_type& __s)
const noexcept
1203 {
return compare(basic_string_view<value_type>(__s)); }
1206 path::compare(
const value_type* __s)
const noexcept
1207 {
return compare(basic_string_view<value_type>(__s)); }
1210 path::filename()
const
1214 else if (_M_type() == _Type::_Filename)
1216 else if (_M_type() == _Type::_Multi)
1218 if (_M_pathname.back() == preferred_separator)
1220 auto& __last = *--
end();
1221 if (__last._M_type() == _Type::_Filename)
1230 auto ext = _M_find_extension();
1231 if (ext.first && ext.second != 0)
1232 return path{ext.first->substr(0, ext.second)};
1237 path::extension()
const
1239 auto ext = _M_find_extension();
1240 if (ext.first && ext.second != string_type::npos)
1241 return path{ext.first->substr(ext.second)};
1246 path::has_stem() const noexcept
1248 auto ext = _M_find_extension();
1249 return ext.first && ext.second != 0;
1253 path::has_extension() const noexcept
1255 auto ext = _M_find_extension();
1256 return ext.first && ext.second != string_type::npos;
1260 path::is_absolute() const noexcept
1262 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1263 return has_root_name() && has_root_directory();
1265 return has_root_directory();
1269 inline path::iterator
1272 if (_M_type() == _Type::_Multi)
1273 return iterator(
this, _M_cmpts.begin());
1274 return iterator(
this, empty());
1277 inline path::iterator
1280 if (_M_type() == _Type::_Multi)
1281 return iterator(
this, _M_cmpts.end());
1282 return iterator(
this,
true);
1285 inline path::iterator&
1286 path::iterator::operator++()
1288 __glibcxx_assert(_M_path !=
nullptr);
1289 if (_M_path->_M_type() == _Type::_Multi)
1291 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1296 __glibcxx_assert(!_M_at_end);
1302 inline path::iterator&
1303 path::iterator::operator--()
1305 __glibcxx_assert(_M_path !=
nullptr);
1306 if (_M_path->_M_type() == _Type::_Multi)
1308 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1313 __glibcxx_assert(_M_at_end);
1319 inline path::iterator::reference
1322 __glibcxx_assert(_M_path !=
nullptr);
1323 if (_M_path->_M_type() == _Type::_Multi)
1325 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1332 path::iterator::_M_equals(iterator __rhs)
const
1334 if (_M_path != __rhs._M_path)
1336 if (_M_path ==
nullptr)
1338 if (_M_path->_M_type() == path::_Type::_Multi)
1339 return _M_cur == __rhs._M_cur;
1340 return _M_at_end == __rhs._M_at_end;
1344 _GLIBCXX_END_NAMESPACE_CXX11
1348 distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1349 {
return __path_iter_distance(__first, __last); }
1351 template<
typename _Distance>
1353 advance(filesystem::path::iterator& __i, _Distance __n)
1354 { __path_iter_advance(__i,
static_cast<ptrdiff_t
>(__n)); }
1356 extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1358 _GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
typename remove_cv< _Tp >::type remove_cv_t
Alias template for remove_cv.
typename remove_const< _Tp >::type remove_const_t
Alias template for remove_const.
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.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_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.
basic_string< char32_t > u32string
A string of char32_t.
basic_string< char16_t > u16string
A string of char16_t.
basic_string< wchar_t > wstring
A string of wchar_t.
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
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.
An exception type that includes an error_code value.
Define a member typedef type only if a boolean constant is true.
void push_back(_CharT __c)
Append a single character.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
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.
Primary class template codecvt.
Traits class for iterators.
Container class for localization functionality.
Bidirectional iterators support a superset of forward iterator operations.