libstdc++
bits/fs_path.h
Go to the documentation of this file.
1// Class filesystem::path -*- C++ -*-
2
3// Copyright (C) 2014-2023 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file include/bits/fs_path.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{filesystem}
28 */
29
30#ifndef _GLIBCXX_FS_PATH_H
31#define _GLIBCXX_FS_PATH_H 1
32
33#if __cplusplus >= 201703L
34
35#include <type_traits>
36#include <locale>
37#include <iosfwd>
38#include <iomanip>
39#include <codecvt>
40#include <string_view>
41#include <system_error>
42#include <bits/stl_algobase.h>
43#include <bits/stl_pair.h>
44#include <bits/locale_conv.h>
45#include <ext/concurrence.h>
46#include <bits/shared_ptr.h>
47#include <bits/unique_ptr.h>
48
49#if __cplusplus > 201703L
50# include <compare>
51#endif
52
53#if defined(_WIN32) && !defined(__CYGWIN__)
54# define _GLIBCXX_FILESYSTEM_IS_WINDOWS 1
55#endif
56
57namespace std _GLIBCXX_VISIBILITY(default)
58{
59_GLIBCXX_BEGIN_NAMESPACE_VERSION
60
61namespace filesystem
62{
63_GLIBCXX_BEGIN_NAMESPACE_CXX11
64
65 class path;
66
67 /// @cond undocumented
68namespace __detail
69{
70 /// @addtogroup filesystem
71 /// @{
72 template<typename _CharT>
73 inline constexpr bool __is_encoded_char = false;
74 template<>
75 inline constexpr bool __is_encoded_char<char> = true;
76#ifdef _GLIBCXX_USE_CHAR8_T
77 template<>
78 inline constexpr bool __is_encoded_char<char8_t> = true;
79#endif
80#if _GLIBCXX_USE_WCHAR_T
81 template<>
82 inline constexpr bool __is_encoded_char<wchar_t> = true;
83#endif
84 template<>
85 inline constexpr bool __is_encoded_char<char16_t> = true;
86 template<>
87 inline constexpr bool __is_encoded_char<char32_t> = true;
88
89#if __cpp_concepts >= 201907L
90 template<typename _Iter>
91 using __safe_iterator_traits = std::iterator_traits<_Iter>;
92#else
93 template<typename _Iter>
94 struct __safe_iterator_traits : std::iterator_traits<_Iter>
95 { };
96
97 // Protect against ill-formed iterator_traits specializations in C++17
98 template<> struct __safe_iterator_traits<void*> { };
99 template<> struct __safe_iterator_traits<const void*> { };
100 template<> struct __safe_iterator_traits<volatile void*> { };
101 template<> struct __safe_iterator_traits<const volatile void*> { };
102#endif
103
104 template<typename _Iter_traits, typename = void>
105 inline constexpr bool __is_path_iter_src = false;
106
107 template<typename _Iter_traits>
108 inline constexpr bool
109 __is_path_iter_src<_Iter_traits, void_t<typename _Iter_traits::value_type>>
110 = __is_encoded_char<typename _Iter_traits::value_type>;
111
112 template<typename _Source>
113 inline constexpr bool __is_path_src
114 = __is_path_iter_src<iterator_traits<decay_t<_Source>>>;
115
116 template<>
117 inline constexpr bool __is_path_src<path> = false;
118
119 template<>
120 inline constexpr bool __is_path_src<volatile path> = false;
121
122 template<>
123 inline constexpr bool __is_path_src<void*> = false;
124
125 template<>
126 inline constexpr bool __is_path_src<const void*> = false;
127
128 template<>
129 inline constexpr bool __is_path_src<volatile void*> = false;
130
131 template<>
132 inline constexpr bool __is_path_src<const volatile void*> = false;
133
134 template<typename _CharT, typename _Traits, typename _Alloc>
135 inline constexpr bool
136 __is_path_src<basic_string<_CharT, _Traits, _Alloc>>
137 = __is_encoded_char<_CharT>;
138
139 template<typename _CharT, typename _Traits>
140 inline constexpr bool
141 __is_path_src<basic_string_view<_CharT, _Traits>>
142 = __is_encoded_char<_CharT>;
143
144 // SFINAE constraint for Source parameters as required by [fs.path.req].
145 template<typename _Tp>
146 using _Path = enable_if_t<__is_path_src<_Tp>, path>;
147
148 // SFINAE constraint for InputIterator parameters as required by [fs.req].
149 template<typename _Iter, typename _Tr = __safe_iterator_traits<_Iter>>
150 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>, path>;
151
152#if __cpp_lib_concepts
153 template<typename _Iter>
154 constexpr bool __is_contiguous = std::contiguous_iterator<_Iter>;
155#else
156 template<typename _Iter>
157 constexpr bool __is_contiguous = false;
158#endif
159
160 template<typename _Tp>
161 constexpr bool __is_contiguous<_Tp*> = true;
162
163 template<typename _Tp, typename _Seq>
164 constexpr bool
165 __is_contiguous<__gnu_cxx::__normal_iterator<_Tp*, _Seq>> = true;
166
167#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
168 // For POSIX treat char8_t sequences as char without encoding conversions.
169 template<typename _EcharT>
170 using __unified_u8_t
171 = __conditional_t<is_same_v<_EcharT, char8_t>, char, _EcharT>;
172#else
173 template<typename _EcharT>
174 using __unified_u8_t = _EcharT;
175#endif
176
177 // The __effective_range overloads convert a Source parameter into
178 // either a basic_string_view<C> or basic_string<C> containing the
179 // effective range of the Source, as defined in [fs.path.req].
180
181 template<typename _CharT, typename _Traits, typename _Alloc>
182 inline basic_string_view<_CharT>
183 __effective_range(const basic_string<_CharT, _Traits, _Alloc>& __source)
184 noexcept
185 { return __source; }
186
187 template<typename _CharT, typename _Traits>
188 inline basic_string_view<_CharT>
189 __effective_range(const basic_string_view<_CharT, _Traits>& __source)
190 noexcept
191 { return __source; }
192
193 // Return the effective range of an NTCTS.
194 template<typename _Source>
195 auto
196 __effective_range(const _Source& __source)
197 {
198 // Remove a level of normal/safe iterator indirection, or decay an array.
199 using _Iter = decltype(std::__niter_base(__source));
200 using value_type = typename iterator_traits<_Iter>::value_type;
201
202 if constexpr (__is_contiguous<_Iter>)
203 return basic_string_view<value_type>{&*__source};
204 else
205 {
206 // _Source is an input iterator that iterates over an NTCTS.
207 // Create a basic_string by reading until the null character.
208 basic_string<__unified_u8_t<value_type>> __str;
209 _Source __it = __source;
210 for (value_type __ch = *__it; __ch != value_type(); __ch = *++__it)
211 __str.push_back(__ch);
212 return __str;
213 }
214 }
215
216 // The value type of a Source parameter's effective range.
217 template<typename _Source>
218 struct __source_value_type_impl
219 {
220 using type
221 = typename __safe_iterator_traits<decay_t<_Source>>::value_type;
222 };
223
224 template<typename _CharT, typename _Traits, typename _Alloc>
225 struct __source_value_type_impl<basic_string<_CharT, _Traits, _Alloc>>
226 {
227 using type = _CharT;
228 };
229
230 template<typename _CharT, typename _Traits>
231 struct __source_value_type_impl<basic_string_view<_CharT, _Traits>>
232 {
233 using type = _CharT;
234 };
235
236 // The value type of a Source parameter's effective range.
237 template<typename _Source>
238 using __source_value_t = typename __source_value_type_impl<_Source>::type;
239
240 // SFINAE helper to check that an effective range has value_type char,
241 // as required by path constructors taking a std::locale parameter.
242 // The type _Tp must have already been checked by _Path<Tp> or _Path2<_Tp>.
243 template<typename _Tp, typename _Val = __source_value_t<_Tp>>
244 using __value_type_is_char
246
247 // As above, but also allows char8_t, as required by u8path
248 // C++20 [depr.fs.path.factory]
249 template<typename _Tp, typename _Val = __source_value_t<_Tp>>
250 using __value_type_is_char_or_char8_t
252#ifdef _GLIBCXX_USE_CHAR8_T
253 || std::is_same_v<_Val, char8_t>
254#endif
255 , _Val>;
256
257 // Create a basic_string<C> or basic_string_view<C> from an iterator range.
258 template<typename _InputIterator>
259 inline auto
260 __string_from_range(_InputIterator __first, _InputIterator __last)
261 {
262 using _EcharT
264 static_assert(__is_encoded_char<_EcharT>); // C++17 [fs.req]/3
265
266 if constexpr (__is_contiguous<_InputIterator>)
267 {
268 // For contiguous iterators we can just return a string view.
269 if (auto __len = __last - __first) [[__likely__]]
270 return basic_string_view<_EcharT>(&*__first, __len);
271 return basic_string_view<_EcharT>();
272 }
273 else
274 {
275 // Conversion requires contiguous characters, so create a string.
276 return basic_string<__unified_u8_t<_EcharT>>(__first, __last);
277 }
278 }
279
280 /// @} group filesystem
281} // namespace __detail
282 /// @endcond
283
284 /// @addtogroup filesystem
285 /// @{
286
287 /// A filesystem path
288 /// @ingroup filesystem
289 class path
290 {
291 public:
292#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
293 using value_type = wchar_t;
294 static constexpr value_type preferred_separator = L'\\';
295#else
296# ifdef _GLIBCXX_DOXYGEN
297 /// Windows uses wchar_t for path::value_type, POSIX uses char.
298 using value_type = __os_dependent__;
299# else
300 using value_type = char;
301# endif
302 static constexpr value_type preferred_separator = '/';
303#endif
305
306 /// path::format is ignored in this implementation
307 enum format : unsigned char { native_format, generic_format, auto_format };
308
309 // constructors and destructor
310
311 path() noexcept { }
312
313 path(const path& __p) = default;
314
315 path(path&& __p) noexcept
316 : _M_pathname(std::move(__p._M_pathname)),
317 _M_cmpts(std::move(__p._M_cmpts))
318 { __p.clear(); }
319
320 path(string_type&& __source, format = auto_format)
321 : _M_pathname(std::move(__source))
322 { _M_split_cmpts(); }
323
324 template<typename _Source,
325 typename _Require = __detail::_Path<_Source>>
326 path(_Source const& __source, format = auto_format)
327 : _M_pathname(_S_convert(__detail::__effective_range(__source)))
328 { _M_split_cmpts(); }
329
330 template<typename _InputIterator,
331 typename _Require = __detail::_Path2<_InputIterator>>
332 path(_InputIterator __first, _InputIterator __last, format = auto_format)
333 : _M_pathname(_S_convert(__detail::__string_from_range(__first, __last)))
334 { _M_split_cmpts(); }
335
336 template<typename _Source,
337 typename _Require = __detail::_Path<_Source>,
338 typename _Require2 = __detail::__value_type_is_char<_Source>>
339 path(_Source const& __src, const locale& __loc, format = auto_format)
340 : _M_pathname(_S_convert_loc(__detail::__effective_range(__src), __loc))
341 { _M_split_cmpts(); }
342
343 template<typename _InputIterator,
344 typename _Require = __detail::_Path2<_InputIterator>,
345 typename _Req2 = __detail::__value_type_is_char<_InputIterator>>
346 path(_InputIterator __first, _InputIterator __last, const locale& __loc,
347 format = auto_format)
348 : _M_pathname(_S_convert_loc(__first, __last, __loc))
349 { _M_split_cmpts(); }
350
351 ~path() = default;
352
353 // assignments
354
355 path& operator=(const path&);
356 path& operator=(path&&) noexcept;
357 path& operator=(string_type&& __source);
358 path& assign(string_type&& __source);
359
360 template<typename _Source>
361 __detail::_Path<_Source>&
362 operator=(_Source const& __source)
363 { return *this = path(__source); }
364
365 template<typename _Source>
366 __detail::_Path<_Source>&
367 assign(_Source const& __source)
368 { return *this = path(__source); }
369
370 template<typename _InputIterator>
371 __detail::_Path2<_InputIterator>&
372 assign(_InputIterator __first, _InputIterator __last)
373 { return *this = path(__first, __last); }
374
375 // appends
376
377 path& operator/=(const path& __p);
378
379 template<typename _Source>
380 __detail::_Path<_Source>&
381 operator/=(_Source const& __source)
382 {
383 _M_append(_S_convert(__detail::__effective_range(__source)));
384 return *this;
385 }
386
387 template<typename _Source>
388 __detail::_Path<_Source>&
389 append(_Source const& __source)
390 {
391 _M_append(_S_convert(__detail::__effective_range(__source)));
392 return *this;
393 }
394
395 template<typename _InputIterator>
396 __detail::_Path2<_InputIterator>&
397 append(_InputIterator __first, _InputIterator __last)
398 {
399 _M_append(_S_convert(__detail::__string_from_range(__first, __last)));
400 return *this;
401 }
402
403 // concatenation
404
405 path& operator+=(const path& __x);
406 path& operator+=(const string_type& __x);
407 path& operator+=(const value_type* __x);
408 path& operator+=(value_type __x);
409 path& operator+=(basic_string_view<value_type> __x);
410
411 template<typename _Source>
412 __detail::_Path<_Source>&
413 operator+=(_Source const& __x) { return concat(__x); }
414
415 template<typename _CharT>
416 __detail::_Path2<_CharT*>&
417 operator+=(_CharT __x);
418
419 template<typename _Source>
420 __detail::_Path<_Source>&
421 concat(_Source const& __x)
422 {
423 _M_concat(_S_convert(__detail::__effective_range(__x)));
424 return *this;
425 }
426
427 template<typename _InputIterator>
428 __detail::_Path2<_InputIterator>&
429 concat(_InputIterator __first, _InputIterator __last)
430 {
431 _M_concat(_S_convert(__detail::__string_from_range(__first, __last)));
432 return *this;
433 }
434
435 // modifiers
436
437 void clear() noexcept { _M_pathname.clear(); _M_split_cmpts(); }
438
439 path& make_preferred();
440 path& remove_filename();
441 path& replace_filename(const path& __replacement);
442 path& replace_extension(const path& __replacement = path());
443
444 void swap(path& __rhs) noexcept;
445
446 // native format observers
447
448 const string_type& native() const noexcept { return _M_pathname; }
449 const value_type* c_str() const noexcept { return _M_pathname.c_str(); }
450 operator string_type() const { return _M_pathname; }
451
452 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
453 typename _Allocator = std::allocator<_CharT>>
455 string(const _Allocator& __a = _Allocator()) const;
456
457 std::string string() const;
458#if _GLIBCXX_USE_WCHAR_T
459 std::wstring wstring() const;
460#endif
461#ifdef _GLIBCXX_USE_CHAR8_T
462 __attribute__((__abi_tag__("__u8")))
463 std::u8string u8string() const;
464#else
465 std::string u8string() const;
466#endif // _GLIBCXX_USE_CHAR8_T
467 std::u16string u16string() const;
468 std::u32string u32string() const;
469
470 // generic format observers
471 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
472 typename _Allocator = std::allocator<_CharT>>
474 generic_string(const _Allocator& __a = _Allocator()) const;
475
476 std::string generic_string() const;
477#if _GLIBCXX_USE_WCHAR_T
478 std::wstring generic_wstring() const;
479#endif
480#ifdef _GLIBCXX_USE_CHAR8_T
481 __attribute__((__abi_tag__("__u8")))
482 std::u8string generic_u8string() const;
483#else
484 std::string generic_u8string() const;
485#endif // _GLIBCXX_USE_CHAR8_T
486 std::u16string generic_u16string() const;
487 std::u32string generic_u32string() const;
488
489 // compare
490
491 int compare(const path& __p) const noexcept;
492 int compare(const string_type& __s) const noexcept;
493 int compare(const value_type* __s) const noexcept;
494 int compare(basic_string_view<value_type> __s) const noexcept;
495
496 // decomposition
497
498 path root_name() const;
499 path root_directory() const;
500 path root_path() const;
501 path relative_path() const;
502 path parent_path() const;
503 path filename() const;
504 path stem() const;
505 path extension() const;
506
507 // query
508
509 [[nodiscard]] bool empty() const noexcept { return _M_pathname.empty(); }
510 bool has_root_name() const noexcept;
511 bool has_root_directory() const noexcept;
512 bool has_root_path() const noexcept;
513 bool has_relative_path() const noexcept;
514 bool has_parent_path() const noexcept;
515 bool has_filename() const noexcept;
516 bool has_stem() const noexcept;
517 bool has_extension() const noexcept;
518 bool is_absolute() const noexcept;
519 bool is_relative() const noexcept { return !is_absolute(); }
520
521 // generation
522 path lexically_normal() const;
523 path lexically_relative(const path& base) const;
524 path lexically_proximate(const path& base) const;
525
526 // iterators
527 class iterator;
528 using const_iterator = iterator;
529
530 iterator begin() const noexcept;
531 iterator end() const noexcept;
532
533 /// Write a path to a stream
534 template<typename _CharT, typename _Traits>
535 friend std::basic_ostream<_CharT, _Traits>&
536 operator<<(std::basic_ostream<_CharT, _Traits>& __os, const path& __p)
537 {
538 __os << std::quoted(__p.string<_CharT, _Traits>());
539 return __os;
540 }
541
542 /// Read a path from a stream
543 template<typename _CharT, typename _Traits>
546 {
548 if (__is >> std::quoted(__tmp))
549 __p = std::move(__tmp);
550 return __is;
551 }
552
553 // non-member operators
554
555 /// Compare paths
556 friend bool operator==(const path& __lhs, const path& __rhs) noexcept
557 { return path::_S_compare(__lhs, __rhs) == 0; }
558
559#if __cpp_lib_three_way_comparison
560 /// Compare paths
561 friend strong_ordering
562 operator<=>(const path& __lhs, const path& __rhs) noexcept
563 { return path::_S_compare(__lhs, __rhs) <=> 0; }
564#else
565 /// Compare paths
566 friend bool operator!=(const path& __lhs, const path& __rhs) noexcept
567 { return !(__lhs == __rhs); }
568
569 /// Compare paths
570 friend bool operator<(const path& __lhs, const path& __rhs) noexcept
571 { return __lhs.compare(__rhs) < 0; }
572
573 /// Compare paths
574 friend bool operator<=(const path& __lhs, const path& __rhs) noexcept
575 { return !(__rhs < __lhs); }
576
577 /// Compare paths
578 friend bool operator>(const path& __lhs, const path& __rhs) noexcept
579 { return __rhs < __lhs; }
580
581 /// Compare paths
582 friend bool operator>=(const path& __lhs, const path& __rhs) noexcept
583 { return !(__lhs < __rhs); }
584#endif
585
586 /// Append one path to another
587 friend path operator/(const path& __lhs, const path& __rhs)
588 {
589 path __result(__lhs);
590 __result /= __rhs;
591 return __result;
592 }
593
594 private:
595 enum class _Type : unsigned char {
596 _Multi = 0, _Root_name, _Root_dir, _Filename
597 };
598
599 path(basic_string_view<value_type> __str, _Type __type)
600 : _M_pathname(__str)
601 {
602 __glibcxx_assert(__type != _Type::_Multi);
603 _M_cmpts.type(__type);
604 }
605
606 enum class _Split { _Stem, _Extension };
607
608 void _M_append(basic_string_view<value_type>);
609 void _M_concat(basic_string_view<value_type>);
610
611 pair<const string_type*, size_t> _M_find_extension() const noexcept;
612
613 // path::_S_convert creates a basic_string<value_type> or
614 // basic_string_view<value_type> from a basic_string<C> or
615 // basic_string_view<C>, for an encoded character type C,
616 // performing the conversions required by [fs.path.type.cvt].
617 template<typename _Tp>
618 static auto
619 _S_convert(_Tp __str)
620 noexcept(is_same_v<typename _Tp::value_type, value_type>)
621 {
622 if constexpr (is_same_v<typename _Tp::value_type, value_type>)
623 return __str; // No conversion needed.
624#if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T
625 else if constexpr (is_same_v<_Tp, std::u8string>)
626 // Calling _S_convert<char8_t> will return a u8string_view that
627 // refers to __str and would dangle after this function returns.
628 // Return a string_type instead, to avoid dangling.
629 return string_type(_S_convert(__str.data(),
630 __str.data() + __str.size()));
631#endif
632 else
633 return _S_convert(__str.data(), __str.data() + __str.size());
634 }
635
636 template<typename _EcharT>
637 static auto
638 _S_convert(const _EcharT* __first, const _EcharT* __last);
639
640 // _S_convert_loc converts a range of char to string_type, using the
641 // supplied locale for encoding conversions.
642
643 static string_type
644 _S_convert_loc(const char* __first, const char* __last,
645 const std::locale& __loc);
646
647 template<typename _Iter>
648 static string_type
649 _S_convert_loc(_Iter __first, _Iter __last, const std::locale& __loc)
650 {
651 const auto __s = __detail::__string_from_range(__first, __last);
652 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
653 }
654
655 template<typename _Tp>
656 static string_type
657 _S_convert_loc(const _Tp& __s, const std::locale& __loc)
658 {
659 return _S_convert_loc(__s.data(), __s.data() + __s.size(), __loc);
660 }
661
662 template<typename _CharT, typename _Traits, typename _Allocator>
663 static basic_string<_CharT, _Traits, _Allocator>
664 _S_str_convert(basic_string_view<value_type>, const _Allocator&);
665
666 // Returns lhs.compare(rhs), but defined after path::iterator is complete.
667 __attribute__((__always_inline__))
668 static int
669 _S_compare(const path& __lhs, const path& __rhs) noexcept;
670
671 void _M_split_cmpts();
672
673 _Type _M_type() const noexcept { return _M_cmpts.type(); }
674
675 string_type _M_pathname;
676
677 struct _Cmpt;
678
679 struct _List
680 {
681 using value_type = _Cmpt;
682 using iterator = value_type*;
683 using const_iterator = const value_type*;
684
685 _List();
686 _List(const _List&);
687 _List(_List&&) = default;
688 _List& operator=(const _List&);
689 _List& operator=(_List&&) = default;
690 ~_List() = default;
691
692 _Type type() const noexcept
693 { return _Type(reinterpret_cast<uintptr_t>(_M_impl.get()) & 0x3); }
694
695 void type(_Type) noexcept;
696
697 int size() const noexcept; // zero unless type() == _Type::_Multi
698 bool empty() const noexcept; // true unless type() == _Type::_Multi
699 void clear();
700 void swap(_List& __l) noexcept { _M_impl.swap(__l._M_impl); }
701 int capacity() const noexcept;
702 void reserve(int, bool); ///< @pre type() == _Type::_Multi
703
704 // All the member functions below here have a precondition !empty()
705 // (and they should only be called from within the library).
706
707 iterator begin() noexcept;
708 iterator end() noexcept;
709 const_iterator begin() const noexcept;
710 const_iterator end() const noexcept;
711
712 value_type& front() noexcept;
713 value_type& back() noexcept;
714 const value_type& front() const noexcept;
715 const value_type& back() const noexcept;
716
717 void pop_back();
718 void _M_erase_from(const_iterator __pos); // erases [__pos,end())
719
720 struct _Impl;
721 struct _Impl_deleter
722 {
723 void operator()(_Impl*) const noexcept;
724 };
725 unique_ptr<_Impl, _Impl_deleter> _M_impl;
726 };
727 _List _M_cmpts;
728
729 struct _Parser;
730
731 template<typename _EcharT> struct _Codecvt;
732 };
733
734 /// @{
735 /// @relates std::filesystem::path
736
737 inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
738
739 size_t hash_value(const path& __p) noexcept;
740
741 /// @}
742
743 /// Exception type thrown by the Filesystem library
745 {
746 public:
747 filesystem_error(const string& __what_arg, error_code __ec);
748
749 filesystem_error(const string& __what_arg, const path& __p1,
750 error_code __ec);
751
752 filesystem_error(const string& __what_arg, const path& __p1,
753 const path& __p2, error_code __ec);
754
755 filesystem_error(const filesystem_error&) = default;
756 filesystem_error& operator=(const filesystem_error&) = default;
757
758 // No move constructor or assignment operator.
759 // Copy rvalues instead, so that _M_impl is not left empty.
760
762
763 const path& path1() const noexcept;
764 const path& path2() const noexcept;
765 const char* what() const noexcept;
766
767 private:
768 struct _Impl;
769 std::__shared_ptr<const _Impl> _M_impl;
770 };
771
772 /// @cond undocumented
773namespace __detail
774{
775 [[noreturn]] inline void
776 __throw_conversion_error()
777 {
778 _GLIBCXX_THROW_OR_ABORT(filesystem_error(
779 "Cannot convert character sequence",
780 std::make_error_code(errc::illegal_byte_sequence)));
781 }
782
783#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
784 template<typename _Tp>
785 inline std::wstring
786 __wstr_from_utf8(const _Tp& __str)
787 {
788 static_assert(std::is_same_v<typename _Tp::value_type, char>);
789 std::wstring __wstr;
790 // XXX This assumes native wide encoding is UTF-16.
791 std::codecvt_utf8_utf16<wchar_t> __wcvt;
792 const auto __p = __str.data();
793 if (!__str_codecvt_in_all(__p, __p + __str.size(), __wstr, __wcvt))
794 __detail::__throw_conversion_error();
795 return __wstr;
796 }
797#endif
798
799} // namespace __detail
800 /// @endcond
801
802
803 /** Create a path from a UTF-8-encoded sequence of char
804 *
805 * @relates std::filesystem::path
806 */
807 template<typename _InputIterator,
808 typename _Require = __detail::_Path2<_InputIterator>,
809 typename _CharT
810 = __detail::__value_type_is_char_or_char8_t<_InputIterator>>
811 _GLIBCXX20_DEPRECATED_SUGGEST("path(u8string(first, last))")
812 inline path
813 u8path(_InputIterator __first, _InputIterator __last)
814 {
815#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
816 if constexpr (is_same_v<_CharT, char>)
817 return path{ __detail::__wstr_from_utf8(
818 __detail::__string_from_range(__first, __last)) };
819 else
820 return path{ __first, __last }; // constructor handles char8_t
821#else
822 // This assumes native normal encoding is UTF-8.
823 return path{ __first, __last };
824#endif
825 }
826
827 /** Create a path from a UTF-8-encoded sequence of char
828 *
829 * @relates std::filesystem::path
830 */
831 template<typename _Source,
832 typename _Require = __detail::_Path<_Source>,
833 typename _CharT = __detail::__value_type_is_char_or_char8_t<_Source>>
834 _GLIBCXX20_DEPRECATED_SUGGEST("path((const char8_t*)&*source)")
835 inline path
836 u8path(const _Source& __source)
837 {
838#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
839 if constexpr (is_same_v<_CharT, char>)
840 return path{ __detail::__wstr_from_utf8(
841 __detail::__effective_range(__source)) };
842 else
843 return path{ __source }; // constructor handles char8_t
844#else
845 // This assumes native normal encoding is UTF-8.
846 return path{ __source };
847#endif
848 }
849
850 /// @cond undocumented
851
852 struct path::_Cmpt : path
853 {
854 _Cmpt(basic_string_view<value_type> __s, _Type __t, size_t __pos)
855 : path(__s, __t), _M_pos(__pos) { }
856
857 _Cmpt() : _M_pos(-1) { }
858
859 size_t _M_pos;
860 };
861
862 // path::_Codecvt<C> Performs conversions between C and path::string_type.
863 // The native encoding of char strings is the OS-dependent current
864 // encoding for pathnames. FIXME: We assume this is UTF-8 everywhere,
865 // but should use a Windows API to query it.
866
867 // Converts between native pathname encoding and char16_t or char32_t.
868 template<typename _EcharT>
869 struct path::_Codecvt
870 // Need derived class here because std::codecvt has protected destructor.
871 : std::codecvt<_EcharT, char, mbstate_t>
872 { };
873
874 // Converts between native pathname encoding and native wide encoding.
875 // The native encoding for wide strings is the execution wide-character
876 // set encoding. FIXME: We assume that this is either UTF-32 or UTF-16
877 // (depending on the width of wchar_t). That matches GCC's default,
878 // but can be changed with -fwide-exec-charset.
879 // We need a custom codecvt converting the native pathname encoding
880 // to/from the native wide encoding.
881 template<>
882 struct path::_Codecvt<wchar_t>
883 : __conditional_t<sizeof(wchar_t) == sizeof(char32_t),
884 std::codecvt_utf8<wchar_t>, // UTF-8 <-> UTF-32
885 std::codecvt_utf8_utf16<wchar_t>> // UTF-8 <-> UTF-16
886 { };
887
888 template<typename _EcharT>
889 auto
890 path::_S_convert(const _EcharT* __f, const _EcharT* __l)
891 {
892 static_assert(__detail::__is_encoded_char<_EcharT>);
893
894#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
895# define _GLIBCXX_CONV_FROM_UTF8(S) __detail::__wstr_from_utf8(S)
896#else
897# define _GLIBCXX_CONV_FROM_UTF8(S) S
898#endif
899
900 if constexpr (is_same_v<_EcharT, value_type>)
901 return basic_string_view<value_type>(__f, __l - __f);
902#ifdef _GLIBCXX_USE_CHAR8_T
903 else if constexpr (is_same_v<_EcharT, char8_t>)
904 {
905 string_view __str(reinterpret_cast<const char*>(__f), __l - __f);
906 return _GLIBCXX_CONV_FROM_UTF8(__str);
907 }
908#endif
909#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
910 else if constexpr (is_same_v<_EcharT, char>)
911 {
912 std::wstring __wstr;
913 path::_Codecvt<wchar_t> __cvt;
914 if (__str_codecvt_in_all(__f, __l, __wstr, __cvt))
915 return __wstr;
916 }
917#endif
918 else
919 {
920 path::_Codecvt<_EcharT> __cvt;
921 std::string __str;
922 if (__str_codecvt_out_all(__f, __l, __str, __cvt))
923 return _GLIBCXX_CONV_FROM_UTF8(__str);
924 }
925 __detail::__throw_conversion_error();
926 }
927#undef _GLIBCXX_CONV_FROM_UTF8
928
929 /// @endcond
930
931 /// An iterator for the components of a path
933 {
934 public:
935 using difference_type = std::ptrdiff_t;
936 using value_type = path;
937 using reference = const path&;
938 using pointer = const path*;
940
941 iterator() noexcept : _M_path(nullptr), _M_cur(), _M_at_end() { }
942
943 iterator(const iterator&) = default;
944 iterator& operator=(const iterator&) = default;
945
946 reference operator*() const noexcept;
947 pointer operator->() const noexcept { return std::__addressof(**this); }
948
949 iterator& operator++() noexcept;
950
951 iterator operator++(int) noexcept
952 { auto __tmp = *this; ++*this; return __tmp; }
953
954 iterator& operator--() noexcept;
955
956 iterator operator--(int) noexcept
957 { auto __tmp = *this; --*this; return __tmp; }
958
959 friend bool
960 operator==(const iterator& __lhs, const iterator& __rhs) noexcept
961 { return __lhs._M_equals(__rhs); }
962
963 friend bool
964 operator!=(const iterator& __lhs, const iterator& __rhs) noexcept
965 { return !__lhs._M_equals(__rhs); }
966
967 private:
968 friend class path;
969
970 bool
971 _M_is_multi() const noexcept
972 { return _M_path->_M_type() == _Type::_Multi; }
973
974 friend difference_type
975 __path_iter_distance(const iterator& __first, const iterator& __last)
976 noexcept
977 {
978 __glibcxx_assert(__first._M_path != nullptr);
979 __glibcxx_assert(__first._M_path == __last._M_path);
980 if (__first._M_is_multi())
981 return std::distance(__first._M_cur, __last._M_cur);
982 else if (__first._M_at_end == __last._M_at_end)
983 return 0;
984 else
985 return __first._M_at_end ? -1 : 1;
986 }
987
988 friend void
989 __path_iter_advance(iterator& __i, difference_type __n) noexcept
990 {
991 if (__n == 1)
992 ++__i;
993 else if (__n == -1)
994 --__i;
995 else if (__n != 0)
996 {
997 __glibcxx_assert(__i._M_path != nullptr);
998 __glibcxx_assert(__i._M_is_multi());
999 // __glibcxx_assert(__i._M_path->_M_cmpts.end() - __i._M_cur >= __n);
1000 __i._M_cur += __n;
1001 }
1002 }
1003
1004 iterator(const path* __path, path::_List::const_iterator __iter) noexcept
1005 : _M_path(__path), _M_cur(__iter), _M_at_end()
1006 { }
1007
1008 iterator(const path* __path, bool __at_end) noexcept
1009 : _M_path(__path), _M_cur(), _M_at_end(__at_end)
1010 { }
1011
1012 bool _M_equals(iterator) const noexcept;
1013
1014 const path* _M_path;
1015 path::_List::const_iterator _M_cur;
1016 bool _M_at_end; // only used when type != _Multi
1017 };
1018
1019
1020 inline path&
1021 path::operator=(path&& __p) noexcept
1022 {
1023 if (&__p == this) [[__unlikely__]]
1024 return *this;
1025
1026 _M_pathname = std::move(__p._M_pathname);
1027 _M_cmpts = std::move(__p._M_cmpts);
1028 __p.clear();
1029 return *this;
1030 }
1031
1032 inline path&
1033 path::operator=(string_type&& __source)
1034 { return *this = path(std::move(__source)); }
1035
1036 inline path&
1037 path::assign(string_type&& __source)
1038 { return *this = path(std::move(__source)); }
1039
1040 inline path&
1041 path::operator+=(const string_type& __x)
1042 {
1043 _M_concat(__x);
1044 return *this;
1045 }
1046
1047 inline path&
1048 path::operator+=(const value_type* __x)
1049 {
1050 _M_concat(__x);
1051 return *this;
1052 }
1053
1054 inline path&
1055 path::operator+=(value_type __x)
1056 {
1057 _M_concat(basic_string_view<value_type>(&__x, 1));
1058 return *this;
1059 }
1060
1061 inline path&
1062 path::operator+=(basic_string_view<value_type> __x)
1063 {
1064 _M_concat(__x);
1065 return *this;
1066 }
1067
1068 template<typename _CharT>
1069 inline __detail::_Path2<_CharT*>&
1070 path::operator+=(const _CharT __x)
1071 {
1072 _M_concat(_S_convert(&__x, &__x + 1));
1073 return *this;
1074 }
1075
1076 inline path&
1077 path::make_preferred()
1078 {
1079#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1080 auto __pos = _M_pathname.find(L'/');
1081 while (__pos != _M_pathname.npos)
1082 {
1083 _M_pathname[__pos] = preferred_separator;
1084 __pos = _M_pathname.find(L'/', __pos);
1085 }
1086#endif
1087 return *this;
1088 }
1089
1090 inline void path::swap(path& __rhs) noexcept
1091 {
1092 _M_pathname.swap(__rhs._M_pathname);
1093 _M_cmpts.swap(__rhs._M_cmpts);
1094 }
1095
1096 /// @cond undocumented
1097 template<typename _CharT, typename _Traits, typename _Allocator>
1099 path::_S_str_convert(basic_string_view<value_type> __str,
1100 const _Allocator& __a)
1101 {
1102 static_assert(!is_same_v<_CharT, value_type>);
1103
1104 using _WString = basic_string<_CharT, _Traits, _Allocator>;
1105
1106 if (__str.size() == 0)
1107 return _WString(__a);
1108
1109#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1110 string_view __u8str = __str;
1111#else
1112 // First convert native string from UTF-16 to to UTF-8.
1113 // XXX This assumes that the execution wide-character set is UTF-16.
1114 std::codecvt_utf8_utf16<value_type> __cvt;
1115
1116 using _CharAlloc = __alloc_rebind<_Allocator, char>;
1117 using _String = basic_string<char, char_traits<char>, _CharAlloc>;
1118 _String __u8str{_CharAlloc{__a}};
1119 const value_type* __wfirst = __str.data();
1120 const value_type* __wlast = __wfirst + __str.size();
1121 if (!__str_codecvt_out_all(__wfirst, __wlast, __u8str, __cvt))
1122 __detail::__throw_conversion_error();
1123 if constexpr (is_same_v<_CharT, char>)
1124 return __u8str; // XXX assumes native ordinary encoding is UTF-8.
1125 else
1126#endif
1127 {
1128 const char* __first = __u8str.data();
1129 const char* __last = __first + __u8str.size();
1130
1131 // Convert UTF-8 string to requested format.
1132#ifdef _GLIBCXX_USE_CHAR8_T
1133 if constexpr (is_same_v<_CharT, char8_t>)
1134 return _WString(__first, __last, __a);
1135 else
1136#endif
1137 {
1138 // Convert UTF-8 to wide string.
1139 _WString __wstr(__a);
1140 path::_Codecvt<_CharT> __cvt;
1141 if (__str_codecvt_in_all(__first, __last, __wstr, __cvt))
1142 return __wstr;
1143 }
1144 }
1145 __detail::__throw_conversion_error();
1146 }
1147 /// @endcond
1148
1149 template<typename _CharT, typename _Traits, typename _Allocator>
1150 inline basic_string<_CharT, _Traits, _Allocator>
1151 path::string(const _Allocator& __a) const
1152 {
1153 if constexpr (is_same_v<_CharT, value_type>)
1154 return { _M_pathname.c_str(), _M_pathname.length(), __a };
1155 else
1156 return _S_str_convert<_CharT, _Traits>(_M_pathname, __a);
1157 }
1158
1159 inline std::string
1160 path::string() const { return string<char>(); }
1161
1162#if _GLIBCXX_USE_WCHAR_T
1163 inline std::wstring
1164 path::wstring() const { return string<wchar_t>(); }
1165#endif
1166
1167#ifdef _GLIBCXX_USE_CHAR8_T
1168 inline std::u8string
1169 path::u8string() const { return string<char8_t>(); }
1170#else
1171 inline std::string
1172 path::u8string() const
1173 {
1174#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1175 std::string __str;
1176 // convert from native wide encoding (assumed to be UTF-16) to UTF-8
1177 std::codecvt_utf8_utf16<value_type> __cvt;
1178 const value_type* __first = _M_pathname.data();
1179 const value_type* __last = __first + _M_pathname.size();
1180 if (__str_codecvt_out_all(__first, __last, __str, __cvt))
1181 return __str;
1182 __detail::__throw_conversion_error();
1183#else
1184 return _M_pathname;
1185#endif
1186 }
1187#endif // _GLIBCXX_USE_CHAR8_T
1188
1189 inline std::u16string
1190 path::u16string() const { return string<char16_t>(); }
1191
1192 inline std::u32string
1193 path::u32string() const { return string<char32_t>(); }
1194
1195 template<typename _CharT, typename _Traits, typename _Allocator>
1197 path::generic_string(const _Allocator& __a) const
1198 {
1199#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1200 const value_type __slash = L'/';
1201#else
1202 const value_type __slash = '/';
1203#endif
1204 using _Alloc2 = typename allocator_traits<_Allocator>::template
1205 rebind_alloc<value_type>;
1206 basic_string<value_type, char_traits<value_type>, _Alloc2> __str(__a);
1207
1208 if (_M_type() == _Type::_Root_dir)
1209 __str.assign(1, __slash);
1210 else
1211 {
1212 __str.reserve(_M_pathname.size());
1213 bool __add_slash = false;
1214 for (auto& __elem : *this)
1215 {
1216#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1217 if (__elem._M_type() == _Type::_Root_dir)
1218 {
1219 __str += __slash;
1220 continue;
1221 }
1222#endif
1223 if (__add_slash)
1224 __str += __slash;
1225 __str += basic_string_view<value_type>(__elem._M_pathname);
1226 __add_slash = __elem._M_type() == _Type::_Filename;
1227 }
1228 }
1229
1230 if constexpr (is_same_v<_CharT, value_type>)
1231 return __str;
1232 else
1233 return _S_str_convert<_CharT, _Traits>(__str, __a);
1234 }
1235
1236 inline std::string
1237 path::generic_string() const
1238 { return generic_string<char>(); }
1239
1240#if _GLIBCXX_USE_WCHAR_T
1241 inline std::wstring
1242 path::generic_wstring() const
1243 { return generic_string<wchar_t>(); }
1244#endif
1245
1246#ifdef _GLIBCXX_USE_CHAR8_T
1247 inline std::u8string
1248 path::generic_u8string() const
1249 { return generic_string<char8_t>(); }
1250#else
1251 inline std::string
1252 path::generic_u8string() const
1253 { return generic_string(); }
1254#endif
1255
1256 inline std::u16string
1257 path::generic_u16string() const
1258 { return generic_string<char16_t>(); }
1259
1260 inline std::u32string
1261 path::generic_u32string() const
1262 { return generic_string<char32_t>(); }
1263
1264 inline int
1265 path::compare(const string_type& __s) const noexcept
1266 { return compare(basic_string_view<value_type>(__s)); }
1267
1268 inline int
1269 path::compare(const value_type* __s) const noexcept
1270 { return compare(basic_string_view<value_type>(__s)); }
1271
1272 inline path
1273 path::filename() const
1274 {
1275 if (empty())
1276 return {};
1277 else if (_M_type() == _Type::_Filename)
1278 return *this;
1279 else if (_M_type() == _Type::_Multi)
1280 {
1281 if (_M_pathname.back() == preferred_separator)
1282 return {};
1283 auto __last = --end();
1284 if (__last->_M_type() == _Type::_Filename)
1285 return *__last;
1286 }
1287 return {};
1288 }
1289
1290 inline path
1291 path::stem() const
1292 {
1293 auto ext = _M_find_extension();
1294 if (ext.first && ext.second != 0)
1295 return path{ext.first->substr(0, ext.second)};
1296 return {};
1297 }
1298
1299 inline path
1300 path::extension() const
1301 {
1302 auto ext = _M_find_extension();
1303 if (ext.first && ext.second != string_type::npos)
1304 return path{ext.first->substr(ext.second)};
1305 return {};
1306 }
1307
1308 inline bool
1309 path::has_stem() const noexcept
1310 {
1311 auto ext = _M_find_extension();
1312 return ext.first && ext.second != 0;
1313 }
1314
1315 inline bool
1316 path::has_extension() const noexcept
1317 {
1318 auto ext = _M_find_extension();
1319 return ext.first && ext.second != string_type::npos;
1320 }
1321
1322 inline bool
1323 path::is_absolute() const noexcept
1324 {
1325#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
1326 return has_root_name() && has_root_directory();
1327#else
1328 return has_root_directory();
1329#endif
1330 }
1331
1332 inline path::iterator
1333 path::begin() const noexcept
1334 {
1335 if (_M_type() == _Type::_Multi)
1336 return iterator(this, _M_cmpts.begin());
1337 return iterator(this, empty());
1338 }
1339
1340 inline path::iterator
1341 path::end() const noexcept
1342 {
1343 if (_M_type() == _Type::_Multi)
1344 return iterator(this, _M_cmpts.end());
1345 return iterator(this, true);
1346 }
1347
1348 inline path::iterator&
1349 path::iterator::operator++() noexcept
1350 {
1351 __glibcxx_assert(_M_path != nullptr);
1352 if (_M_is_multi())
1353 {
1354 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1355 ++_M_cur;
1356 }
1357 else
1358 {
1359 __glibcxx_assert(!_M_at_end);
1360 _M_at_end = true;
1361 }
1362 return *this;
1363 }
1364
1365 inline path::iterator&
1366 path::iterator::operator--() noexcept
1367 {
1368 __glibcxx_assert(_M_path != nullptr);
1369 if (_M_is_multi())
1370 {
1371 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.begin());
1372 --_M_cur;
1373 }
1374 else
1375 {
1376 __glibcxx_assert(_M_at_end);
1377 _M_at_end = false;
1378 }
1379 return *this;
1380 }
1381
1382 inline path::iterator::reference
1383 path::iterator::operator*() const noexcept
1384 {
1385 __glibcxx_assert(_M_path != nullptr);
1386 if (_M_is_multi())
1387 {
1388 __glibcxx_assert(_M_cur != _M_path->_M_cmpts.end());
1389 return *_M_cur;
1390 }
1391 return *_M_path;
1392 }
1393
1394 inline bool
1395 path::iterator::_M_equals(iterator __rhs) const noexcept
1396 {
1397 if (_M_path != __rhs._M_path)
1398 return false;
1399 if (_M_path == nullptr)
1400 return true;
1401 if (_M_is_multi())
1402 return _M_cur == __rhs._M_cur;
1403 return _M_at_end == __rhs._M_at_end;
1404 }
1405
1406 // Define this now that path and path::iterator are complete.
1407 // It needs to consider the string_view(Range&&) constructor during
1408 // overload resolution, which depends on whether range<path> is satisfied,
1409 // which depends on whether path::iterator is complete.
1410 inline int
1411 path::_S_compare(const path& __lhs, const path& __rhs) noexcept
1412 { return __lhs.compare(__rhs); }
1413
1414 /// @} group filesystem
1415_GLIBCXX_END_NAMESPACE_CXX11
1416} // namespace filesystem
1417
1418/// @cond undocumented
1419
1420inline ptrdiff_t
1421distance(filesystem::path::iterator __first, filesystem::path::iterator __last)
1422noexcept
1423{ return __path_iter_distance(__first, __last); }
1424
1425template<typename _Distance>
1426 inline void
1427 advance(filesystem::path::iterator& __i, _Distance __n) noexcept
1428 { __path_iter_advance(__i, static_cast<ptrdiff_t>(__n)); }
1429
1430extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
1431
1432/// @endcond
1433
1434// _GLIBCXX_RESOLVE_LIB_DEFECTS
1435// 3657. std::hash<std::filesystem::path> is not enabled
1436template<>
1437 struct hash<filesystem::path>
1438 {
1439 size_t
1440 operator()(const filesystem::path& __p) const noexcept
1441 { return filesystem::hash_value(__p); }
1442 };
1443
1444_GLIBCXX_END_NAMESPACE_VERSION
1445} // namespace std
1446
1447#endif // C++17
1448
1449#endif // _GLIBCXX_FS_PATH_H
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
Definition: complex:395
error_code make_error_code(future_errc __errc) noexcept
Overload of make_error_code for future_errc.
Definition: future:94
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
Definition: type_traits:2594
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:104
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition: move.h:49
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
Definition: valarray:1239
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
Definition: range_access.h:284
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.
Definition: iomanip:463
Template class basic_istream.
Definition: istream:61
Template class basic_ostream.
Definition: ostream:61
A non-owning reference to a string.
Definition: string_view:107
An exception type that includes an error_code value.
Definition: system_error:557
Primary class template codecvt.
Definition: codecvt.h:279
const _CharT * data() const noexcept
Return const pointer to contents.
Definition: cow_string.h:2218
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
Definition: cow_string.h:3478
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
Definition: cow_string.h:3216
void clear() noexcept
Definition: cow_string.h:1004
bool empty() const noexcept
Definition: cow_string.h:1026
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Definition: cow_string.h:2206
Traits class for iterators.
A filesystem path.
Definition: bits/fs_path.h:290
friend bool operator!=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Definition: bits/fs_path.h:566
friend bool operator<=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Definition: bits/fs_path.h:574
friend bool operator>(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Definition: bits/fs_path.h:578
friend path operator/(const path &__lhs, const path &__rhs)
Append one path to another.
Definition: bits/fs_path.h:587
format
path::format is ignored in this implementation
Definition: bits/fs_path.h:307
friend bool operator>=(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Definition: bits/fs_path.h:582
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, path &__p)
Read a path from a stream.
Definition: bits/fs_path.h:545
friend bool operator<(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Definition: bits/fs_path.h:570
#define _GLIBCXX20_DEPRECATED_SUGGEST(ALT)
friend bool operator==(const path &__lhs, const path &__rhs) noexcept
Compare paths.
Definition: bits/fs_path.h:556
Exception type thrown by the Filesystem library.
Definition: bits/fs_path.h:745
const char * what() const noexcept
An iterator for the components of a path.
Definition: bits/fs_path.h:933
Container class for localization functionality.
Bidirectional iterators support a superset of forward iterator operations.