adapted.qbk 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2006 Dan Marsden
  4. Copyright (C) 2010 Christopher Schmidt
  5. Use, modification and distribution is subject to the Boost Software
  6. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. ===============================================================================/]
  9. [section Adapted]
  10. Fusion provides a couple of adapters for other sequences such as arrays,
  11. `std::pair`, __mpl__ sequences, and `boost::array`. These adapters are
  12. written using Fusion's non-intrusive __extension__ mechanism. If you wish
  13. to use these sequences with fusion, simply include the necessary files and
  14. they will be regarded as first-class, fully conforming fusion sequences.
  15. Fusion also provides various schemes to make it easy for the user to adapt
  16. various data structures, non-intrusively, as full fledged Fusion sequences.
  17. [heading Header]
  18. #include <boost/fusion/adapted.hpp>
  19. #include <boost/fusion/include/adapted.hpp>
  20. [section:array Array]
  21. This module provides adapters for arrays. Including the module
  22. header makes any array a fully conforming __random_access_sequence__.
  23. [heading Header]
  24. #include <boost/fusion/adapted/array.hpp>
  25. #include <boost/fusion/include/array.hpp>
  26. [heading Model of]
  27. * __random_access_sequence__
  28. [heading Example]
  29. int arr[3] = {1,2,3};
  30. std::cout << *__begin__(arr) << std::endl;
  31. std::cout << *__next__(__begin__(arr)) << std::endl;
  32. std::cout << *__advance_c__<2>(__begin__(arr)) << std::endl;
  33. std::cout << *__prior__(__end__(arr)) << std::endl;
  34. std::cout << __at_c__<2>(arr) << std::endl;
  35. [endsect]
  36. [section std::pair]
  37. This module provides adapters for `std::pair`. Including the module header
  38. makes `std::pair` a fully conforming __random_access_sequence__.
  39. [heading Header]
  40. #include <boost/fusion/adapted/std_pair.hpp>
  41. #include <boost/fusion/include/std_pair.hpp>
  42. [heading Model of]
  43. * __random_access_sequence__
  44. [heading Example]
  45. std::pair<int, std::string> p(123, "Hola!!!");
  46. std::cout << __at_c__<0>(p) << std::endl;
  47. std::cout << __at_c__<1>(p) << std::endl;
  48. std::cout << p << std::endl;
  49. [heading See also]
  50. __std_pair_doc__, __tr1_tuple_pair__
  51. [endsect]
  52. [section std::tuple]
  53. This module provides adapters for `std::tuple`. Including the module header
  54. makes `std::tuple` a fully conforming __random_access_sequence__.
  55. [important To be fully conforming, compiler should support C++11 Variadic Templates.]
  56. [heading Header]
  57. #include <boost/fusion/adapted/std_tuple.hpp>
  58. #include <boost/fusion/include/std_tuple.hpp>
  59. [heading Model of]
  60. * __random_access_sequence__
  61. [heading Example]
  62. std::tuple<int, std::string, float> p(123, "Hola!!!", 456.f);
  63. std::cout << __at_c__<0>(p) << std::endl;
  64. std::cout << __at_c__<1>(p) << std::endl;
  65. std::cout << p << std::endl;
  66. [heading See also]
  67. __std_tuple_doc__
  68. [endsect]
  69. [section mpl sequence]
  70. This module provides adapters for __mpl__ sequences. Including the module
  71. header makes all __mpl__ sequences fully conforming fusion sequences.
  72. [heading Header]
  73. #include <boost/fusion/adapted/mpl.hpp>
  74. #include <boost/fusion/include/mpl.hpp>
  75. [heading Model of]
  76. * __forward_sequence__ (If the __mpl__ sequence is a forward sequence.)
  77. * __bidirectional_sequence__ (If the __mpl__ sequence is a bidirectional sequence.)
  78. * __random_access_sequence__ (If the __mpl__ sequence is a random access sequence.)
  79. [heading Example]
  80. mpl::vector_c<int, 123, 456> vec_c;
  81. fusion::vector2<int, long> v(vec_c);
  82. std::cout << __at_c__<0>(v) << std::endl;
  83. std::cout << __at_c__<1>(v) << std::endl;
  84. v = mpl::vector_c<int, 456, 789>();
  85. std::cout << __at_c__<0>(v) << std::endl;
  86. std::cout << __at_c__<1>(v) << std::endl;
  87. [heading Bi-directional adaptation]
  88. Fusion sequences may also be adapted as fully conforming __mpl__ sequences (see
  89. __intrinsics__). That way, we can have 2-way adaptation to and from __mpl__ and
  90. Fusion. To make Fusion sequences fully conforming __mpl__ sequences, include:
  91. #include <boost/fusion/mpl.hpp>
  92. If you want bi-directional adaptation to and from __mpl__ and Fusion, simply
  93. include:
  94. #include <boost/fusion/include/mpl.hpp>
  95. The header includes all the necessary headers.
  96. [heading See also]
  97. __mpl__
  98. [endsect]
  99. [section boost::array]
  100. This module provides adapters for `boost::array`. Including the module
  101. header makes `boost::array` a fully conforming __random_access_sequence__.
  102. [heading Header]
  103. #include <boost/fusion/adapted/boost_array.hpp>
  104. #include <boost/fusion/include/boost_array.hpp>
  105. [heading Model of]
  106. * __random_access_sequence__
  107. [heading Example]
  108. boost::array<int,3> arr = {{1,2,3}};
  109. std::cout << *__begin__(arr) << std::endl;
  110. std::cout << *__next__(__begin__(arr)) << std::endl;
  111. std::cout << *__advance_c__<2>(__begin__(arr)) << std::endl;
  112. std::cout << *__prior__(__end__(arr)) << std::endl;
  113. std::cout << __at_c__<2>(arr) << std::endl;
  114. [heading See also]
  115. __boost_array_library__
  116. [endsect]
  117. [section boost::tuple]
  118. This module provides adapters for `boost::tuple`. Including the module
  119. header makes `boost::tuple` a fully conforming __forward_sequence__.
  120. [heading Header]
  121. #include <boost/fusion/adapted/boost_tuple.hpp>
  122. #include <boost/fusion/include/boost_tuple.hpp>
  123. [heading Model of]
  124. * __forward_sequence__
  125. [heading Example]
  126. boost::tuple<int,std::string> example_tuple(101, "hello");
  127. std::cout << *__begin__(example_tuple) << '\n';
  128. std::cout << *__next__(__begin__(example_tuple)) << '\n';
  129. [heading See also]
  130. __boost_tuple_library__
  131. [endsect]
  132. [section:adapt_struct BOOST_FUSION_ADAPT_STRUCT]
  133. [heading Description]
  134. BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the
  135. necessary boilerplate to make an arbitrary struct a model of
  136. __random_access_sequence__.
  137. [heading Synopsis]
  138. BOOST_FUSION_ADAPT_STRUCT(
  139. struct_name,
  140. member_name0,
  141. member_name1,
  142. member_name2,
  143. ...
  144. )
  145. // Without BOOST_PP_VARIADICS support :
  146. BOOST_FUSION_ADAPT_STRUCT(
  147. struct_name,
  148. (member_type0, member_name0)
  149. (member_type1, member_name1)
  150. (auto, member_name2)
  151. ...
  152. )
  153. [heading Semantics]
  154. The above macro generates the necessary code to adapt `struct_name`
  155. as a model of __random_access_sequence__.
  156. The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
  157. pairs declares the type and names of each of the struct members that are part of
  158. the sequence.
  159. When member_typeN is omitted or set to auto, the type is
  160. infered with Boost.TypeOf.
  161. The macro should be used at global scope, and `struct_name` should be the fully
  162. namespace qualified name of the struct to be adapted.
  163. [heading Header]
  164. #include <boost/fusion/adapted/struct/adapt_struct.hpp>
  165. #include <boost/fusion/include/adapt_struct.hpp>
  166. [heading Example: BOOST_FUSION_ADAPT_STRUCT ]
  167. namespace demo
  168. {
  169. struct employee
  170. {
  171. std::string name;
  172. int age;
  173. };
  174. }
  175. // demo::employee is now a Fusion sequence
  176. BOOST_FUSION_ADAPT_STRUCT(
  177. demo::employee,
  178. name,
  179. age)
  180. // Without BOOST_PP_VARIADICS support :
  181. BOOST_FUSION_ADAPT_STRUCT(
  182. demo::employee,
  183. (auto, name)
  184. (auto, age)
  185. )
  186. [endsect]
  187. [section:adapt_tpl_struct BOOST_FUSION_ADAPT_TPL_STRUCT]
  188. [heading Description]
  189. BOOST_FUSION_ADAPT_TPL_STRUCT is a macro that can be used to generate all the
  190. necessary boilerplate to make an arbitrary template struct a model of
  191. __random_access_sequence__.
  192. [heading Synopsis]
  193. BOOST_FUSION_ADAPT_TPL_STRUCT(
  194. (template_param0)(template_param1)...,
  195. (struct_name) (specialization_param0)(specialization_param1)...,
  196. member_name0,
  197. member_name1
  198. ...
  199. )
  200. // Without BOOST_PP_VARIADICS support :
  201. BOOST_FUSION_ADAPT_TPL_STRUCT(
  202. (template_param0)(template_param1)...,
  203. (struct_name) (specialization_param0)(specialization_param1)...,
  204. (member_type0, member_name0)
  205. (member_type1, member_name1)
  206. (auto, member_name2),
  207. ...
  208. )
  209. [heading Semantics]
  210. The above macro generates the necessary code to adapt `struct_name` or an
  211. arbitrary specialization of `struct_name` as a model of
  212. __random_access_sequence__.
  213. The sequence `(template_param0)(template_param1)...` declares the names of
  214. the template type parameters used.
  215. The sequence `(specialization_param0)(specialization_param1)...`
  216. declares the template parameters of the actual specialization of `struct_name`
  217. that is adapted as a fusion sequence.
  218. The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
  219. pairs declares the type and names of each of the struct members that are part of
  220. the sequence.
  221. When member_typeN is omitted or set to auto, the type is
  222. infered with Boost.TypeOf.
  223. The macro should be used at global scope, and `struct_name` should be the fully
  224. namespace qualified name of the struct to be adapted.
  225. [heading Header]
  226. #include <boost/fusion/adapted/struct/adapt_struct.hpp>
  227. #include <boost/fusion/include/adapt_struct.hpp>
  228. [heading Example]
  229. namespace demo
  230. {
  231. template<typename Name, typename Age>
  232. struct employee
  233. {
  234. Name name;
  235. Age age;
  236. int employment_timestamp;
  237. };
  238. }
  239. // Any instantiated demo::employee is now a Fusion sequence
  240. BOOST_FUSION_ADAPT_TPL_STRUCT(
  241. (Name)(Age),
  242. (demo::employee) (Name)(Age),
  243. (Name, name)
  244. (Age, age)
  245. (auto, employment_timestamp))
  246. // Or by infering type completely
  247. BOOST_FUSION_ADAPT_TPL_STRUCT(
  248. (Name)(Age),
  249. (demo::employee) (Name)(Age),
  250. name,
  251. age,
  252. employment_timestamp)
  253. [endsect]
  254. [section:adapt_struct_named BOOST_FUSION_ADAPT_STRUCT_NAMED]
  255. [heading Description]
  256. BOOST_FUSION_ADAPT_STRUCT_NAMED and BOOST_FUSION_ADAPT_STRUCT_NAMED_NS are
  257. macros that can be used to generate all the necessary boilerplate to make an
  258. arbitrary struct a model of __random_access_sequence__. The given struct is
  259. adapted using the given name.
  260. [heading Synopsis]
  261. BOOST_FUSION_ADAPT_STRUCT_NAMED(
  262. struct_name, adapted_name,
  263. member_name0,
  264. member_name1,
  265. member_name2,
  266. ...
  267. )
  268. BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
  269. struct_name,
  270. (namespace0)(namespace1)...,
  271. adapted_name,
  272. member_name0,
  273. member_name1,
  274. member_name2,
  275. ...
  276. )
  277. // Without BOOST_PP_VARIADICS support :
  278. BOOST_FUSION_ADAPT_STRUCT_NAMED(
  279. struct_name, adapted_name,
  280. (member_type0, member_name0)
  281. (member_type1, member_name1)
  282. (auto, member_name2),
  283. ...
  284. )
  285. BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(
  286. struct_name,
  287. (namespace0)(namespace1)...,
  288. adapted_name,
  289. (member_type0, member_name0)
  290. (member_type1, member_name1)
  291. (auto, member_name2),
  292. ...
  293. )
  294. [heading Semantics]
  295. The above macros generate the necessary code to adapt `struct_name`
  296. as a model of __random_access_sequence__ while using `adapted_name` as the
  297. name of the adapted struct.
  298. The sequence `(namespace0)(namespace1)...` declares the namespace
  299. for `adapted_name`. It yields to a fully qualified name for `adapted_name` of
  300. `namespace0::namespace1::... adapted_name`.
  301. If an empty namespace sequence is given (that is a macro that expands to
  302. nothing), the adapted view is placed in the global namespace.
  303. If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_NAMED`), the
  304. adapted view is placed in the namespace `boost::fusion::adapted`.
  305. The sequence of `member_nameN,` arguments or `(member_typeN, member_nameN)`
  306. pairs declares the type and names of each of the struct members that are part of
  307. the sequence.
  308. When member_typeN is omitted or set to auto, the type is
  309. infered with Boost.TypeOf.
  310. The macros should be used at global scope, and `struct_name` should be the fully
  311. namespace qualified name of the struct to be converted.
  312. [heading Header]
  313. #include <boost/fusion/adapted/struct/adapt_struct_named.hpp>
  314. #include <boost/fusion/include/adapt_struct_named.hpp>
  315. [heading Example]
  316. namespace demo
  317. {
  318. struct employee
  319. {
  320. std::string name;
  321. int age;
  322. };
  323. }
  324. // boost::fusion::adapted::adapted_employee is now a Fusion sequence
  325. // referring to demo::employee
  326. BOOST_FUSION_ADAPT_STRUCT_NAMED(
  327. demo::employee, adapted_employee,
  328. name,
  329. age)
  330. // Without BOOST_PP_VARIADICS support :
  331. BOOST_FUSION_ADAPT_STRUCT_NAMED(
  332. demo::employee, adapted_employee,
  333. (auto, name),
  334. (auto, age))
  335. [endsect]
  336. [section:adapt_assoc BOOST_FUSION_ADAPT_ASSOC_STRUCT]
  337. [heading Description]
  338. BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the
  339. necessary boilerplate to make an arbitrary struct a model of
  340. __random_access_sequence__ and __associative_sequence__.
  341. [heading Synopsis]
  342. BOOST_FUSION_ADAPT_ASSOC_STRUCT(
  343. struct_name,
  344. ([member_type0,] member_name0, key_type0)
  345. ([member_type1,] member_name1, key_type1)
  346. ...
  347. )
  348. [heading Semantics]
  349. The above macro generates the necessary code to adapt `struct_name`
  350. as a model of __random_access_sequence__ and __associative_sequence__.
  351. The sequence of `([member_typeN,] member_nameN, key_typeN)` tuples
  352. declares the type, name and key type of each of the struct members
  353. that are part of the sequence.
  354. When member_typeN is omitted or set to auto, the type is
  355. infered with Boost.TypeOf.
  356. The macro should be used at global scope, and `struct_name` should be the fully
  357. namespace qualified name of the struct to be adapted.
  358. [heading Header]
  359. #include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
  360. #include <boost/fusion/include/adapt_assoc_struct.hpp>
  361. [heading Example]
  362. namespace demo
  363. {
  364. struct employee
  365. {
  366. std::string name;
  367. int age;
  368. };
  369. }
  370. namespace keys
  371. {
  372. struct name;
  373. struct age;
  374. }
  375. // demo::employee is now a Fusion sequence.
  376. // It is also an associative sequence with
  377. // keys keys::name and keys::age present.
  378. BOOST_FUSION_ADAPT_ASSOC_STRUCT(
  379. demo::employee,
  380. (name, keys::name)
  381. (age, keys::age))
  382. // Without BOOST_PP_VARIADICS support :
  383. BOOST_FUSION_ADAPT_ASSOC_STRUCT(
  384. demo::employee,
  385. (auto, name, keys::name),
  386. (auto, age, keys::name))
  387. [endsect]
  388. [section:adapt_assoc_tpl_struct BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT]
  389. [heading Description]
  390. BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT is a macro that can be used to generate all the
  391. necessary boilerplate to make an arbitrary template struct a model of
  392. __random_access_sequence__ and __associative_sequence__.
  393. [heading Synopsis]
  394. BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
  395. (template_param0)(template_param1)...,
  396. (struct_name) (specialization_param0)(specialization_param1)...,
  397. ([member_type0,] member_name0, key_type0)
  398. ([member_type1,] member_name1, key_type1)
  399. ...
  400. )
  401. [heading Semantics]
  402. The above macro generates the necessary code to adapt `struct_name` or an
  403. arbitrary specialization of `struct_name` as a model of
  404. __random_access_sequence__ and __associative_sequence__.
  405. The sequence `(template_param0)(template_param1)...` declares the names of
  406. the template type parameters used.
  407. The sequence `(specialization_param0)(specialization_param1)...`
  408. declares the template parameters of the actual specialization of `struct_name`
  409. that is adapted as a fusion sequence.
  410. The sequence of `([member_typeN,] member_nameN, key_typeN)`
  411. tuples declares the type, name and key type of each of the struct members
  412. that are part of the sequence.
  413. When member_typeN is omitted or set to auto, the type is
  414. infered with Boost.TypeOf.
  415. The macro should be used at global scope, and `struct_name` should be the fully
  416. namespace qualified name of the struct to be adapted.
  417. [heading Header]
  418. #include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
  419. #include <boost/fusion/include/adapt_assoc_struct.hpp>
  420. [heading Example]
  421. namespace demo
  422. {
  423. template<typename Name, typename Age>
  424. struct employee
  425. {
  426. Name name;
  427. Age age;
  428. };
  429. }
  430. namespace keys
  431. {
  432. struct name;
  433. struct age;
  434. }
  435. // Any instantiated demo::employee is now a Fusion sequence.
  436. // It is also an associative sequence with
  437. // keys keys::name and keys::age present.
  438. BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
  439. (Name)(Age),
  440. (demo::employee) (Name)(Age),
  441. (name, keys::name)
  442. (age, keys::age))
  443. // Without BOOST_PP_VARIADICS support :
  444. BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
  445. (Name)(Age),
  446. (demo::employee) (Name)(Age),
  447. (Name, name, keys::name)
  448. (Age, age, keys::age))
  449. [endsect]
  450. [section:adapt_assoc_struct_named BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED]
  451. [heading Description]
  452. BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED and BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS are
  453. macros that can be used to generate all the necessary boilerplate to make an
  454. arbitrary struct a model of __random_access_sequence__ and
  455. __associative_sequence__. The given struct is adapted using the given name.
  456. [heading Synopsis]
  457. BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
  458. struct_name, adapted_name,
  459. ([member_type0,] member_name0, key_type0)
  460. ([member_type1,] member_name1, key_type1)
  461. ...
  462. )
  463. BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED_NS(
  464. struct_name,
  465. (namespace0)(namespace1)...,
  466. adapted_name,
  467. ([member_type0,] member_name0, key_type0)
  468. ([member_type1,] member_name1, key_type1)
  469. ...
  470. )
  471. [heading Semantics]
  472. The above macros generate the necessary code to adapt `struct_name`
  473. as a model of __random_access_sequence__ and __associative_sequence__ while
  474. using `adapted_name` as the name of the adapted struct.
  475. The sequence `(namespace0)(namespace1)...` declares the namespace
  476. for `adapted_name`. It yields to a fully qualified name for `adapted_name` of
  477. `namespace0::namespace1::... adapted_name`.
  478. If an empty namespace sequence is given (that is a macro that expands to
  479. nothing), the adapted view is placed in the global namespace.
  480. If no namespace sequence is given (i.e. `BOOST_FUSION_ADAPT_STRUCT_ASSOC_NAMED`), the
  481. adapted view is placed in the namespace `boost::fusion::adapted`.
  482. The sequence of `(member_typeN, member_nameN, key_typeN)`
  483. triples declares the type, name and key type of each of the struct members
  484. that are part of the sequence.
  485. When member_typeN is omitted or set to auto, the type is
  486. infered with Boost.TypeOf.
  487. The macros should be used at global scope, and `struct_name` should be the fully
  488. namespace qualified name of the struct to be converted.
  489. [heading Header]
  490. #include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp>
  491. #include <boost/fusion/include/adapt_assoc_struct_named.hpp>
  492. [heading Example]
  493. namespace demo
  494. {
  495. struct employee
  496. {
  497. std::string name;
  498. int age;
  499. };
  500. }
  501. namespace keys
  502. {
  503. struct name;
  504. struct age;
  505. }
  506. // boost::fusion::adapted::adapted_employee is now a Fusion sequence
  507. // referring to demo::employee
  508. BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
  509. demo::employee, adapted_employee,
  510. (name, keys::name)
  511. (age, keys::age))
  512. // Without BOOST_PP_VARIADICS support :
  513. BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
  514. demo::employee, adapted_employee,
  515. (auto, name, keys::name)
  516. (auto, age, keys::age))
  517. [endsect]
  518. [section:adapt_adt BOOST_FUSION_ADAPT_ADT]
  519. BOOST_FUSION_ADAPT_ADT is a macro than can be used to generate all the
  520. necessary boilerplate to adapt an arbitrary class type as a model of
  521. __random_access_sequence__.
  522. [heading Synopsis]
  523. BOOST_FUSION_ADAPT_ADT(
  524. type_name,
  525. ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0)
  526. ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1)
  527. ...
  528. )
  529. [heading Expression Semantics]
  530. The above macro generates the necessary code to adapt `type_name`
  531. as a model of __random_access_sequence__.
  532. The sequence of
  533. [^([attribute_type['N], attribute_const_type['N],] get_expr['N], set_expr['N])]
  534. quadruples declares the types, const types, get-expressions and set-expressions
  535. of the elements that are part of the adapted fusion sequence.
  536. [^get_expr['N]] is the expression that is invoked to get the ['N]th element
  537. of an instance of `type_name`. This expression may access a variable named
  538. `obj` of type `type_name&` or `type_name const&` which represents the underlying
  539. instance of `type_name`.
  540. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
  541. that [^get_expr['N]] denotes to, when omitted the type is deduced from
  542. [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
  543. variadic macros auto can be used to avoid repeating the type.
  544. [^set_expr['N]] is the expression that is invoked to set the ['N]th element
  545. of an instance of `type_name`. This expression may access variables named
  546. `obj` of type `type_name&`, which represent the corresponding instance of
  547. `type_name`, and `val` of an arbitrary const-qualified reference template type
  548. parameter `Val`, which represents the right operand of the assignment
  549. expression.
  550. The actual return type of fusion's intrinsic sequence access (meta-)functions
  551. when in invoked with (an instance of) `type_name` is a proxy type.
  552. This type is implicitly convertible to the attribute type via [^get_expr['N]] and
  553. forwards assignment to the underlying element via [^set_expr['N]].
  554. The value type (that is the type returned by __result_of_value_of__,
  555. __result_of_value_at__ and __result_of_value_at_c__) of the ['N]th element
  556. is [^attribute_type['N]] with const-qualifier and reference removed.
  557. The macro should be used at global scope, and `type_name` should be the fully
  558. namespace qualified name of the class type to be adapted.
  559. [heading Header]
  560. #include <boost/fusion/adapted/adt/adapt_adt.hpp>
  561. #include <boost/fusion/include/adapt_adt.hpp>
  562. [heading Example]
  563. namespace demo
  564. {
  565. struct employee
  566. {
  567. private:
  568. std::string name;
  569. int age;
  570. public:
  571. void set_name(std::string const& n)
  572. {
  573. name=n;
  574. }
  575. void set_age(int a)
  576. {
  577. age=a;
  578. }
  579. std::string const& get_name()const
  580. {
  581. return name;
  582. }
  583. int get_age()const
  584. {
  585. return age;
  586. }
  587. };
  588. }
  589. BOOST_FUSION_ADAPT_ADT(
  590. demo::employee,
  591. (obj.get_name(), obj.set_name(val))
  592. (obj.get_age(), obj.set_age(val)))
  593. demo::employee e;
  594. front(e)="Edward Norton";
  595. back(e)=41;
  596. //Prints 'Edward Norton is 41 years old'
  597. std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
  598. [heading See also]
  599. __adt_attribute_proxy__
  600. [endsect]
  601. [section:adapt_tpl_adt BOOST_FUSION_ADAPT_TPL_ADT]
  602. BOOST_FUSION_ADAPT_TPL_ADT is a macro than can be used to generate all the
  603. necessary boilerplate to adapt an arbitrary template class type as a model of
  604. __random_access_sequence__.
  605. [heading Synopsis]
  606. BOOST_FUSION_ADAPT_TPL_ADT(
  607. (template_param0)(template_param1)...,
  608. (type_name) (specialization_param0)(specialization_param1)...,
  609. ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0)
  610. ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1)
  611. ...
  612. )
  613. [heading Expression Semantics]
  614. The above macro generates the necessary code to adapt `type_name`
  615. or an arbitrary specialization of `type_name`
  616. as a model of __random_access_sequence__.
  617. The sequence `(template_param0)(template_param1)...` declares the names of
  618. the template type parameters used.
  619. The sequence `(specialization_param0)(specialization_param1)...`
  620. declares the template parameters of the actual specialization of `type_name`
  621. that is adapted as a fusion sequence.
  622. The sequence of
  623. [^(attribute_type['N], attribute_const_type['N], get_expr['N], set_expr['N])]
  624. quadruples declares the types, const types, get-expressions and set-expressions
  625. of the elements that are part of the adapted fusion sequence.
  626. [^get_expr['N]] is the expression that is invoked to get the ['N]th element
  627. of an instance of `type_name`. This expression may access a variable named
  628. `obj` of type `type_name&` or `type_name const&` which represents the underlying
  629. instance of `type_name`.
  630. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
  631. that [^get_expr['N]] denotes to, when omitted the type is deduced from
  632. [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
  633. variadic macros auto can be used to avoid repeating the type.
  634. [^set_expr['N]] is the expression that is invoked to set the ['N]th element
  635. of an instance of `type_name`. This expression may access variables named
  636. `obj` of type `type_name&`, which represent the corresponding instance of
  637. `type_name`, and `val` of an arbitrary const-qualified reference template type
  638. parameter `Val`, which represents the right operand of the assignment
  639. expression.
  640. The actual return type of fusion's intrinsic sequence access (meta-)functions
  641. when in invoked with (an instance of) `type_name` is a proxy type.
  642. This type is implicitly convertible to the attribute type via [^get_expr['N]] and
  643. forwards assignment to the underlying element via [^set_expr['N]].
  644. The value type (that is the type returned by __result_of_value_of__,
  645. __result_of_value_at__ and __result_of_value_at_c__) of the ['N]th element
  646. is [^attribute_type['N]] with const-qualifier and reference removed.
  647. The macro should be used at global scope, and `type_name` should be the fully
  648. namespace qualified name of the template class type to be adapted.
  649. [heading Header]
  650. #include <boost/fusion/adapted/adt/adapt_adt.hpp>
  651. #include <boost/fusion/include/adapt_adt.hpp>
  652. [heading Example]
  653. namespace demo
  654. {
  655. template<typename Name, typename Age>
  656. struct employee
  657. {
  658. private:
  659. Name name;
  660. Age age;
  661. public:
  662. void set_name(Name const& n)
  663. {
  664. name=n;
  665. }
  666. void set_age(Age const& a)
  667. {
  668. age=a;
  669. }
  670. Name const& get_name()const
  671. {
  672. return name;
  673. }
  674. Age const& get_age()const
  675. {
  676. return age;
  677. }
  678. };
  679. }
  680. BOOST_FUSION_ADAPT_TPL_ADT(
  681. (Name)(Age),
  682. (demo::employee) (Name)(Age),
  683. (Name const&, Name const&, obj.get_name(), obj.set_name(val))
  684. (Age const&, Age const&, obj.get_age(), obj.set_age(val)))
  685. demo::employee<std::string, int> e;
  686. boost::fusion::front(e)="Edward Norton";
  687. boost::fusion::back(e)=41;
  688. //Prints 'Edward Norton is 41 years old'
  689. std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
  690. [heading See also]
  691. __adt_attribute_proxy__
  692. [endsect]
  693. [section:adapt_assoc_adt BOOST_FUSION_ADAPT_ASSOC_ADT]
  694. BOOST_FUSION_ADAPT_ASSOC_ADT is a macro than can be used to generate all the
  695. necessary boilerplate to adapt an arbitrary class type as a model of
  696. __random_access_sequence__ and __associative_sequence__.
  697. [heading Synopsis]
  698. BOOST_FUSION_ADAPT_ASSOC_ADT(
  699. type_name,
  700. ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0, key_type0)
  701. ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1, key_type1)
  702. ...
  703. )
  704. [heading Expression Semantics]
  705. The above macro generates the necessary code to adapt `type_name`
  706. as a model of __random_access_sequence__ and __associative_sequence__.
  707. The sequence of
  708. [^(attribute_type['N], attribute_const_type['N], get_expr['N], set_expr['N], key_type['N])]
  709. 5-tuples declares the types, const types, get-expressions, set-expressions and key types
  710. of the elements that are part of the adapted fusion sequence.
  711. [^get_expr['N]] is the expression that is invoked to get the ['N]th element
  712. of an instance of `type_name`. This expression may access a variable named
  713. `obj` of type `type_name&` or `type_name const&` which represents the underlying
  714. instance of `type_name`.
  715. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
  716. that [^get_expr['N]] denotes to, when omitted the type is deduced from
  717. [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
  718. variadic macros auto can be used to avoid repeating the type.
  719. [^set_expr['N]] is the expression that is invoked to set the ['N]th element
  720. of an instance of `type_name`. This expression may access variables named
  721. `obj` of type `type_name&`, which represent the corresponding instance of
  722. `type_name`, and `val` of an arbitrary const-qualified reference template type
  723. parameter `Val`, which represents the right operand of the assignment
  724. expression.
  725. The actual return type of fusion's intrinsic sequence access (meta-)functions
  726. when in invoked with (an instance of) `type_name` is a proxy type.
  727. This type is implicitly convertible to the attribute type via [^get_expr['N]] and
  728. forwards assignment to the underlying element via [^set_expr['N]].
  729. The value type (that is the type returned by __result_of_value_of__, __result_of_value_of_data__,
  730. __result_of_value_at__, __result_of_value_at_c__ and __result_of_value_at_key__) of the ['N]th element
  731. is [^attribute_type['N]] with const-qualifier and reference removed.
  732. The macro should be used at global scope, and `type_name` should be the fully
  733. namespace qualified name of the class type to be adapted.
  734. [heading Header]
  735. #include <boost/fusion/adapted/adt/adapt_assoc_adt.hpp>
  736. #include <boost/fusion/include/adapt_assoc_adt.hpp>
  737. [heading Example]
  738. namespace demo
  739. {
  740. struct employee
  741. {
  742. private:
  743. std::string name;
  744. int age;
  745. public:
  746. void set_name(std::string const& n)
  747. {
  748. name=n;
  749. }
  750. void set_age(int a)
  751. {
  752. age=a;
  753. }
  754. std::string const& get_name()const
  755. {
  756. return name;
  757. }
  758. int get_age()const
  759. {
  760. return age;
  761. }
  762. };
  763. }
  764. namespace keys
  765. {
  766. struct name;
  767. struct age;
  768. }
  769. BOOST_FUSION_ADAPT_ASSOC_ADT(
  770. demo::employee,
  771. (obj.get_name(), obj.set_name(val), keys::name)
  772. (obj.get_age(), obj.set_age(val), keys::age))
  773. demo::employee e;
  774. at_key<keys::name>(e)="Edward Norton";
  775. at_key<keys::age>(e)=41;
  776. //Prints 'Edward Norton is 41 years old'
  777. std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
  778. [heading See also]
  779. __adt_attribute_proxy__
  780. [endsect]
  781. [section:adapt_assoc_tpl_adt BOOST_FUSION_ADAPT_ASSOC_TPL_ADT]
  782. BOOST_FUSION_ADAPT_ASSOC_TPL_ADT is a macro than can be used to generate all the
  783. necessary boilerplate to adapt an arbitrary template class type as a model of
  784. __random_access_sequence__ and __associative_sequence__.
  785. [heading Synopsis]
  786. BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
  787. (template_param0)(template_param1)...,
  788. (type_name) (specialization_param0)(specialization_param1)...,
  789. ([attribute_type0, attribute_const_type0,] get_expr0, set_expr0, key_type0)
  790. ([attribute_type1, attribute_const_type1,] get_expr1, set_expr1, key_type1)
  791. ...
  792. )
  793. [heading Expression Semantics]
  794. The above macro generates the necessary code to adapt `type_name`
  795. or an arbitrary specialization of `type_name`
  796. as a model of __random_access_sequence__ and __associative_sequence__.
  797. The sequence `(template_param0)(template_param1)...` declares the names of
  798. the template type parameters used.
  799. The sequence `(specialization_param0)(specialization_param1)...`
  800. declares the template parameters of the actual specialization of `type_name`
  801. that is adapted as a fusion sequence.
  802. The sequence of
  803. [^([attribute_type['N], attribute_const_type['N],] get_expr['N], set_expr['N], key_type['N])]
  804. 5-tuples declares the types, const types, get-expressions, set-expressions and key types
  805. of the elements that are part of the adapted fusion sequence.
  806. [^get_expr['N]] is the expression that is invoked to get the ['N]th element
  807. of an instance of `type_name`. This expression may access a variable named
  808. `obj` of type `type_name&` or `type_name const&` which represents the underlying
  809. instance of `type_name`.
  810. [^attribute_type['N]] and [^attribute_const_type['N]] may specify the types
  811. that [^get_expr['N]] denotes to, when omitted the type is deduced from
  812. [get_expr['N]] return type via BOOST_TYPEOF. On compiler missing support for
  813. variadic macros auto can be used to avoid repeating the type.
  814. [^set_expr['N]] is the expression that is invoked to set the ['N]th element
  815. of an instance of `type_name`. This expression may access variables named
  816. `obj` of type `type_name&`, which represent the corresponding instance of
  817. `type_name`, and `val` of an arbitrary const-qualified reference template type
  818. parameter `Val`, which represents the right operand of the assignment
  819. expression.
  820. The actual return type of fusion's intrinsic sequence access (meta-)functions
  821. when in invoked with (an instance of) `type_name` is a proxy type.
  822. This type is implicitly convertible to the attribute type via [^get_expr['N]] and
  823. forwards assignment to the underlying element via [^set_expr['N]].
  824. The value type (that is the type returned by __result_of_value_of__, __result_of_value_of_data__,
  825. __result_of_value_at__, __result_of_value_at_c__ and __result_of_value_at_key__) of the ['N]th element
  826. is [^attribute_type['N]] with const-qualifier and reference removed.
  827. The macro should be used at global scope, and `type_name` should be the fully
  828. namespace qualified name of the template class type to be adapted.
  829. [heading Header]
  830. #include <boost/fusion/adapted/adt/adapt_assoc_adt.hpp>
  831. #include <boost/fusion/include/adapt_assoc_adt.hpp>
  832. [heading Example]
  833. namespace demo
  834. {
  835. template<typename Name, typename Age>
  836. struct employee
  837. {
  838. private:
  839. Name name;
  840. Age age;
  841. public:
  842. void set_name(Name const& n)
  843. {
  844. name=n;
  845. }
  846. void set_age(Age const& a)
  847. {
  848. age=a;
  849. }
  850. Name const& get_name()const
  851. {
  852. return name;
  853. }
  854. Age const& get_age()const
  855. {
  856. return age;
  857. }
  858. };
  859. }
  860. namespace keys
  861. {
  862. struct name;
  863. struct age;
  864. }
  865. BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
  866. (Name)(Age),
  867. (demo::employee) (Name)(Age),
  868. (Name const&, Name const&, obj.get_name(), obj.set_name(val), keys::name)
  869. (Age const&, Age const&, obj.get_age(), obj.set_age(val), keys::age))
  870. demo::employee<std::string, int> e;
  871. at_key<keys::name>(e)="Edward Norton";
  872. at_key<keys::age>(e)=41;
  873. //Prints 'Edward Norton is 41 years old'
  874. std::cout << e.get_name() << " is " << e.get_age() << " years old" << std::endl;
  875. [heading See also]
  876. __adt_attribute_proxy__
  877. [endsect]
  878. [section:define_struct BOOST_FUSION_DEFINE_STRUCT]
  879. BOOST_FUSION_DEFINE_STRUCT is a macro that can be used to generate all the
  880. necessary boilerplate to define and adapt an arbitrary struct as a model of
  881. __random_access_sequence__.
  882. [heading Synopsis]
  883. BOOST_FUSION_DEFINE_STRUCT(
  884. (namespace0)(namespace1)...,
  885. struct_name,
  886. (member_type0, member_name0)
  887. (member_type1, member_name1)
  888. ...
  889. )
  890. [variablelist Notation
  891. [[`str`] [An instance of `struct_name`]]
  892. [[`e0`...`en`] [Heterogeneous values]]
  893. [[`fs`] [A __forward_sequence__]]
  894. ]
  895. [heading Expression Semantics]
  896. The above macro generates the necessary code that defines and adapts `struct_name`
  897. as a model of __random_access_sequence__.
  898. The sequence `(namespace0)(namespace1)...` declares the namespace
  899. for `struct_name`. It yields to a fully qualified name for `struct_name` of
  900. `namespace0::namespace1::... struct_name`.
  901. If an empty namespace sequence is given (that is a macro that expands to
  902. nothing), the struct is placed in the global namespace.
  903. The sequence of `(member_typeN, member_nameN)`
  904. pairs declares the type and names of each of the struct members that are
  905. part of the sequence.
  906. The macro should be used at global scope.
  907. Semantics of an expression is defined only where it differs from, or is not
  908. defined in __random_access_sequence__.
  909. [table
  910. [[Expression] [Semantics]]
  911. [[`struct_name()`] [Creates an instance of `struct_name` with default constructed elements.]]
  912. [[`struct_name(e0, e1,... en)`] [Creates an instance of `struct_name` with elements `e0`...`en`.]]
  913. [[`struct_name(fs)`] [Copy constructs an instance of `struct_name` from a __forward_sequence__ `fs`.]]
  914. [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
  915. [[`str.member_nameN`] [Access of struct member `member_nameN`]]
  916. ]
  917. [heading Header]
  918. #include <boost/fusion/adapted/struct/define_struct.hpp>
  919. #include <boost/fusion/include/define_struct.hpp>
  920. [heading Example]
  921. // demo::employee is a Fusion sequence
  922. BOOST_FUSION_DEFINE_STRUCT(
  923. (demo), employee,
  924. (std::string, name)
  925. (int, age))
  926. [endsect]
  927. [section:define_tpl_struct BOOST_FUSION_DEFINE_TPL_STRUCT]
  928. [heading Description]
  929. BOOST_FUSION_DEFINE_TPL_STRUCT is a macro that can be used to generate all the
  930. necessary boilerplate to define and adapt an arbitrary template struct as a
  931. model of __random_access_sequence__.
  932. [heading Synopsis]
  933. BOOST_FUSION_DEFINE_TPL_STRUCT(
  934. (template_param0)(template_param1)...,
  935. (namespace0)(namespace1)...,
  936. struct_name,
  937. (member_type0, member_name0)
  938. (member_type1, member_name1)
  939. ...
  940. )
  941. [variablelist Notation
  942. [[`Str`] [An instantiated `struct_name`]]
  943. [[`str`] [An instance of `Str`]]
  944. [[`e0`...`en`] [Heterogeneous values]]
  945. [[`fs`] [A __forward_sequence__]]
  946. ]
  947. [heading Expression Semantics]
  948. The above macro generates the necessary code that defines and adapts `struct_name`
  949. as a model of __random_access_sequence__.
  950. The sequence `(template_param0)(template_param1)...` declares the names of
  951. the template type parameters used.
  952. The sequence `(namespace0)(namespace1)...` declares the namespace
  953. for `struct_name`. It yields to a fully qualified name for `struct_name` of
  954. `namespace0::namespace1::... struct_name`.
  955. If an empty namespace sequence is given (that is a macro that expands to
  956. nothing), the struct is placed in the global namespace.
  957. The sequence of `(member_typeN, member_nameN)`
  958. pairs declares the type and names of each of the struct members that are
  959. part of the sequence.
  960. The macro should be used at global scope.
  961. Semantics of an expression is defined only where it differs from, or is not
  962. defined in __random_access_sequence__.
  963. [table
  964. [[Expression] [Semantics]]
  965. [[`Str()`] [Creates an instance of `Str` with default constructed elements.]]
  966. [[`Str(e0, e1,... en)`] [Creates an instance of `Str` with elements `e0`...`en`.]]
  967. [[`Str(fs)`] [Copy constructs an instance of `Str` from a __forward_sequence__ `fs`.]]
  968. [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
  969. [[`str.member_nameN`] [Access of struct member `member_nameN`]]
  970. ]
  971. [heading Header]
  972. #include <boost/fusion/adapted/struct/define_struct.hpp>
  973. #include <boost/fusion/include/define_struct.hpp>
  974. [heading Example]
  975. // Any instantiated demo::employee is a Fusion sequence
  976. BOOST_FUSION_DEFINE_TPL_STRUCT(
  977. (Name)(Age), (demo), employee,
  978. (Name, name)
  979. (Age, age))
  980. [endsect]
  981. [section:define_struct_inline BOOST_FUSION_DEFINE_STRUCT_INLINE]
  982. [heading Description]
  983. BOOST_FUSION_DEFINE_STRUCT_INLINE is a macro that can be used to generate all
  984. the necessary boilerplate to define and adapt an arbitrary struct as a model of
  985. __random_access_sequence__. Unlike BOOST_FUSION_DEFINE_STRUCT, it can be used
  986. at class or namespace scope.
  987. [heading Synopsis]
  988. BOOST_FUSION_DEFINE_STRUCT_INLINE(
  989. struct_name,
  990. (member_type0, member_name0)
  991. (member_type1, member_name1)
  992. ...
  993. )
  994. [heading Expression Semantics]
  995. The semantics of BOOST_FUSION_DEFINE_STRUCT_INLINE are identical to those of
  996. BOOST_FUSION_DEFINE_STRUCT, with two differences:
  997. # BOOST_FUSION_DEFINE_STRUCT_INLINE can be used at class or namespace scope, and
  998. thus does not take a namespace list parameter.
  999. # The structure generated by BOOST_FUSION_DEFINE_STRUCT_INLINE has a base class,
  1000. and is thus not POD in C++03.
  1001. [heading Header]
  1002. #include <boost/fusion/adapted/struct/define_struct_inline.hpp>
  1003. #include <boost/fusion/include/define_struct_inline.hpp>
  1004. [heading Example]
  1005. // enclosing::employee is a Fusion sequence
  1006. class enclosing
  1007. {
  1008. BOOST_FUSION_DEFINE_STRUCT_INLINE(
  1009. employee,
  1010. (std::string, name)
  1011. (int, age))
  1012. };
  1013. [endsect]
  1014. [section:define_tpl_struct_inline BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE]
  1015. [heading Description]
  1016. BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE is a macro that can be used to generate
  1017. all the necessary boilerplate to define and adapt an arbitrary template struct
  1018. as a model of __random_access_sequence__. Unlike BOOST_FUSION_DEFINE_TPL_STRUCT,
  1019. it can be used at class or namespace scope.
  1020. [heading Synopsis]
  1021. BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
  1022. (template_param0)(template_param1)...,
  1023. struct_name,
  1024. (member_type0, member_name0)
  1025. (member_type1, member_name1)
  1026. ...
  1027. )
  1028. [heading Expression Semantics]
  1029. The semantics of BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE are identical to those of
  1030. BOOST_FUSION_DEFINE_TPL_STRUCT, with two differences:
  1031. # BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE can be used at class or namespace scope,
  1032. and thus does not take a namespace list parameter.
  1033. # The structure generated by BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE has a base
  1034. class, and is thus not POD in C++03.
  1035. [heading Header]
  1036. #include <boost/fusion/adapted/struct/define_struct_inline.hpp>
  1037. #include <boost/fusion/include/define_struct_inline.hpp>
  1038. [heading Example]
  1039. // Any instantiated enclosing::employee is a Fusion sequence
  1040. class enclosing
  1041. {
  1042. BOOST_FUSION_DEFINE_TPL_STRUCT(
  1043. (Name)(Age), employee,
  1044. (Name, name)
  1045. (Age, age))
  1046. };
  1047. [endsect]
  1048. [section:define_assoc_struct BOOST_FUSION_DEFINE_ASSOC_STRUCT]
  1049. [heading Description]
  1050. BOOST_FUSION_DEFINE_ASSOC_STRUCT is a macro that can be used to generate all the
  1051. necessary boilerplate to define and adapt an arbitrary struct as a model of
  1052. __random_access_sequence__ and __associative_sequence__.
  1053. [heading Synopsis]
  1054. BOOST_FUSION_DEFINE_ASSOC_STRUCT(
  1055. (namespace0)(namespace1)...,
  1056. struct_name,
  1057. (member_type0, member_name0, key_type0)
  1058. (member_type1, member_name1, key_type1)
  1059. ...
  1060. )
  1061. [variablelist Notation
  1062. [[`str`] [An instance of `struct_name`]]
  1063. [[`e0`...`en`] [Heterogeneous values]]
  1064. [[`fs`] [A __forward_sequence__]]
  1065. ]
  1066. [heading Expression Semantics]
  1067. The above macro generates the necessary code that defines and adapts `struct_name`
  1068. as a model of __random_access_sequence__ and __associative_sequence__.
  1069. The sequence `(namespace0)(namespace1)...` declares the namespace
  1070. for `struct_name`. It yields to a fully qualified name for `struct_name` of
  1071. `namespace0::namespace1::... struct_name`.
  1072. If an empty namespace sequence is given (that is a macro that expands to
  1073. nothing), the struct is placed in the global namespace.
  1074. The sequence of `(member_typeN, member_nameN, key_typeN)`
  1075. triples declares the type, name and key type of each of the struct members
  1076. that are part of the sequence.
  1077. The macro should be used at global scope.
  1078. Semantics of an expression is defined only where it differs from, or is not
  1079. defined in __random_access_sequence__ and __associative_sequence__.
  1080. [table
  1081. [[Expression] [Semantics]]
  1082. [[`struct_name()`] [Creates an instance of `struct_name` with default constructed elements.]]
  1083. [[`struct_name(e0, e1,... en)`] [Creates an instance of `struct_name` with elements `e0`...`en`.]]
  1084. [[`struct_name(fs)`] [Copy constructs an instance of `struct_name` from a __forward_sequence__ `fs`.]]
  1085. [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
  1086. [[`str.member_nameN`] [Access of struct member `member_nameN`]]
  1087. ]
  1088. [heading Header]
  1089. #include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
  1090. #include <boost/fusion/include/define_assoc_struct.hpp>
  1091. [heading Example]
  1092. namespace keys
  1093. {
  1094. struct name;
  1095. struct age;
  1096. }
  1097. // demo::employee is a Fusion sequence
  1098. BOOST_FUSION_DEFINE_ASSOC_STRUCT(
  1099. (demo), employee,
  1100. (std::string, name, keys::name)
  1101. (int, age, keys::age))
  1102. [endsect]
  1103. [section:define_assoc_tpl_struct BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT]
  1104. [heading Description]
  1105. BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT is a macro that can be used to generate all
  1106. the necessary boilerplate to define and adapt an arbitrary template struct as a
  1107. model of __random_access_sequence__ and __associative_sequence__.
  1108. [heading Synopsis]
  1109. BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
  1110. (template_param0)(template_param1)...,
  1111. (namespace0)(namespace1)...,
  1112. struct_name,
  1113. (member_type0, member_name0, key_type0)
  1114. (member_type1, member_name1, key_type1)
  1115. ...
  1116. )
  1117. [variablelist Notation
  1118. [[`Str`] [An instantiated `struct_name`]]
  1119. [[`str`] [An instance of `Str`]]
  1120. [[`e0`...`en`] [Heterogeneous values]]
  1121. [[`fs`] [A __forward_sequence__]]
  1122. ]
  1123. [heading Expression Semantics]
  1124. The above macro generates the necessary code that defines and adapts
  1125. `struct_name` as a model of __random_access_sequence__ and
  1126. __associative_sequence__.
  1127. The sequence `(template_param0)(template_param1)...` declares the names of
  1128. the template type parameters used.
  1129. The sequence `(namespace0)(namespace1)...` declares the namespace
  1130. for `struct_name`. It yields to a fully qualified name for `struct_name` of
  1131. `namespace0::namespace1::... struct_name`.
  1132. If an empty namespace sequence is given (that is a macro that expands to
  1133. nothing), the struct is placed in the global namespace.
  1134. The sequence of `(member_typeN, member_nameN, key_typeN)`
  1135. triples declares the type, name and key type of each of the struct members
  1136. that are part of the sequence.
  1137. The macro should be used at global scope.
  1138. Semantics of an expression is defined only where it differs from, or is not
  1139. defined in __random_access_sequence__ and __associative_sequence__.
  1140. [table
  1141. [[Expression] [Semantics]]
  1142. [[`Str()`] [Creates an instance of `Str` with default constructed elements.]]
  1143. [[`Str(e0, e1,... en)`] [Creates an instance of `Str` with elements `e0`...`en`.]]
  1144. [[`Str(fs)`] [Copy constructs an instance of `Str` from a __forward_sequence__ `fs`.]]
  1145. [[`str = fs`] [Assigns from a __forward_sequence__ `fs`.]]
  1146. [[`str.member_nameN`] [Access of struct member `member_nameN`]]
  1147. ]
  1148. [heading Header]
  1149. #include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
  1150. #include <boost/fusion/include/define_assoc_struct.hpp>
  1151. [heading Example]
  1152. namespace keys
  1153. {
  1154. struct name;
  1155. struct age;
  1156. }
  1157. // Any instantiated demo::employee is a Fusion sequence
  1158. BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT(
  1159. (Name)(Age), (demo), employee,
  1160. (Name, name, keys::name)
  1161. (Age, age, keys::age))
  1162. [endsect]
  1163. [endsect]