detail_str.hpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. // Boost.Range library
  2. //
  3. // Copyright Thorsten Ottosen 2003-2004. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_DETAIL_DETAIL_STR_HPP
  11. #define BOOST_RANGE_DETAIL_DETAIL_STR_HPP
  12. #include <boost/config.hpp> // BOOST_MSVC
  13. #include <boost/range/iterator.hpp>
  14. namespace boost
  15. {
  16. namespace range_detail
  17. {
  18. //
  19. // iterator
  20. //
  21. template<>
  22. struct range_iterator_<char_array_>
  23. {
  24. template< typename T >
  25. struct pts
  26. {
  27. typedef BOOST_RANGE_DEDUCED_TYPENAME
  28. remove_extent<T>::type* type;
  29. };
  30. };
  31. template<>
  32. struct range_iterator_<char_ptr_>
  33. {
  34. template< typename S >
  35. struct pts
  36. {
  37. typedef char* type;
  38. };
  39. };
  40. template<>
  41. struct range_iterator_<const_char_ptr_>
  42. {
  43. template< typename S >
  44. struct pts
  45. {
  46. typedef const char* type;
  47. };
  48. };
  49. template<>
  50. struct range_iterator_<wchar_t_ptr_>
  51. {
  52. template< typename S >
  53. struct pts
  54. {
  55. typedef wchar_t* type;
  56. };
  57. };
  58. template<>
  59. struct range_iterator_<const_wchar_t_ptr_>
  60. {
  61. template< typename S >
  62. struct pts
  63. {
  64. typedef const wchar_t* type;
  65. };
  66. };
  67. //
  68. // const iterator
  69. //
  70. template<>
  71. struct range_const_iterator_<char_array_>
  72. {
  73. template< typename T >
  74. struct pts
  75. {
  76. typedef const BOOST_RANGE_DEDUCED_TYPENAME
  77. remove_extent<T>::type* type;
  78. };
  79. };
  80. template<>
  81. struct range_const_iterator_<char_ptr_>
  82. {
  83. template< typename S >
  84. struct pts
  85. {
  86. typedef const char* type;
  87. };
  88. };
  89. template<>
  90. struct range_const_iterator_<const_char_ptr_>
  91. {
  92. template< typename S >
  93. struct pts
  94. {
  95. typedef const char* type;
  96. };
  97. };
  98. template<>
  99. struct range_const_iterator_<wchar_t_ptr_>
  100. {
  101. template< typename S >
  102. struct pts
  103. {
  104. typedef const wchar_t* type;
  105. };
  106. };
  107. template<>
  108. struct range_const_iterator_<const_wchar_t_ptr_>
  109. {
  110. template< typename S >
  111. struct pts
  112. {
  113. typedef const wchar_t* type;
  114. };
  115. };
  116. }
  117. }
  118. #include <boost/range/detail/begin.hpp>
  119. #include <boost/range/detail/end.hpp>
  120. #include <boost/range/detail/size_type.hpp>
  121. #include <boost/range/detail/value_type.hpp>
  122. #include <boost/range/detail/common.hpp>
  123. namespace boost
  124. {
  125. namespace range_detail
  126. {
  127. //
  128. // str_begin()
  129. //
  130. template<>
  131. struct range_begin<char_ptr_>
  132. {
  133. static char* fun( char* s )
  134. {
  135. return s;
  136. }
  137. };
  138. template<>
  139. struct range_begin<const_char_ptr_>
  140. {
  141. static const char* fun( const char* s )
  142. {
  143. return s;
  144. }
  145. };
  146. template<>
  147. struct range_begin<wchar_t_ptr_>
  148. {
  149. static wchar_t* fun( wchar_t* s )
  150. {
  151. return s;
  152. }
  153. };
  154. template<>
  155. struct range_begin<const_wchar_t_ptr_>
  156. {
  157. static const wchar_t* fun( const wchar_t* s )
  158. {
  159. return s;
  160. }
  161. };
  162. template< typename C >
  163. inline BOOST_RANGE_DEDUCED_TYPENAME range_iterator<C>::type
  164. str_begin( C& c )
  165. {
  166. return range_detail::range_begin< BOOST_RANGE_DEDUCED_TYPENAME
  167. range_detail::range<C>::type >::fun( c );
  168. }
  169. //
  170. // str_end()
  171. //
  172. template<>
  173. struct range_end<char_array_>
  174. {
  175. template< typename T, std::size_t sz >
  176. static T* fun( T BOOST_RANGE_ARRAY_REF()[sz] )
  177. {
  178. return boost::range_detail::array_end( boost_range_array );
  179. }
  180. };
  181. template<>
  182. struct range_end<wchar_t_array_>
  183. {
  184. template< typename T, std::size_t sz >
  185. static T* fun( T BOOST_RANGE_ARRAY_REF()[sz] )
  186. {
  187. return boost::range_detail::array_end( boost_range_array );
  188. }
  189. };
  190. template<>
  191. struct range_end<char_ptr_>
  192. {
  193. static char* fun( char* s )
  194. {
  195. return boost::range_detail::str_end( s );
  196. }
  197. };
  198. template<>
  199. struct range_end<const_char_ptr_>
  200. {
  201. static const char* fun( const char* s )
  202. {
  203. return boost::range_detail::str_end( s );
  204. }
  205. };
  206. template<>
  207. struct range_end<wchar_t_ptr_>
  208. {
  209. static wchar_t* fun( wchar_t* s )
  210. {
  211. return boost::range_detail::str_end( s );
  212. }
  213. };
  214. template<>
  215. struct range_end<const_wchar_t_ptr_>
  216. {
  217. static const wchar_t* fun( const wchar_t* s )
  218. {
  219. return boost::range_detail::str_end( s );
  220. }
  221. };
  222. template< typename C >
  223. inline BOOST_RANGE_DEDUCED_TYPENAME range_iterator<C>::type
  224. str_end( C& c )
  225. {
  226. return range_detail::range_end< BOOST_RANGE_DEDUCED_TYPENAME
  227. range_detail::range<C>::type >::fun( c );
  228. }
  229. //
  230. // size_type
  231. //
  232. template<>
  233. struct range_size_type_<char_array_>
  234. {
  235. template< typename A >
  236. struct pts
  237. {
  238. typedef std::size_t type;
  239. };
  240. };
  241. template<>
  242. struct range_size_type_<char_ptr_>
  243. {
  244. template< typename S >
  245. struct pts
  246. {
  247. typedef std::size_t type;
  248. };
  249. };
  250. template<>
  251. struct range_size_type_<const_char_ptr_>
  252. {
  253. template< typename S >
  254. struct pts
  255. {
  256. typedef std::size_t type;
  257. };
  258. };
  259. template<>
  260. struct range_size_type_<wchar_t_ptr_>
  261. {
  262. template< typename S >
  263. struct pts
  264. {
  265. typedef std::size_t type;
  266. };
  267. };
  268. template<>
  269. struct range_size_type_<const_wchar_t_ptr_>
  270. {
  271. template< typename S >
  272. struct pts
  273. {
  274. typedef std::size_t type;
  275. };
  276. };
  277. //
  278. // value_type
  279. //
  280. template<>
  281. struct range_value_type_<char_array_>
  282. {
  283. template< typename T >
  284. struct pts
  285. {
  286. typedef char type;
  287. };
  288. };
  289. template<>
  290. struct range_value_type_<char_ptr_>
  291. {
  292. template< typename S >
  293. struct pts
  294. {
  295. typedef char type;
  296. };
  297. };
  298. template<>
  299. struct range_value_type_<const_char_ptr_>
  300. {
  301. template< typename S >
  302. struct pts
  303. {
  304. typedef const char type;
  305. };
  306. };
  307. template<>
  308. struct range_value_type_<wchar_t_ptr_>
  309. {
  310. template< typename S >
  311. struct pts
  312. {
  313. typedef wchar_t type;
  314. };
  315. };
  316. template<>
  317. struct range_value_type_<const_wchar_t_ptr_>
  318. {
  319. template< typename S >
  320. struct pts
  321. {
  322. typedef const wchar_t type;
  323. };
  324. };
  325. } // namespace 'range_detail'
  326. } // namespace 'boost'
  327. #endif