30 #ifndef _GLIBCXX_EXPERIMENTAL_FS_PATH_H
31 #define _GLIBCXX_EXPERIMENTAL_FS_PATH_H 1
33 #if __cplusplus < 201103L
47 #if __cplusplus == 201402L
51 #if defined(_WIN32) && !defined(__CYGWIN__)
52 # define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1
56 namespace std _GLIBCXX_VISIBILITY(default)
58 _GLIBCXX_BEGIN_NAMESPACE_VERSION
60 namespace experimental
66 _GLIBCXX_BEGIN_NAMESPACE_CXX11
68 #if __cplusplus == 201402L
70 #elif __cplusplus > 201402L
81 template<
typename _CharT,
82 typename _Ch =
typename remove_const<_CharT>::type>
83 using __is_encoded_char
84 = __or_<is_same<_Ch, char>,
85 is_same<_Ch, wchar_t>,
86 #ifdef _GLIBCXX_USE_CHAR8_T
87 is_same<_Ch, char8_t>,
89 is_same<_Ch, char16_t>,
90 is_same<_Ch, char32_t>>;
92 template<
typename _Iter,
94 using __is_path_iter_src
95 = __and_<__is_encoded_char<typename _Iter_traits::value_type>,
97 typename _Iter_traits::iterator_category>>;
99 template<
typename _Iter>
100 static __is_path_iter_src<_Iter>
101 __is_path_src(_Iter,
int);
103 template<
typename _CharT,
typename _Traits,
typename _Alloc>
104 static __is_encoded_char<_CharT>
105 __is_path_src(
const basic_string<_CharT, _Traits, _Alloc>&,
int);
107 #if __cplusplus >= 201402L
108 template<
typename _CharT,
typename _Traits>
109 static __is_encoded_char<_CharT>
110 __is_path_src(
const basic_string_view<_CharT, _Traits>&,
int);
113 template<
typename _Unknown>
115 __is_path_src(
const _Unknown&, ...);
117 template<
typename _Tp1,
typename _Tp2>
118 struct __constructible_from;
120 template<
typename _Iter>
121 struct __constructible_from<_Iter, _Iter>
122 : __is_path_iter_src<_Iter>
125 template<
typename _Source>
126 struct __constructible_from<_Source, void>
127 : decltype(__is_path_src(std::declval<const _Source&>(), 0))
130 template<
typename _Tp1,
typename _Tp2 = void,
131 typename _Tp1_nocv =
typename remove_cv<_Tp1>::type,
132 typename _Tp1_noptr =
typename remove_pointer<_Tp1>::type>
133 using _Path =
typename
135 __not_<is_void<_Tp1_noptr>>,
136 __constructible_from<_Tp1, _Tp2>>::value,
139 template<
typename _Source>
141 _S_range_begin(_Source __begin) {
return __begin; }
143 struct __null_terminated { };
145 template<
typename _Source>
146 inline __null_terminated
147 _S_range_end(_Source) {
return {}; }
149 template<
typename _CharT,
typename _Traits,
typename _Alloc>
151 _S_range_begin(
const basic_string<_CharT, _Traits, _Alloc>& __str)
152 {
return __str.data(); }
154 template<
typename _CharT,
typename _Traits,
typename _Alloc>
156 _S_range_end(
const basic_string<_CharT, _Traits, _Alloc>& __str)
157 {
return __str.data() + __str.size(); }
159 #if __cplusplus >= 201402L
160 template<
typename _CharT,
typename _Traits>
162 _S_range_begin(
const basic_string_view<_CharT, _Traits>& __str)
163 {
return __str.data(); }
165 template<
typename _CharT,
typename _Traits>
167 _S_range_end(
const basic_string_view<_CharT, _Traits>& __str)
168 {
return __str.data() + __str.size(); }
171 template<
typename _Tp,
172 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
174 typename _UnqualVal =
typename std::remove_const<_Val>::type>
179 template<
typename _Tp,
180 typename _Iter = decltype(_S_range_begin(std::declval<_Tp>())),
182 typename _UnqualVal =
typename std::remove_const<_Val>::type>
186 #ifdef _GLIBCXX_USE_CHAR8_T
189 >::value, _UnqualVal>::type;
198 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
199 typedef wchar_t value_type;
200 static constexpr value_type preferred_separator = L
'\\';
202 typedef char value_type;
203 static constexpr value_type preferred_separator =
'/';
214 : _M_pathname(
std::move(__p._M_pathname)), _M_type(__p._M_type)
216 if (_M_type == _Type::_Multi)
221 path(string_type&& __source)
223 { _M_split_cmpts(); }
225 template<
typename _Source,
226 typename _Require = __detail::_Path<_Source>>
227 path(_Source
const& __source)
228 : _M_pathname(_S_convert(__detail::_S_range_begin(__source),
229 __detail::_S_range_end(__source)))
230 { _M_split_cmpts(); }
232 template<
typename _InputIterator,
233 typename _Require = __detail::_Path<_InputIterator, _InputIterator>>
234 path(_InputIterator __first, _InputIterator __last)
235 : _M_pathname(_S_convert(__first, __last))
236 { _M_split_cmpts(); }
238 template<
typename _Source,
239 typename _Require = __detail::_Path<_Source>,
240 typename _Require2 = __detail::__value_type_is_char<_Source>>
241 path(_Source
const& __source,
const locale& __loc)
242 : _M_pathname(_S_convert_loc(__detail::_S_range_begin(__source),
243 __detail::_S_range_end(__source), __loc))
244 { _M_split_cmpts(); }
246 template<
typename _InputIterator,
247 typename _Require = __detail::_Path<_InputIterator, _InputIterator>,
248 typename _Require2 = __detail::__value_type_is_char<_InputIterator>>
249 path(_InputIterator __first, _InputIterator __last,
const locale& __loc)
250 : _M_pathname(_S_convert_loc(__first, __last, __loc))
251 { _M_split_cmpts(); }
257 path& operator=(
const path& __p) =
default;
258 path& operator=(
path&& __p) noexcept;
259 path& operator=(string_type&& __source);
260 path& assign(string_type&& __source);
262 template<
typename _Source>
263 __detail::_Path<_Source>&
265 {
return *
this =
path(__source); }
267 template<
typename _Source>
268 __detail::_Path<_Source>&
269 assign(_Source
const& __source)
270 {
return *
this =
path(__source); }
272 template<
typename _InputIterator>
273 __detail::_Path<_InputIterator, _InputIterator>&
274 assign(_InputIterator __first, _InputIterator __last)
275 {
return *
this =
path(__first, __last); }
279 path& operator/=(
const path& __p) {
return _M_append(__p._M_pathname); }
281 template<
typename _Source>
282 __detail::_Path<_Source>&
283 operator/=(_Source
const& __source)
284 {
return append(__source); }
286 template<
typename _Source>
287 __detail::_Path<_Source>&
288 append(_Source
const& __source)
290 return _M_append(_S_convert(__detail::_S_range_begin(__source),
291 __detail::_S_range_end(__source)));
294 template<
typename _InputIterator>
295 __detail::_Path<_InputIterator, _InputIterator>&
296 append(_InputIterator __first, _InputIterator __last)
297 {
return _M_append(_S_convert(__first, __last)); }
302 path& operator+=(
const string_type& __x);
303 path& operator+=(
const value_type* __x);
304 path& operator+=(value_type __x);
305 #if __cplusplus >= 201402L
309 template<
typename _Source>
310 __detail::_Path<_Source>&
311 operator+=(_Source
const& __x) {
return concat(__x); }
313 template<
typename _CharT>
314 __detail::_Path<_CharT*, _CharT*>&
315 operator+=(_CharT __x);
317 template<
typename _Source>
318 __detail::_Path<_Source>&
319 concat(_Source
const& __x)
321 return *
this += _S_convert(__detail::_S_range_begin(__x),
322 __detail::_S_range_end(__x));
325 template<
typename _InputIterator>
326 __detail::_Path<_InputIterator, _InputIterator>&
327 concat(_InputIterator __first, _InputIterator __last)
328 {
return *
this += _S_convert(__first, __last); }
332 void clear() noexcept { _M_pathname.
clear(); _M_split_cmpts(); }
334 path& make_preferred();
335 path& remove_filename();
336 path& replace_filename(
const path& __replacement);
337 path& replace_extension(
const path& __replacement =
path());
339 void swap(
path& __rhs) noexcept;
343 const string_type& native()
const noexcept {
return _M_pathname; }
344 const value_type* c_str()
const noexcept {
return _M_pathname.
c_str(); }
345 operator string_type()
const {
return _M_pathname; }
347 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
348 typename _Allocator = std::allocator<_CharT>>
350 string(
const _Allocator& __a = _Allocator())
const;
353 #if _GLIBCXX_USE_WCHAR_T
356 #ifdef _GLIBCXX_USE_CHAR8_T
357 __attribute__((__abi_tag__(
"__u8")))
358 std::u8string u8string()
const;
366 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
367 typename _Allocator = std::allocator<_CharT>>
369 generic_string(
const _Allocator& __a = _Allocator())
const;
372 #if _GLIBCXX_USE_WCHAR_T
375 #ifdef _GLIBCXX_USE_CHAR8_T
376 __attribute__((__abi_tag__(
"__u8")))
377 std::u8string generic_u8string()
const;
386 int compare(
const path& __p)
const noexcept;
387 int compare(
const string_type& __s)
const;
388 int compare(
const value_type* __s)
const;
389 #if __cplusplus >= 201402L
395 path root_name()
const;
396 path root_directory()
const;
397 path root_path()
const;
398 path relative_path()
const;
399 path parent_path()
const;
400 path filename()
const;
402 path extension()
const;
406 _GLIBCXX_NODISCARD
bool empty()
const noexcept {
return _M_pathname.
empty(); }
407 bool has_root_name()
const;
408 bool has_root_directory()
const;
409 bool has_root_path()
const;
410 bool has_relative_path()
const;
411 bool has_parent_path()
const;
412 bool has_filename()
const;
413 bool has_stem()
const;
414 bool has_extension()
const;
415 bool is_absolute()
const;
416 bool is_relative()
const {
return !is_absolute(); }
427 template<
typename _InputIterator,
430 =
typename std::remove_cv<typename _Traits::value_type>::type>
432 _S_string_from_iter(_InputIterator __source)
435 for (_CharT __ch = *__source; __ch != _CharT(); __ch = *++__source)
442 enum class _Type : unsigned char {
443 _Multi, _Root_name, _Root_dir, _Filename
446 path(string_type __str, _Type __type) : _M_pathname(__str), _M_type(__type)
448 __glibcxx_assert(!empty());
449 __glibcxx_assert(_M_type != _Type::_Multi);
452 enum class _Split { _Stem, _Extension };
454 path& _M_append(
const string_type& __str)
456 if (!_M_pathname.
empty() && !_S_is_dir_sep(_M_pathname.
back())
457 && !__str.empty() && !_S_is_dir_sep(__str.front()))
458 _M_pathname += preferred_separator;
459 _M_pathname += __str;
466 template<
typename _CharT>
470 _S_convert(value_type* __src, __detail::__null_terminated)
471 {
return string_type(__src); }
474 _S_convert(
const value_type* __src, __detail::__null_terminated)
475 {
return string_type(__src); }
477 template<
typename _Iter>
479 _S_convert(_Iter __first, _Iter __last)
482 return _Cvt<typename remove_cv<__value_type>::type>::
483 _S_convert(__first, __last);
486 template<
typename _InputIterator>
488 _S_convert(_InputIterator __src, __detail::__null_terminated)
490 auto __s = _S_string_from_iter(__src);
491 return _S_convert(__s.c_str(), __s.c_str() + __s.size());
495 _S_convert_loc(
const char* __first,
const char* __last,
499 _S_convert_loc(
char* __first,
char* __last,
const std::locale& __loc)
501 return _S_convert_loc(
const_cast<const char*
>(__first),
502 const_cast<const char*
>(__last), __loc);
505 template<
typename _Iter>
507 _S_convert_loc(_Iter __first, _Iter __last,
const std::locale& __loc)
510 return _S_convert_loc(__str.
data(), __str.
data()+__str.
size(), __loc);
513 template<
typename _InputIterator>
515 _S_convert_loc(_InputIterator __src, __detail::__null_terminated,
518 const std::string __s = _S_string_from_iter(__src);
519 return _S_convert_loc(__s.
data(), __s.
data() + __s.
size(), __loc);
522 static bool _S_is_dir_sep(value_type __ch)
524 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
525 return __ch == L
'/' || __ch == preferred_separator;
531 void _M_split_cmpts();
533 void _M_add_root_name(
size_t __n);
534 void _M_add_root_dir(
size_t __pos);
535 void _M_add_filename(
size_t __pos,
size_t __n);
537 string_type _M_pathname;
540 using _List = _GLIBCXX_STD_C::vector<_Cmpt>;
542 _Type _M_type = _Type::_Multi;
548 inline void swap(
path& __lhs,
path& __rhs) noexcept { __lhs.swap(__rhs); }
551 size_t hash_value(
const path& __p) noexcept;
554 inline bool operator<(
const path& __lhs,
const path& __rhs) noexcept;
557 inline bool operator<=(
const path& __lhs,
const path& __rhs) noexcept
558 {
return !(__rhs < __lhs); }
561 inline bool operator>(
const path& __lhs,
const path& __rhs) noexcept
562 {
return __rhs < __lhs; }
565 inline bool operator>=(
const path& __lhs,
const path& __rhs) noexcept
566 {
return !(__lhs < __rhs); }
569 inline bool operator==(
const path& __lhs,
const path& __rhs) noexcept;
572 inline bool operator!=(
const path& __lhs,
const path& __rhs) noexcept
573 {
return !(__lhs == __rhs); }
576 inline path
operator/(
const path& __lhs,
const path& __rhs)
578 path __result(__lhs);
584 template<
typename _CharT,
typename _Traits>
585 basic_ostream<_CharT, _Traits>&
586 operator<<(basic_ostream<_CharT, _Traits>& __os,
const path& __p)
588 auto __tmp = __p.string<_CharT, _Traits>();
589 using __quoted_string
591 __os << __quoted_string{__tmp, _CharT(
'"'), _CharT(
'\\')};
596 template<
typename _CharT,
typename _Traits>
597 basic_istream<_CharT, _Traits>&
598 operator>>(basic_istream<_CharT, _Traits>& __is, path& __p)
600 basic_string<_CharT, _Traits> __tmp;
601 using __quoted_string
603 if (__is >> __quoted_string{ __tmp, _CharT(
'"'), _CharT(
'\\') })
609 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
610 template<
typename _InputIterator>
612 __u8path(_InputIterator __first, _InputIterator __last,
char)
615 std::codecvt_utf8_utf16<path::value_type> __cvt;
616 path::string_type __tmp;
618 const char*
const __ptr = __u8str.
data();
619 if (__str_codecvt_in_all(__ptr, __ptr + __u8str.size(), __tmp, __cvt))
620 return path{ __tmp };
621 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
622 "Cannot convert character sequence",
623 std::make_error_code(errc::illegal_byte_sequence)));
626 #ifdef _GLIBCXX_USE_CHAR8_T
627 template<
typename _InputIterator>
629 __u8path(_InputIterator __first, _InputIterator __last, char8_t)
631 return path{ __first, __last };
636 template<
typename _InputIterator,
637 typename _Require = __detail::_Path<_InputIterator, _InputIterator>,
639 __detail::__value_type_is_char_or_char8_t<_InputIterator>>
641 u8path(_InputIterator __first, _InputIterator __last)
643 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
644 return __u8path(__first, __last, _CharT{});
646 return path{ __first, __last };
651 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
653 __u8path(
const string& __s,
char)
655 return filesystem::u8path(__s.data(), __s.data() + __s.size());
658 template<
typename _Source>
659 inline __enable_if_t<is_convertible<const _Source&, string>::value, path>
660 __u8path(
const _Source& __source,
char)
663 return filesystem::u8path(__s.
data(), __s.
data() + __s.
size());
666 template<
typename _Source>
667 inline __enable_if_t<!is_convertible<const _Source&, string>::value, path>
668 __u8path(
const _Source& __source,
char)
670 std::string __s = path::_S_string_from_iter(__source);
671 return filesystem::u8path(__s.
data(), __s.
data() + __s.
size());
674 #ifdef _GLIBCXX_USE_CHAR8_T
675 template<
typename _Source>
677 __u8path(
const _Source& __source, char8_t)
679 return path{ __source };
684 template<
typename _Source,
685 typename _Require = __detail::_Path<_Source>,
687 __detail::__value_type_is_char_or_char8_t<_Source>>
689 u8path(
const _Source& __source)
691 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
692 return __u8path(__source, _CharT{});
694 return path{ __source };
713 :
system_error(__ec, __what_arg), _M_path1(__p1), _M_path2(__p2)
718 const path& path1()
const noexcept {
return _M_path1; }
719 const path& path2()
const noexcept {
return _M_path2; }
720 const char*
what() const noexcept {
return _M_what.
c_str(); }
731 struct path::_Cmpt :
path
733 _Cmpt(string_type __s, _Type __t,
size_t __pos)
736 _Cmpt() : _M_pos(-1) { }
743 struct path::_Cvt<path::value_type>
745 template<
typename _Iter>
747 _S_convert(_Iter __first, _Iter __last)
748 {
return string_type{__first, __last}; }
751 template<
typename _CharT>
754 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
755 #ifdef _GLIBCXX_USE_CHAR8_T
757 _S_wconvert(
const char8_t* __f,
const char8_t* __l,
const char8_t*)
759 const char* __f2 = (
const char*)__f;
760 const char* __l2 = (
const char*)__l;
762 std::codecvt_utf8_utf16<wchar_t> __wcvt;
763 if (__str_codecvt_in_all(__f2, __l2, __wstr, __wcvt))
769 _S_wconvert(
const char* __f,
const char* __l,
const char*)
772 const auto& __cvt = std::use_facet<_Cvt>(
std::locale{});
774 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
776 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
777 "Cannot convert character sequence",
778 std::make_error_code(errc::illegal_byte_sequence)));
782 _S_wconvert(
const _CharT* __f,
const _CharT* __l,
const void*)
784 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
787 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
789 const char* __f2 = __str.
data();
790 const char* __l2 = __f2 + __str.
size();
791 std::codecvt_utf8_utf16<wchar_t> __wcvt;
793 if (__str_codecvt_in_all(__f2, __l2, __wstr, __wcvt))
796 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
797 "Cannot convert character sequence",
798 std::make_error_code(errc::illegal_byte_sequence)));
802 _S_convert(
const _CharT* __f,
const _CharT* __l)
804 return _S_wconvert(__f, __l, (
const _CharT*)
nullptr);
808 _S_convert(
const _CharT* __f,
const _CharT* __l)
810 #ifdef _GLIBCXX_USE_CHAR8_T
811 if constexpr (is_same<_CharT, char8_t>::value)
812 return string_type(__f, __l);
816 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
819 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
821 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
822 "Cannot convert character sequence",
823 std::make_error_code(errc::illegal_byte_sequence)));
829 _S_convert(_CharT* __f, _CharT* __l)
831 return _S_convert(
const_cast<const _CharT*
>(__f),
832 const_cast<const _CharT*
>(__l));
835 template<
typename _Iter>
837 _S_convert(_Iter __first, _Iter __last)
840 return _S_convert(__str.
data(), __str.
data() + __str.
size());
843 template<
typename _Iter,
typename _Cont>
845 _S_convert(__gnu_cxx::__normal_iterator<_Iter, _Cont> __first,
846 __gnu_cxx::__normal_iterator<_Iter, _Cont> __last)
847 {
return _S_convert(__first.base(), __last.base()); }
855 using difference_type = std::ptrdiff_t;
861 iterator() : _M_path(
nullptr), _M_cur(), _M_at_end() { }
870 iterator operator++(
int) {
auto __tmp = *
this; ++*
this;
return __tmp; }
873 iterator operator--(
int) {
auto __tmp = *
this; --*
this;
return __tmp; }
876 {
return __lhs._M_equals(__rhs); }
879 {
return !__lhs._M_equals(__rhs); }
884 iterator(
const path* __path, path::_List::const_iterator __iter)
885 : _M_path(__path), _M_cur(__iter), _M_at_end()
889 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
895 path::_List::const_iterator _M_cur;
903 _M_pathname =
std::move(__p._M_pathname);
905 _M_type = __p._M_type;
915 path::assign(string_type&& __source)
919 path::operator+=(
const path& __p)
921 return operator+=(__p.native());
925 path::operator+=(
const string_type& __x)
933 path::operator+=(
const value_type* __x)
941 path::operator+=(value_type __x)
948 #if __cplusplus >= 201402L
950 path::operator+=(basic_string_view<value_type> __x)
952 _M_pathname.
append(__x.data(), __x.size());
958 template<
typename _CharT>
959 inline __detail::_Path<_CharT*, _CharT*>&
960 path::operator+=(_CharT __x)
963 return concat(__addr, __addr + 1);
967 path::make_preferred()
969 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
970 std::replace(_M_pathname.
begin(), _M_pathname.
end(), L
'/',
971 preferred_separator);
978 _M_pathname.swap(__rhs._M_pathname);
979 _M_cmpts.swap(__rhs._M_cmpts);
983 template<
typename _CharT,
typename _Traits,
typename _Allocator>
987 if (is_same<_CharT, value_type>::value)
988 return { _M_pathname.
begin(), _M_pathname.
end(), __a };
990 using _WString = basic_string<_CharT, _Traits, _Allocator>;
992 const value_type* __first = _M_pathname.
data();
993 const value_type* __last = __first + _M_pathname.
size();
995 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
996 using _CharAlloc = __alloc_rebind<_Allocator, char>;
997 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1001 codecvt_utf8_utf16<value_type> __cvt;
1002 _String __u8str{_CharAlloc{__a}};
1003 if (__str_codecvt_out_all(__first, __last, __u8str, __cvt))
1008 operator()(
const _String& __from, _String&,
true_type)
1012 operator()(
const _String& __from, _WString& __to,
false_type)
1014 #ifdef _GLIBCXX_USE_CHAR8_T
1015 if constexpr (is_same<_CharT, char8_t>::value)
1017 __to.assign(__from.begin(), __from.end());
1024 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t>
1026 const char* __f = __from.data();
1027 const char* __l = __f + __from.size();
1028 if (__str_codecvt_in_all(__f, __l, __to, __cvt))
1034 _WString __wstr(__a);
1035 if (
auto* __p = __dispatch(__u8str, __wstr, is_same<_CharT, char>{}))
1039 #ifdef _GLIBCXX_USE_CHAR8_T
1040 if constexpr (is_same<_CharT, char8_t>::value)
1041 return _WString(__first, __last, __a);
1045 struct _UCvt :
std::codecvt<_CharT, char, std::mbstate_t> { } __cvt;
1046 _WString __wstr(__a);
1047 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1051 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1052 "Cannot convert character sequence",
1053 std::make_error_code(errc::illegal_byte_sequence)));
1057 path::string()
const {
return string<char>(); }
1059 #if _GLIBCXX_USE_WCHAR_T
1061 path::wstring()
const {
return string<wchar_t>(); }
1064 #ifdef _GLIBCXX_USE_CHAR8_T
1065 inline std::u8string
1066 path::u8string()
const {
return string<char8_t>(); }
1069 path::u8string()
const
1071 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1074 std::codecvt_utf8_utf16<value_type> __cvt;
1075 const value_type* __first = _M_pathname.
data();
1076 const value_type* __last = __first + _M_pathname.
size();
1077 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1079 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
1080 "Cannot convert character sequence",
1081 std::make_error_code(errc::illegal_byte_sequence)));
1089 path::u16string()
const {
return string<char16_t>(); }
1092 path::u32string()
const {
return string<char32_t>(); }
1094 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1096 path::generic_string(
const _Allocator& __a)
const
1098 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1099 const _CharT __slash = is_same<_CharT, wchar_t>::value
1103 const _CharT __slash = _CharT(
'/');
1105 basic_string<_CharT, _Traits, _Allocator> __str(__a);
1107 bool __add_slash =
false;
1108 for (
auto& __elem : *
this)
1110 if (__elem._M_type == _Type::_Root_dir)
1117 __str += __elem.string<_CharT, _Traits, _Allocator>(__a);
1118 __add_slash = __elem._M_type == _Type::_Filename;
1124 path::generic_string()
const {
return generic_string<char>(); }
1126 #if _GLIBCXX_USE_WCHAR_T
1128 path::generic_wstring()
const {
return generic_string<wchar_t>(); }
1131 #ifdef _GLIBCXX_USE_CHAR8_T
1132 inline std::u8string
1133 path::generic_u8string()
const {
return generic_string<char8_t>(); }
1136 path::generic_u8string()
const {
return generic_string<char>(); }
1140 path::generic_u16string()
const {
return generic_string<char16_t>(); }
1143 path::generic_u32string()
const {
return generic_string<char32_t>(); }
1146 path::compare(
const string_type& __s)
const {
return compare(path(__s)); }
1149 path::compare(
const value_type* __s)
const {
return compare(path(__s)); }
1151 #if __cplusplus >= 201402L
1153 path::compare(basic_string_view<value_type> __s)
const
1154 {
return compare(path(__s)); }
1158 path::filename()
const {
return empty() ? path() : *--end(); }
1163 auto ext = _M_find_extension();
1164 if (ext.first && ext.second != 0)
1165 return path{ext.first->substr(0, ext.second)};
1170 path::extension()
const
1172 auto ext = _M_find_extension();
1174 return path{ext.first->substr(ext.second)};
1179 path::has_stem()
const
1181 auto ext = _M_find_extension();
1182 return ext.first && ext.second != 0;
1186 path::has_extension()
const
1188 auto ext = _M_find_extension();
1193 path::is_absolute()
const
1195 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1196 return has_root_name() && has_root_directory();
1198 return has_root_directory();
1202 inline path::iterator
1205 if (_M_type == _Type::_Multi)
1206 return iterator(
this, _M_cmpts.
begin());
1207 return iterator(
this,
false);
1210 inline path::iterator
1213 if (_M_type == _Type::_Multi)
1214 return iterator(
this, _M_cmpts.
end());
1215 return iterator(
this,
true);
1218 inline path::iterator&
1219 path::iterator::operator++()
1221 __glibcxx_assert(_M_path !=
nullptr);
1222 if (_M_path->_M_type == _Type::_Multi)
1224 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.
end());
1229 __glibcxx_assert(!_M_at_end);
1235 inline path::iterator&
1236 path::iterator::operator--()
1238 __glibcxx_assert(_M_path !=
nullptr);
1239 if (_M_path->_M_type == _Type::_Multi)
1241 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1246 __glibcxx_assert(_M_at_end);
1252 inline path::iterator::reference
1253 path::iterator::operator*()
const
1255 __glibcxx_assert(_M_path !=
nullptr);
1256 if (_M_path->_M_type == _Type::_Multi)
1258 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1265 path::iterator::_M_equals(iterator __rhs)
const
1267 if (_M_path != __rhs._M_path)
1269 if (_M_path ==
nullptr)
1271 if (_M_path->_M_type == path::_Type::_Multi)
1272 return _M_cur == __rhs._M_cur;
1273 return _M_at_end == __rhs._M_at_end;
1280 inline bool operator<(
const path& __lhs,
const path& __rhs) noexcept
1281 {
return __lhs.compare(__rhs) < 0; }
1283 inline bool operator==(
const path& __lhs,
const path& __rhs) noexcept
1284 {
return __lhs.compare(__rhs) == 0; }
1287 _GLIBCXX_END_NAMESPACE_CXX11
1292 _GLIBCXX_END_NAMESPACE_VERSION
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
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 * begin(valarray< _Tp > &__va)
Return an iterator pointing to the first element of the valarray.
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
basic_string< char > string
A string of char.
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.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
A non-owning reference to a string.
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)
Attempt to preallocate enough memory for specified number of characters.
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.
basic_string & append(const basic_string &__str)
Append a string to this string.
bool empty() const noexcept
static const size_type npos
Value returned by various member functions when they fail.
Primary class template codecvt.
Class codecvt<wchar_t, char, mbstate_t> specialization.
Traits class for iterators.
Container class for localization functionality.
Struct for delimited strings.
Bidirectional iterators support a superset of forward iterator operations.
Struct holding two objects of arbitrary type.
iterator begin() noexcept
Exception type thrown by the Filesystem TS library.
const char * what() const noexcept
An iterator for the components of a path.
A non-owning reference to a string.