path_traits.hpp 26 KB

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