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