path_traits.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. // filesystem path_traits.hpp --------------------------------------------------------//
  2. // Copyright Beman Dawes 2009
  3. // Copyright Andrey Semashev 2022
  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. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  17. #include <string_view>
  18. #endif
  19. #include <boost/assert.hpp>
  20. #include <boost/system/error_category.hpp>
  21. #include <boost/type_traits/declval.hpp>
  22. #include <boost/type_traits/remove_cv.hpp>
  23. #if defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  24. #include <boost/type_traits/disjunction.hpp>
  25. #include <boost/core/enable_if.hpp>
  26. #endif
  27. #if !defined(BOOST_FILESYSTEM_NO_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() BOOST_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_NO_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_NO_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. {
  269. static BOOST_CONSTEXPR_OR_CONST bool value = true;
  270. };
  271. template< >
  272. struct is_known_path_source_tag< unknown_type_tag >
  273. {
  274. static BOOST_CONSTEXPR_OR_CONST bool value = false;
  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 >
  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. {
  286. static BOOST_CONSTEXPR_OR_CONST bool value = path_source_traits< T >::is_native;
  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. {
  292. static BOOST_CONSTEXPR_OR_CONST bool value = false;
  293. };
  294. template< >
  295. struct is_path_char_type< char >
  296. {
  297. static BOOST_CONSTEXPR_OR_CONST bool value = true;
  298. };
  299. template< >
  300. struct is_path_char_type< wchar_t >
  301. {
  302. static BOOST_CONSTEXPR_OR_CONST bool value = true;
  303. };
  304. //! The trait indicates whether the type is an iterator over a sequence of path characters
  305. template< typename Iterator >
  306. struct is_path_source_iterator :
  307. public is_path_char_type< typename std::iterator_traits< Iterator >::value_type >
  308. {
  309. };
  310. //! The trait indicates whether the type is a pointer to a sequence of native path characters
  311. template< typename T >
  312. struct is_native_char_ptr
  313. {
  314. static BOOST_CONSTEXPR_OR_CONST bool value = false;
  315. };
  316. template< >
  317. struct is_native_char_ptr< path_native_char_type* >
  318. {
  319. static BOOST_CONSTEXPR_OR_CONST bool value = true;
  320. };
  321. template< >
  322. struct is_native_char_ptr< const path_native_char_type* >
  323. {
  324. static BOOST_CONSTEXPR_OR_CONST bool value = true;
  325. };
  326. //! Converts character encoding using the supplied codecvt facet. If \a cvt is \c NULL then \c path::codecvt() will be used.
  327. BOOST_FILESYSTEM_DECL
  328. void convert(const char* from, const char* from_end, std::wstring& to, const codecvt_type* cvt = NULL);
  329. //! \overload convert
  330. BOOST_FILESYSTEM_DECL
  331. void convert(const wchar_t* from, const wchar_t* from_end, std::string& to, const codecvt_type* cvt = NULL);
  332. // Source dispatch -----------------------------------------------------------------//
  333. template< typename Source, typename Callback >
  334. typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt = NULL);
  335. template< typename Callback >
  336. BOOST_FORCEINLINE typename Callback::result_type dispatch(const char* source, Callback cb, const codecvt_type* cvt, ntcts_type_tag)
  337. {
  338. return cb(source, source + std::strlen(source), cvt);
  339. }
  340. template< typename Callback >
  341. BOOST_FORCEINLINE typename Callback::result_type dispatch(const wchar_t* source, Callback cb, const codecvt_type* cvt, ntcts_type_tag)
  342. {
  343. return cb(source, source + std::wcslen(source), cvt);
  344. }
  345. template< typename Source, typename Callback >
  346. BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt, string_class_tag)
  347. {
  348. return cb(source.data(), source.data() + source.size(), cvt);
  349. }
  350. template< typename Source, typename Callback >
  351. BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
  352. {
  353. std::basic_string< typename Source::value_type > src(source.begin(), source.end());
  354. return cb(src.data(), src.data() + src.size(), cvt);
  355. }
  356. #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  357. template< typename Callback >
  358. BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< char > const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
  359. {
  360. const char* data = NULL, *data_end = NULL;
  361. if (!source.empty())
  362. {
  363. data = &source[0];
  364. data_end = data + source.size();
  365. }
  366. return cb(data, data_end, cvt);
  367. }
  368. template< typename Callback >
  369. BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< wchar_t > const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
  370. {
  371. const wchar_t* data = NULL, *data_end = NULL;
  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. #endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
  380. // Defined in directory.hpp to avoid circular header dependencies
  381. template< typename Callback >
  382. typename Callback::result_type dispatch(directory_entry const& de, Callback cb, const codecvt_type* cvt, directory_entry_tag);
  383. template< typename Source, typename Callback >
  384. BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt)
  385. {
  386. return path_traits::dispatch(source, cb, cvt,
  387. typename path_traits::path_source_traits< typename boost::remove_cv< Source >::type >::tag_type());
  388. }
  389. typedef char yes_type;
  390. struct no_type { char buf[2]; };
  391. // Note: The obscure naming of the _check* functions below is a workaround for an MSVC-9.0 bug, which looks up the function outside the class scope
  392. #if !defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  393. //! The type trait indicates whether the type has a conversion path to one of the path source types
  394. template< typename T >
  395. struct is_convertible_to_path_source
  396. {
  397. // Note: The obscure naming of this function is a workaround for an MSVC-9.0 bug, which looks up the function outside the class scope
  398. static yes_type _check_convertible_to_path_source(const char*);
  399. static yes_type _check_convertible_to_path_source(const wchar_t*);
  400. static yes_type _check_convertible_to_path_source(std::string const&);
  401. static yes_type _check_convertible_to_path_source(std::wstring const&);
  402. static yes_type _check_convertible_to_path_source(boost::container::basic_string< char, std::char_traits< char >, void > const&);
  403. static yes_type _check_convertible_to_path_source(boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const&);
  404. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  405. static yes_type _check_convertible_to_path_source(std::string_view const&);
  406. static yes_type _check_convertible_to_path_source(std::wstring_view const&);
  407. #endif
  408. static yes_type _check_convertible_to_path_source(boost::basic_string_view< char, std::char_traits< char > > const&);
  409. static yes_type _check_convertible_to_path_source(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
  410. #if !defined(BOOST_NO_CXX11_NULLPTR)
  411. static no_type _check_convertible_to_path_source(std::nullptr_t);
  412. #endif
  413. static no_type _check_convertible_to_path_source(...);
  414. static BOOST_CONSTEXPR_OR_CONST bool value =
  415. sizeof(is_convertible_to_path_source< T >::_check_convertible_to_path_source(boost::declval< T const& >())) == sizeof(yes_type);
  416. };
  417. #else // !defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  418. // Note: We use separate checks for convertibility to std::string_view and other types to avoid ambiguity with an implicit range constructor
  419. // 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
  420. // ranges::contiguous_range and ranges::sized_range concepts then the conversion is ambiguous: the type is convertible to std::string
  421. // through the conversion operator in the user's class and is also convertible to std::string_view through the implicit conversion
  422. // constructor in std::string_view. The solution is to check convertibility to std::string_view separately first.
  423. template< typename T >
  424. struct is_convertible_to_std_string_view
  425. {
  426. static yes_type _check_convertible_to_std_string_view(std::string_view const&);
  427. static yes_type _check_convertible_to_std_string_view(std::wstring_view const&);
  428. #if !defined(BOOST_NO_CXX11_NULLPTR)
  429. static no_type _check_convertible_to_std_string_view(std::nullptr_t);
  430. #endif
  431. static no_type _check_convertible_to_std_string_view(...);
  432. static BOOST_CONSTEXPR_OR_CONST bool value =
  433. sizeof(is_convertible_to_std_string_view< T >::_check_convertible_to_std_string_view(boost::declval< T const& >())) == sizeof(yes_type);
  434. };
  435. template< typename T >
  436. struct is_convertible_to_path_source_non_std_string_view
  437. {
  438. // Note: The obscure naming of this function is a workaround for an MSVC-9.0 bug, which looks up the function outside the class scope
  439. static yes_type _check_convertible_to_path_source(const char*);
  440. static yes_type _check_convertible_to_path_source(const wchar_t*);
  441. static yes_type _check_convertible_to_path_source(std::string const&);
  442. static yes_type _check_convertible_to_path_source(std::wstring const&);
  443. static yes_type _check_convertible_to_path_source(boost::container::basic_string< char, std::char_traits< char >, void > const&);
  444. static yes_type _check_convertible_to_path_source(boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const&);
  445. static yes_type _check_convertible_to_path_source(boost::basic_string_view< char, std::char_traits< char > > const&);
  446. static yes_type _check_convertible_to_path_source(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
  447. #if !defined(BOOST_NO_CXX11_NULLPTR)
  448. static no_type _check_convertible_to_path_source(std::nullptr_t);
  449. #endif
  450. static no_type _check_convertible_to_path_source(...);
  451. static BOOST_CONSTEXPR_OR_CONST bool value =
  452. sizeof(is_convertible_to_path_source_non_std_string_view< T >::_check_convertible_to_path_source(boost::declval< T const& >())) == sizeof(yes_type);
  453. };
  454. //! The type trait indicates whether the type has a conversion path to one of the path source types
  455. template< typename T >
  456. struct is_convertible_to_path_source :
  457. public boost::disjunction<
  458. is_convertible_to_std_string_view< T >,
  459. is_convertible_to_path_source_non_std_string_view< T >
  460. >
  461. {
  462. };
  463. #endif // !defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  464. //! The type trait makes \a T dependent on the second template argument. Used to delay type resolution and name binding.
  465. template< typename T, typename >
  466. struct make_dependent
  467. {
  468. typedef T type;
  469. };
  470. template< typename Source, typename Callback >
  471. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(const char* source, Callback cb, const codecvt_type* cvt)
  472. {
  473. typedef typename path_traits::make_dependent< const char*, Source >::type source_t;
  474. return path_traits::dispatch(static_cast< source_t >(source), cb, cvt);
  475. }
  476. template< typename Source, typename Callback >
  477. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(const wchar_t* source, Callback cb, const codecvt_type* cvt)
  478. {
  479. typedef typename path_traits::make_dependent< const wchar_t*, Source >::type source_t;
  480. return path_traits::dispatch(static_cast< source_t >(source), cb, cvt);
  481. }
  482. template< typename Source, typename Callback >
  483. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::string const& source, Callback cb, const codecvt_type* cvt)
  484. {
  485. typedef typename path_traits::make_dependent< std::string, Source >::type source_t;
  486. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  487. }
  488. template< typename Source, typename Callback >
  489. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::wstring const& source, Callback cb, const codecvt_type* cvt)
  490. {
  491. typedef typename path_traits::make_dependent< std::wstring, Source >::type source_t;
  492. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  493. }
  494. template< typename Source, typename Callback >
  495. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  496. (
  497. boost::container::basic_string< char, std::char_traits< char >, void > const& source,
  498. Callback cb,
  499. const codecvt_type* cvt
  500. )
  501. {
  502. typedef typename path_traits::make_dependent< boost::container::basic_string< char, std::char_traits< char >, void >, 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
  507. (
  508. boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const& source,
  509. Callback cb,
  510. const codecvt_type* cvt
  511. )
  512. {
  513. typedef typename path_traits::make_dependent< boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void >, Source >::type source_t;
  514. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  515. }
  516. template< typename Source, typename Callback >
  517. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  518. (
  519. boost::basic_string_view< char, std::char_traits< char > > const& source,
  520. Callback cb,
  521. const codecvt_type* cvt
  522. )
  523. {
  524. typedef typename path_traits::make_dependent< boost::basic_string_view< char, std::char_traits< char > >, Source >::type source_t;
  525. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  526. }
  527. template< typename Source, typename Callback >
  528. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl
  529. (
  530. boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const& source,
  531. Callback cb,
  532. const codecvt_type* cvt
  533. )
  534. {
  535. typedef typename path_traits::make_dependent< boost::basic_string_view< wchar_t, std::char_traits< wchar_t > >, Source >::type source_t;
  536. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  537. }
  538. #if !defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  539. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  540. template< typename Source, typename Callback >
  541. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::string_view const& source, Callback cb, const codecvt_type* cvt)
  542. {
  543. typedef typename path_traits::make_dependent< std::string_view, Source >::type source_t;
  544. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  545. }
  546. template< typename Source, typename Callback >
  547. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::wstring_view const& source, Callback cb, const codecvt_type* cvt)
  548. {
  549. typedef typename path_traits::make_dependent< std::wstring_view, Source >::type source_t;
  550. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  551. }
  552. #endif // !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  553. template< typename Source, typename Callback >
  554. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = NULL)
  555. {
  556. typedef typename boost::remove_cv< Source >::type source_t;
  557. return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
  558. }
  559. #else // !defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  560. template< typename Source, typename Callback >
  561. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_sv_impl(std::string_view const& source, Callback cb, const codecvt_type* cvt)
  562. {
  563. typedef typename path_traits::make_dependent< std::string_view, Source >::type source_t;
  564. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  565. }
  566. template< typename Source, typename Callback >
  567. BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_sv_impl(std::wstring_view const& source, Callback cb, const codecvt_type* cvt)
  568. {
  569. typedef typename path_traits::make_dependent< std::wstring_view, Source >::type source_t;
  570. return path_traits::dispatch(static_cast< source_t const& >(source), cb, cvt);
  571. }
  572. template< typename Source, typename Callback >
  573. BOOST_FORCEINLINE typename boost::disable_if_c<
  574. is_convertible_to_std_string_view< typename boost::remove_cv< Source >::type >::value,
  575. typename Callback::result_type
  576. >::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = NULL)
  577. {
  578. typedef typename boost::remove_cv< Source >::type source_t;
  579. return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
  580. }
  581. template< typename Source, typename Callback >
  582. BOOST_FORCEINLINE typename boost::enable_if_c<
  583. is_convertible_to_std_string_view< typename boost::remove_cv< Source >::type >::value,
  584. typename Callback::result_type
  585. >::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = NULL)
  586. {
  587. typedef typename boost::remove_cv< Source >::type source_t;
  588. return path_traits::dispatch_convertible_sv_impl< source_t >(source, cb, cvt);
  589. }
  590. #endif // !defined(BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
  591. } // namespace path_traits
  592. } // namespace detail
  593. } // namespace filesystem
  594. } // namespace boost
  595. #include <boost/filesystem/detail/footer.hpp>
  596. #endif // BOOST_FILESYSTEM_DETAIL_PATH_TRAITS_HPP