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