support.qbk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2006 Dan Marsden
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ===============================================================================/]
  8. [section Support]
  9. A couple of classes and metafunctions provide basic support for Fusion.
  10. [section is_sequence]
  11. [heading Description]
  12. Metafunction that evaluates to `mpl::true_` if a certain type `T` is a
  13. conforming Fusion __sequence__, `mpl::false_` otherwise. This may be
  14. specialized to accommodate clients which provide Fusion conforming sequences.
  15. [heading Synopsis]
  16. namespace traits
  17. {
  18. template <typename T>
  19. struct is_sequence
  20. {
  21. typedef __unspecified__ type;
  22. };
  23. }
  24. [heading Parameters]
  25. [table
  26. [[Parameter] [Requirement] [Description]]
  27. [[`T`] [Any type] [The type to query.]]
  28. ]
  29. [heading Expression Semantics]
  30. typedef traits::is_sequence<T>::type c;
  31. [*Return type]: An __mpl_boolean_constant__.
  32. [*Semantics]: Metafunction that evaluates to `mpl::true_` if a certain type
  33. `T` is a conforming Fusion sequence, `mpl::false_` otherwise.
  34. [heading Header]
  35. #include <boost/fusion/support/is_sequence.hpp>
  36. #include <boost/fusion/include/is_sequence.hpp>
  37. [heading Example]
  38. BOOST_MPL_ASSERT_NOT(( traits::is_sequence< std::vector<int> > ));
  39. BOOST_MPL_ASSERT_NOT(( is_sequence< int > ));
  40. BOOST_MPL_ASSERT(( traits::is_sequence<__list__<> > ));
  41. BOOST_MPL_ASSERT(( traits::is_sequence<__list__<int> > ));
  42. BOOST_MPL_ASSERT(( traits::is_sequence<__vector__<> > ));
  43. BOOST_MPL_ASSERT(( traits::is_sequence<__vector__<int> > ));
  44. [endsect]
  45. [section is_view]
  46. [heading Description]
  47. Metafunction that evaluates to `mpl::true_` if a certain type `T` is a
  48. conforming Fusion __view__, `mpl::false_` otherwise. A view is a
  49. specialized sequence that does not actually contain data. Views hold
  50. sequences which may be other views. In general, views are held by other
  51. views by value, while non-views are held by other views by reference. `is_view`
  52. may be specialized to accommodate clients providing Fusion conforming views.
  53. [heading Synopsis]
  54. namespace traits
  55. {
  56. template <typename T>
  57. struct is_view
  58. {
  59. typedef __unspecified__ type;
  60. };
  61. }
  62. [heading Parameters]
  63. [table
  64. [[Parameter] [Requirement] [Description]]
  65. [[`T`] [Any type] [The type to query.]]
  66. ]
  67. [heading Expression Semantics]
  68. typedef traits::is_view<T>::type c;
  69. [*Return type]: An __mpl_boolean_constant__.
  70. [*Semantics]: Metafunction that evaluates to `mpl::true_` if a certain type
  71. `T` is a conforming Fusion view, `mpl::false_` otherwise.
  72. [heading Header]
  73. #include <boost/fusion/support/is_view.hpp>
  74. #include <boost/fusion/include/is_view.hpp>
  75. [heading Example]
  76. BOOST_MPL_ASSERT_NOT(( traits::is_view<std::vector<int> > ));
  77. BOOST_MPL_ASSERT_NOT(( traits::is_view<int> ));
  78. using boost::mpl::_
  79. using boost::is_pointer;
  80. typedef __vector__<int*, char, long*, bool, double> vector_type;
  81. typedef __filter_view__<vector_type, is_pointer<_> > filter_view_type;
  82. BOOST_MPL_ASSERT(( traits::is_view<filter_view_type> ));
  83. [endsect]
  84. [section tag_of]
  85. [heading Description]
  86. All conforming Fusion sequences and iterators have an associated tag type. The
  87. purpose of the tag is to enable __tag_dispatching__ from __intrinsic__
  88. functions to implementations appropriate for the type.
  89. This metafunction may be specialized to accommodate clients providing Fusion
  90. conforming sequences.
  91. [heading Synopsis]
  92. namespace traits
  93. {
  94. template<typename Sequence>
  95. struct tag_of
  96. {
  97. typedef __unspecified__ type;
  98. };
  99. }
  100. [heading Parameters]
  101. [table
  102. [[Parameter] [Requirement] [Description]]
  103. [[`T`] [Any type] [The type to query.]]
  104. ]
  105. [heading Expression Semantics]
  106. typedef traits::tag_of<T>::type tag;
  107. [*Return type]: Any type.
  108. [*Semantics]: Returns the tag type associated with `T`.
  109. [heading Header]
  110. #include <boost/fusion/support/tag_of.hpp>
  111. #include <boost/fusion/include/tag_of.hpp>
  112. [heading Example]
  113. typedef traits::tag_of<__list__<> >::type tag1;
  114. typedef traits::tag_of<__list__<int> >::type tag2;
  115. typedef traits::tag_of<__vector__<> >::type tag3;
  116. typedef traits::tag_of<__vector__<int> >::type tag4;
  117. BOOST_MPL_ASSERT((boost::is_same<tag1, tag2>));
  118. BOOST_MPL_ASSERT((boost::is_same<tag3, tag4>));
  119. [endsect]
  120. [section category_of]
  121. [heading Description]
  122. A metafunction that establishes the conceptual classification of a particular
  123. __sequence__ or __iterator__ (see __iterator_concepts__ and
  124. __sequence_concepts__).
  125. [heading Synopsis]
  126. namespace traits
  127. {
  128. template <typename T>
  129. struct category_of
  130. {
  131. typedef __unspecified__ type;
  132. };
  133. }
  134. [heading Parameters]
  135. [table
  136. [[Parameter] [Requirement] [Description]]
  137. [[`T`] [Any type] [The type to query.]]
  138. ]
  139. [heading Expression Semantics]
  140. typedef traits::category_of<T>::type category;
  141. [*Return type]:
  142. The return type is derived from one of:
  143. namespace boost { namespace fusion
  144. {
  145. struct incrementable_traversal_tag {};
  146. struct single_pass_traversal_tag
  147. : incrementable_traversal_tag {};
  148. struct forward_traversal_tag
  149. : single_pass_traversal_tag {};
  150. struct bidirectional_traversal_tag
  151. : forward_traversal_tag {};
  152. struct random_access_traversal_tag
  153. : bidirectional_traversal_tag {};
  154. }}
  155. And optionally from:
  156. namespace boost { namespace fusion
  157. {
  158. struct associative_tag {};
  159. struct unbounded_tag {};
  160. }}
  161. [*Semantics]: Establishes the conceptual classification of a particular
  162. __sequence__ or __iterator__.
  163. [heading Header]
  164. #include <boost/fusion/support/category_of.hpp>
  165. #include <boost/fusion/include/category_of.hpp>
  166. [heading Example]
  167. using boost::is_base_of;
  168. typedef traits::category_of<__list__<> >::type list_category;
  169. typedef traits::category_of<__vector__<> >::type vector_category;
  170. BOOST_MPL_ASSERT(( is_base_of<forward_traversal_tag, list_category> ));
  171. BOOST_MPL_ASSERT(( is_base_of<random_access_traversal_tag, vector_category> ));
  172. [endsect]
  173. [section deduce]
  174. [heading Description]
  175. Metafunction to apply __element_conversion__ to the full argument type.
  176. It removes references to `const`, references to array types are kept, even
  177. if the array is `const`. Reference wrappers are removed (see
  178. __note_ref_wrappers__)[footnote Since C++11, the standard reference wrappers
  179. are also removed.].
  180. [heading Header]
  181. #include <boost/fusion/support/deduce.hpp>
  182. #include <boost/fusion/include/deduce.hpp>
  183. [heading Synopsis]
  184. namespace traits
  185. {
  186. template <typename T>
  187. struct deduce
  188. {
  189. typedef __unspecified__ type;
  190. };
  191. }
  192. [heading Example]
  193. template <typename T>
  194. struct holder
  195. {
  196. typename traits::deduce<T const &>::type element;
  197. holder(T const & a)
  198. : element(a)
  199. { }
  200. };
  201. template <typename T>
  202. holder<T> make_holder(T const & a)
  203. {
  204. return holder<T>(a);
  205. }
  206. [heading See also]
  207. * __deduce_sequence__
  208. [endsect]
  209. [section deduce_sequence]
  210. [heading Description]
  211. Applies __element_conversion__ to each element in a __forward_sequence__.
  212. The resulting type is a __random_access_sequence__ that provides a converting
  213. constructor accepting the original type as its argument.
  214. [heading Header]
  215. #include <boost/fusion/support/deduce_sequence.hpp>
  216. #include <boost/fusion/include/deduce_sequence.hpp>
  217. [heading Synopsis]
  218. namespace traits
  219. {
  220. template <class Sequence>
  221. struct deduce_sequence
  222. {
  223. typedef __unspecified__ type;
  224. };
  225. }
  226. [heading Example]
  227. template <class Seq>
  228. struct holder
  229. {
  230. typename traits::deduce_sequence<Seq>::type element;
  231. holder(Seq const & a)
  232. : element(a)
  233. { }
  234. };
  235. template <typename T0, typename T1>
  236. holder< __vector__<T0 const &, T1 const &> >
  237. make_holder(T0 const & a0, T1 const & a1)
  238. {
  239. typedef __vector__<T0 const &, T1 const &> arg_vec_t;
  240. return holder<arg_vec_t>( arg_vec_t(a0,a1) );
  241. }
  242. [heading See also]
  243. * __deduce__
  244. [endsect]
  245. [section pair]
  246. [heading Description]
  247. Fusion `pair` type is a half runtime pair. A half runtime pair is similar
  248. to a __std_pair__, but, unlike __std_pair__, the first type does not have data.
  249. It is used as elements in __map__\ s, for example.
  250. [heading Synopsis]
  251. template <typename First, typename Second>
  252. struct pair;
  253. namespace result_of
  254. {
  255. template <typename Pair>
  256. struct first;
  257. template <typename Pair>
  258. struct second;
  259. template <typename First, typename Second>
  260. struct make_pair;
  261. }
  262. template <typename First, typename Second>
  263. typename result_of::make_pair<First,Second>::type
  264. make_pair(Second const &);
  265. [heading Template parameters]
  266. [table
  267. [[Parameter] [Description]]
  268. [[First] [The first type. This is purely a type. No data is held.]]
  269. [[Second] [The second type. This contains data.]]
  270. ]
  271. [variablelist Notation
  272. [[`P`] [Fusion pair type]]
  273. [[`p`, `p2`] [Fusion pairs]]
  274. [[`F`, `S`] [Arbitrary types]]
  275. [[`s`] [Value of type `S`]]
  276. [[`o`] [Output stream]]
  277. [[`i`] [Input stream]]
  278. ]
  279. [heading Expression Semantics]
  280. [table
  281. [[Expression] [Semantics]]
  282. [[`P::first_type`] [The type of the first template parameter, `F`, equivalent to
  283. `result_of::first<P>::type`. ]]
  284. [[`P::second_type`] [The type of the second template parameter, `S`, equivalent to
  285. `result_of::second<P>::type`. ]]
  286. [[`P()`] [Default construction.]]
  287. [[`P(s)`] [Construct a pair given value for the second type, `s`.]]
  288. [[`P(p2)`] [Copy constructs a pair from another pair, `p2`.]]
  289. [[`p.second`] [Get the data from `p1`.]]
  290. [[`p = p2`] [Assigns a pair, `p1`, from another pair, `p2`.]]
  291. [[make_pair<F>(s)] [Make a pair given the first type, `F`, and a value for
  292. the second type, `s`. The second type assumes the type of `s`]]
  293. [[`o << p`] [Output `p` to output stream, `o`.]]
  294. [[`i >> p`] [Input `p` from input stream, `i`.]]
  295. [[`p == p2`] [Tests two pairs for equality.]]
  296. [[`p != p2`] [Tests two pairs for inequality.]]
  297. ]
  298. [heading Header]
  299. #include <boost/fusion/support/pair.hpp>
  300. #include <boost/fusion/include/pair.hpp>
  301. [heading Example]
  302. pair<int, char> p('X');
  303. std::cout << p << std::endl;
  304. std::cout << make_pair<int>('X') << std::endl;
  305. assert((p == make_pair<int>('X')));
  306. [endsect]
  307. [endsect]