path_traits.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. // filesystem path_traits.hpp --------------------------------------------------------//
  2. // Copyright Beman Dawes 2009
  3. // Copyright Andrey Semashev 2022-2024
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. // Library home page: http://www.boost.org/libs/filesystem
  7. #ifndef BOOST_FILESYSTEM_DETAIL_PATH_TRAITS_HPP
  8. #define BOOST_FILESYSTEM_DETAIL_PATH_TRAITS_HPP
  9. #include <boost/filesystem/config.hpp>
  10. #include <cstddef>
  11. #include <cstring> // for strlen
  12. #include <cwchar> // for mbstate_t, wcslen
  13. #include <locale>
  14. #include <string>
  15. #include <iterator>
  16. #include <type_traits>
  17. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  18. #include <string_view>
  19. #endif
  20. #include <boost/assert.hpp>
  21. #include <boost/system/error_category.hpp>
  22. #include <boost/iterator/is_iterator.hpp>
  23. #include <boost/filesystem/detail/type_traits/conjunction.hpp>
  24. #if defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  25. #include <boost/filesystem/detail/type_traits/disjunction.hpp>
  26. #endif
  27. #if defined(BOOST_FILESYSTEM_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  28. #include <vector>
  29. #include <list>
  30. #endif
  31. #include <boost/filesystem/detail/header.hpp> // must be the last #include
  32. namespace boost {
  33. template< typename, typename > class basic_string_view;
  34. namespace container {
  35. template< typename, typename, typename > class basic_string;
  36. } // namespace container
  37. namespace filesystem {
  38. BOOST_FILESYSTEM_DECL system::error_category const& codecvt_error_category() noexcept;
  39. class directory_entry;
  40. namespace detail {
  41. namespace path_traits {
  42. #if defined(BOOST_WINDOWS_API)
  43. typedef wchar_t path_native_char_type;
  44. #define BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE false
  45. #define BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE true
  46. #else
  47. typedef char path_native_char_type;
  48. #define BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE true
  49. #define BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE false
  50. #endif
  51. typedef std::codecvt< wchar_t, char, std::mbstate_t > codecvt_type;
  52. struct unknown_type_tag {};
  53. struct ntcts_type_tag {};
  54. struct char_ptr_tag : ntcts_type_tag {};
  55. struct char_array_tag : ntcts_type_tag {};
  56. struct string_class_tag {};
  57. struct std_string_tag : string_class_tag {};
  58. struct boost_container_string_tag : string_class_tag {};
  59. struct std_string_view_tag : string_class_tag {};
  60. struct boost_string_view_tag : string_class_tag {};
  61. struct range_type_tag {};
  62. struct directory_entry_tag {};
  63. //! The traits define a number of properties of a path source
  64. template< typename T >
  65. struct path_source_traits
  66. {
  67. //! The kind of the path source. Useful for dispatching.
  68. typedef unknown_type_tag tag_type;
  69. //! Character type that the source contains
  70. typedef void char_type;
  71. //! Indicates whether the source is natively supported by \c path::string_type as arguments for constructors/assignment/appending
  72. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  73. };
  74. template< >
  75. struct path_source_traits< char* >
  76. {
  77. typedef char_ptr_tag tag_type;
  78. typedef char char_type;
  79. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  80. };
  81. template< >
  82. struct path_source_traits< const char* >
  83. {
  84. typedef char_ptr_tag tag_type;
  85. typedef char char_type;
  86. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  87. };
  88. template< >
  89. struct path_source_traits< wchar_t* >
  90. {
  91. typedef char_ptr_tag tag_type;
  92. typedef wchar_t char_type;
  93. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  94. };
  95. template< >
  96. struct path_source_traits< const wchar_t* >
  97. {
  98. typedef char_ptr_tag tag_type;
  99. typedef wchar_t char_type;
  100. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  101. };
  102. template< >
  103. struct path_source_traits< char[] >
  104. {
  105. typedef char_array_tag tag_type;
  106. typedef char char_type;
  107. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  108. };
  109. template< >
  110. struct path_source_traits< const char[] >
  111. {
  112. typedef char_array_tag tag_type;
  113. typedef char char_type;
  114. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  115. };
  116. template< >
  117. struct path_source_traits< wchar_t[] >
  118. {
  119. typedef char_array_tag tag_type;
  120. typedef wchar_t char_type;
  121. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  122. };
  123. template< >
  124. struct path_source_traits< const wchar_t[] >
  125. {
  126. typedef char_array_tag tag_type;
  127. typedef wchar_t char_type;
  128. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  129. };
  130. template< std::size_t N >
  131. struct path_source_traits< char[N] >
  132. {
  133. typedef char_array_tag tag_type;
  134. typedef char char_type;
  135. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  136. };
  137. template< std::size_t N >
  138. struct path_source_traits< const char[N] >
  139. {
  140. typedef char_array_tag tag_type;
  141. typedef char char_type;
  142. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  143. };
  144. template< std::size_t N >
  145. struct path_source_traits< wchar_t[N] >
  146. {
  147. typedef char_array_tag tag_type;
  148. typedef wchar_t char_type;
  149. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  150. };
  151. template< std::size_t N >
  152. struct path_source_traits< const wchar_t[N] >
  153. {
  154. typedef char_array_tag tag_type;
  155. typedef wchar_t char_type;
  156. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  157. };
  158. template< >
  159. struct path_source_traits< std::string >
  160. {
  161. typedef std_string_tag tag_type;
  162. typedef char char_type;
  163. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  164. };
  165. template< >
  166. struct path_source_traits< std::wstring >
  167. {
  168. typedef std_string_tag tag_type;
  169. typedef wchar_t char_type;
  170. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  171. };
  172. template< >
  173. struct path_source_traits< boost::container::basic_string< char, std::char_traits< char >, void > >
  174. {
  175. typedef boost_container_string_tag tag_type;
  176. typedef char char_type;
  177. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  178. };
  179. template< >
  180. struct path_source_traits< boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > >
  181. {
  182. typedef boost_container_string_tag tag_type;
  183. typedef wchar_t char_type;
  184. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  185. };
  186. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  187. template< >
  188. struct path_source_traits< std::string_view >
  189. {
  190. typedef std_string_view_tag tag_type;
  191. typedef char char_type;
  192. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE;
  193. };
  194. template< >
  195. struct path_source_traits< std::wstring_view >
  196. {
  197. typedef std_string_view_tag tag_type;
  198. typedef wchar_t char_type;
  199. static BOOST_CONSTEXPR_OR_CONST bool is_native = BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE;
  200. };
  201. #endif // !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  202. template< >
  203. struct path_source_traits< boost::basic_string_view< char, std::char_traits< char > > >
  204. {
  205. typedef boost_string_view_tag tag_type;
  206. typedef char char_type;
  207. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  208. };
  209. template< >
  210. struct path_source_traits< boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > >
  211. {
  212. typedef boost_string_view_tag tag_type;
  213. typedef wchar_t char_type;
  214. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  215. };
  216. #if defined(BOOST_FILESYSTEM_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  217. template< >
  218. struct
  219. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Boost.Filesystem path construction/assignment/appending from containers is deprecated, use strings or iterators instead.")
  220. path_source_traits< std::vector< char > >
  221. {
  222. // Since C++11 this could be string_class_tag as std::vector gained data() member
  223. typedef range_type_tag tag_type;
  224. typedef char char_type;
  225. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  226. };
  227. template< >
  228. struct
  229. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Boost.Filesystem path construction/assignment/appending from containers is deprecated, use strings or iterators instead.")
  230. path_source_traits< std::vector< wchar_t > >
  231. {
  232. // Since C++11 this could be string_class_tag as std::vector gained data() member
  233. typedef range_type_tag tag_type;
  234. typedef wchar_t char_type;
  235. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  236. };
  237. template< >
  238. struct
  239. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Boost.Filesystem path construction/assignment/appending from containers is deprecated, use strings or iterators instead.")
  240. path_source_traits< std::list< char > >
  241. {
  242. typedef range_type_tag tag_type;
  243. typedef char char_type;
  244. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  245. };
  246. template< >
  247. struct
  248. BOOST_FILESYSTEM_DETAIL_DEPRECATED("Boost.Filesystem path construction/assignment/appending from containers is deprecated, use strings or iterators instead.")
  249. path_source_traits< std::list< wchar_t > >
  250. {
  251. typedef range_type_tag tag_type;
  252. typedef wchar_t char_type;
  253. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  254. };
  255. #endif // defined(BOOST_FILESYSTEM_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  256. template< >
  257. struct path_source_traits< directory_entry >
  258. {
  259. typedef directory_entry_tag tag_type;
  260. typedef path_native_char_type char_type;
  261. static BOOST_CONSTEXPR_OR_CONST bool is_native = false;
  262. };
  263. #undef BOOST_FILESYSTEM_DETAIL_IS_CHAR_NATIVE
  264. #undef BOOST_FILESYSTEM_DETAIL_IS_WCHAR_T_NATIVE
  265. //! The trait tests if the type is a known path Source tag
  266. template< typename Tag >
  267. struct is_known_path_source_tag :
  268. public std::true_type
  269. {
  270. };
  271. template< >
  272. struct is_known_path_source_tag< unknown_type_tag > :
  273. public std::false_type
  274. {
  275. };
  276. //! The trait tests if the type is compatible with path Source requirements
  277. template< typename T >
  278. struct is_path_source :
  279. public is_known_path_source_tag< typename path_source_traits< T >::tag_type >::type
  280. {
  281. };
  282. //! The trait indicates whether the type is a path Source that is natively supported by path::string_type as the source for construction/assignment/appending
  283. template< typename T >
  284. struct is_native_path_source :
  285. public std::integral_constant< bool, path_source_traits< T >::is_native >
  286. {
  287. };
  288. //! The trait indicates whether the type is one of the supported path character types
  289. template< typename T >
  290. struct is_path_char_type :
  291. public std::false_type
  292. {
  293. };
  294. template< >
  295. struct is_path_char_type< char > :
  296. public std::true_type
  297. {
  298. };
  299. template< >
  300. struct is_path_char_type< wchar_t > :
  301. public std::true_type
  302. {
  303. };
  304. template< typename Iterator >
  305. struct is_iterator_to_path_chars :
  306. public is_path_char_type< typename std::iterator_traits< Iterator >::value_type >::type
  307. {
  308. };
  309. //! The trait indicates whether the type is an iterator over a sequence of path characters
  310. template< typename Iterator >
  311. struct is_path_source_iterator :
  312. public std::integral_constant<
  313. bool,
  314. detail::conjunction<
  315. boost::iterators::is_iterator< Iterator >,
  316. is_iterator_to_path_chars< Iterator >
  317. >::value
  318. >
  319. {
  320. };
  321. //! The trait indicates whether the type is a pointer to a sequence of native path characters
  322. template< typename T >
  323. struct is_native_char_ptr :
  324. public std::false_type
  325. {
  326. };
  327. template< >
  328. struct is_native_char_ptr< path_native_char_type* > :
  329. public std::true_type
  330. {
  331. };
  332. template< >
  333. struct is_native_char_ptr< const path_native_char_type* > :
  334. public std::true_type
  335. {
  336. };
  337. //! Converts character encoding using the supplied codecvt facet. If \a cvt is \c nullptr then \c path::codecvt() will be used.
  338. BOOST_FILESYSTEM_DECL
  339. void convert(const char* from, const char* from_end, std::wstring& to, const codecvt_type* cvt = nullptr);
  340. //! \overload convert
  341. BOOST_FILESYSTEM_DECL
  342. void convert(const wchar_t* from, const wchar_t* from_end, std::string& to, const codecvt_type* cvt = nullptr);
  343. // Source dispatch -----------------------------------------------------------------//
  344. template< typename Source, typename Callback >
  345. typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt = nullptr);
  346. template< typename Callback >
  347. BOOST_FORCEINLINE typename Callback::result_type dispatch(const char* source, Callback cb, const codecvt_type* cvt, ntcts_type_tag)
  348. {
  349. return cb(source, source + std::strlen(source), cvt);
  350. }
  351. template< typename Callback >
  352. BOOST_FORCEINLINE typename Callback::result_type dispatch(const wchar_t* source, Callback cb, const codecvt_type* cvt, ntcts_type_tag)
  353. {
  354. return cb(source, source + std::wcslen(source), cvt);
  355. }
  356. template< typename Source, typename Callback >
  357. BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt, string_class_tag)
  358. {
  359. return cb(source.data(), source.data() + source.size(), cvt);
  360. }
  361. template< typename Source, typename Callback >
  362. BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
  363. {
  364. std::basic_string< typename Source::value_type > src(source.begin(), source.end());
  365. return cb(src.data(), src.data() + src.size(), cvt);
  366. }
  367. #if defined(BOOST_FILESYSTEM_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  368. template< typename Callback >
  369. BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< char > const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
  370. {
  371. const char* data = nullptr, *data_end = nullptr;
  372. if (!source.empty())
  373. {
  374. data = &source[0];
  375. data_end = data + source.size();
  376. }
  377. return cb(data, data_end, cvt);
  378. }
  379. template< typename Callback >
  380. BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< wchar_t > const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
  381. {
  382. const wchar_t* data = nullptr, *data_end = nullptr;
  383. if (!source.empty())
  384. {
  385. data = &source[0];
  386. data_end = data + source.size();
  387. }
  388. return cb(data, data_end, cvt);
  389. }
  390. #endif // defined(BOOST_FILESYSTEM_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  391. // Defined in directory.hpp to avoid circular header dependencies
  392. template< typename Callback >
  393. typename Callback::result_type dispatch(directory_entry const& de, Callback cb, const codecvt_type* cvt, directory_entry_tag);
  394. template< typename Source, typename Callback >
  395. BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt)
  396. {
  397. return path_traits::dispatch(source, cb, cvt,
  398. typename path_traits::path_source_traits< typename std::remove_cv< Source >::type >::tag_type());
  399. }
  400. typedef char yes_type;
  401. struct no_type { char buf[2]; };
  402. #if !defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  403. namespace is_convertible_to_path_source_impl {
  404. yes_type check_convertible(const char*);
  405. yes_type check_convertible(const wchar_t*);
  406. yes_type check_convertible(std::string const&);
  407. yes_type check_convertible(std::wstring const&);
  408. yes_type check_convertible(boost::container::basic_string< char, std::char_traits< char >, void > const&);
  409. yes_type check_convertible(boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const&);
  410. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  411. yes_type check_convertible(std::string_view const&);
  412. yes_type check_convertible(std::wstring_view const&);
  413. #endif
  414. yes_type check_convertible(boost::basic_string_view< char, std::char_traits< char > > const&);
  415. yes_type check_convertible(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
  416. no_type check_convertible(std::nullptr_t);
  417. no_type check_convertible(...);
  418. } // namespace is_convertible_to_path_source_impl
  419. //! The type trait indicates whether the type has a conversion path to one of the path source types
  420. template< typename T >
  421. struct is_convertible_to_path_source :
  422. public std::integral_constant<
  423. bool,
  424. sizeof(is_convertible_to_path_source_impl::check_convertible(std::declval< T const& >())) == sizeof(yes_type)
  425. >
  426. {
  427. };
  428. #else // !defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  429. // Note: We use separate checks for convertibility to std::string_view and other types to avoid ambiguity with an implicit range constructor
  430. // of std::string_view in the early C++23 draft (N4892). If a user's type is convertible to e.g. std::string and also satisfies
  431. // ranges::contiguous_range and ranges::sized_range concepts then the conversion is ambiguous: the type is convertible to std::string
  432. // through the conversion operator in the user's class and is also convertible to std::string_view through the implicit conversion
  433. // constructor in std::string_view. The solution is to check convertibility to std::string_view separately first.
  434. namespace is_convertible_to_std_string_view_impl {
  435. yes_type check_convertible(std::string_view const&);
  436. yes_type check_convertible(std::wstring_view const&);
  437. no_type check_convertible(std::nullptr_t);
  438. no_type check_convertible(...);
  439. } // namespace is_convertible_to_std_string_view_impl
  440. template< typename T >
  441. struct is_convertible_to_std_string_view :
  442. public std::integral_constant<
  443. bool,
  444. sizeof(is_convertible_to_std_string_view_impl::check_convertible(std::declval< T const& >())) == sizeof(yes_type)
  445. >
  446. {
  447. };
  448. namespace is_convertible_to_path_source_non_std_string_view_impl {
  449. yes_type check_convertible(const char*);
  450. yes_type check_convertible(const wchar_t*);
  451. yes_type check_convertible(std::string const&);
  452. yes_type check_convertible(std::wstring const&);
  453. yes_type check_convertible(boost::container::basic_string< char, std::char_traits< char >, void > const&);
  454. yes_type check_convertible(boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const&);
  455. yes_type check_convertible(boost::basic_string_view< char, std::char_traits< char > > const&);
  456. yes_type check_convertible(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
  457. no_type check_convertible(std::nullptr_t);
  458. no_type check_convertible(...);
  459. } // namespace is_convertible_to_path_source_non_std_string_view_impl
  460. template< typename T >
  461. struct is_convertible_to_path_source_non_std_string_view :
  462. public std::integral_constant<
  463. bool,
  464. sizeof(is_convertible_to_path_source_non_std_string_view_impl::check_convertible(std::declval< T const& >())) == sizeof(yes_type)
  465. >
  466. {
  467. };
  468. //! The type trait indicates whether the type has a conversion path to one of the path source types
  469. template< typename T >
  470. struct is_convertible_to_path_source :
  471. public std::integral_constant<
  472. bool,
  473. detail::disjunction<
  474. is_convertible_to_std_string_view< T >,
  475. is_convertible_to_path_source_non_std_string_view< T >
  476. >::value
  477. >
  478. {
  479. };
  480. #endif // !defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  481. //! The type trait makes \a T dependent on the second template argument. Used to delay type resolution and name binding.
  482. template< typename T, typename >
  483. struct make_dependent
  484. {
  485. typedef T type;
  486. };
  487. template< typename Source, typename Callback >
  488. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(const char* source, Callback cb, const codecvt_type* cvt)
  489. {
  490. typedef typename path_traits::make_dependent< const char*, Source >::type source_t;
  491. return path_traits::dispatch(static_cast< source_t >(source), cb, cvt);
  492. }
  493. template< typename Source, typename Callback >
  494. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(const wchar_t* source, Callback cb, const codecvt_type* cvt)
  495. {
  496. typedef typename path_traits::make_dependent< const wchar_t*, Source >::type source_t;
  497. return path_traits::dispatch(static_cast< source_t >(source), cb, cvt);
  498. }
  499. template< typename Source, typename Callback >
  500. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::string const& source, Callback cb, const codecvt_type* cvt)
  501. {
  502. typedef typename path_traits::make_dependent< std::string, Source >::type source_t;
  503. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  504. }
  505. template< typename Source, typename Callback >
  506. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::wstring const& source, Callback cb, const codecvt_type* cvt)
  507. {
  508. typedef typename path_traits::make_dependent< std::wstring, Source >::type source_t;
  509. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  510. }
  511. template< typename Source, typename Callback >
  512. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  513. (
  514. boost::container::basic_string< char, std::char_traits< char >, void > const& source,
  515. Callback cb,
  516. const codecvt_type* cvt
  517. )
  518. {
  519. typedef typename path_traits::make_dependent< boost::container::basic_string< char, std::char_traits< char >, void >, Source >::type source_t;
  520. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  521. }
  522. template< typename Source, typename Callback >
  523. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  524. (
  525. boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const& source,
  526. Callback cb,
  527. const codecvt_type* cvt
  528. )
  529. {
  530. typedef typename path_traits::make_dependent< boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void >, Source >::type source_t;
  531. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  532. }
  533. template< typename Source, typename Callback >
  534. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  535. (
  536. boost::basic_string_view< char, std::char_traits< char > > const& source,
  537. Callback cb,
  538. const codecvt_type* cvt
  539. )
  540. {
  541. typedef typename path_traits::make_dependent< boost::basic_string_view< char, std::char_traits< char > >, Source >::type source_t;
  542. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  543. }
  544. template< typename Source, typename Callback >
  545. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  546. (
  547. boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const& source,
  548. Callback cb,
  549. const codecvt_type* cvt
  550. )
  551. {
  552. typedef typename path_traits::make_dependent< boost::basic_string_view< wchar_t, std::char_traits< wchar_t > >, Source >::type source_t;
  553. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  554. }
  555. #if !defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  556. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  557. template< typename Source, typename Callback >
  558. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::string_view const& source, Callback cb, const codecvt_type* cvt)
  559. {
  560. typedef typename path_traits::make_dependent< std::string_view, Source >::type source_t;
  561. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  562. }
  563. template< typename Source, typename Callback >
  564. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::wstring_view const& source, Callback cb, const codecvt_type* cvt)
  565. {
  566. typedef typename path_traits::make_dependent< std::wstring_view, Source >::type source_t;
  567. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  568. }
  569. #endif // !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  570. template< typename Source, typename Callback >
  571. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
  572. {
  573. typedef typename std::remove_cv< Source >::type source_t;
  574. return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
  575. }
  576. #else // !defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  577. template< typename Source, typename Callback >
  578. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_sv_impl(std::string_view const& source, Callback cb, const codecvt_type* cvt)
  579. {
  580. typedef typename path_traits::make_dependent< std::string_view, Source >::type source_t;
  581. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  582. }
  583. template< typename Source, typename Callback >
  584. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_sv_impl(std::wstring_view const& source, Callback cb, const codecvt_type* cvt)
  585. {
  586. typedef typename path_traits::make_dependent< std::wstring_view, Source >::type source_t;
  587. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  588. }
  589. template< typename Source, typename Callback >
  590. BOOST_FORCEINLINE typename std::enable_if<
  591. !is_convertible_to_std_string_view< typename std::remove_cv< Source >::type >::value,
  592. typename Callback::result_type
  593. >::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
  594. {
  595. typedef typename std::remove_cv< Source >::type source_t;
  596. return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
  597. }
  598. template< typename Source, typename Callback >
  599. BOOST_FORCEINLINE typename std::enable_if<
  600. is_convertible_to_std_string_view< typename std::remove_cv< Source >::type >::value,
  601. typename Callback::result_type
  602. >::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
  603. {
  604. typedef typename std::remove_cv< Source >::type source_t;
  605. return path_traits::dispatch_convertible_sv_impl< source_t >(source, cb, cvt);
  606. }
  607. #endif // !defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  608. } // namespace path_traits
  609. } // namespace detail
  610. } // namespace filesystem
  611. } // namespace boost
  612. #include <boost/filesystem/detail/footer.hpp>
  613. #endif // BOOST_FILESYSTEM_DETAIL_PATH_TRAITS_HPP