1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068 |
- [/==============================================================================
- Copyright (C) 2001-2011 Joel de Guzman
- Copyright (C) 2006 Dan Marsden
- Copyright (C) 2014 Christoph Weiss
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
- ===============================================================================/]
- [section Sequence]
- Like __mpl__, the Sequence is a fundamental concept in Fusion. A Sequence
- may or may not actually store or contain data. __containers__ are sequences
- that hold data. __views__, on the other hand, are sequences that do not
- store any data. Instead, they are proxies that impart an alternative
- presentation over another sequence. All models of Sequence have an
- associated __iterator__ type that can be used to iterate through the
- Sequence's elements.
- [heading Header]
- #include <boost/fusion/sequence.hpp>
- #include <boost/fusion/include/sequence.hpp>
- [section Concepts]
- Fusion Sequences are organized into a hierarchy of concepts.
- [heading Traversal]
- Fusion's sequence traversal related concepts parallel Fusion's
- __iterator_concepts__. __forward_sequence__ is the most basic concept.
- __bidirectional_sequence__ is a refinement of __forward_sequence__.
- __random_access_sequence__ is a refinement of __bidirectional_sequence__.
- These concepts pertain to sequence traversal.
- [heading Associativity]
- The __associative_sequence__ concept is orthogonal to traversal. An Associative
- Sequence allows efficient retrieval of elements based on keys.
- [heading Boundary]
- The __unbounded_sequence__ concept is also orthogonal to traversal and associativity.
- A Unbounded Sequence allows out-of-bounds access.
- [section Forward Sequence]
- [heading Description]
- A Forward Sequence is a Sequence whose elements are arranged in a definite
- order. The ordering is guaranteed not to change from iteration to
- iteration. The requirement of a definite ordering allows the definition of
- element-by-element equality (if the container's element type is Equality
- Comparable) and of lexicographical ordering (if the container's element
- type is LessThan Comparable).
- [variablelist Notation
- [[`s`] [A Forward Sequence]]
- [[`S`] [A Forward Sequence type]]
- [[`o`] [An arbitrary object]]
- [[`e`] [A Sequence element]]
- ]
- [heading Valid Expressions]
- For any Forward Sequence the following expressions must be valid:
- [table
- [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
- [[`__begin__(s)`] [__forward_iterator__] [] [Constant]]
- [[`__end__(s)`] [__forward_iterator__] [] [Constant]]
- [[`__size__(s)`] [__mpl_integral_constant__.
- Convertible to int.] [] [Constant]]
- [[`__empty__(s)`] [__mpl_boolean_constant__.
- Convertible to bool.] [] [Constant]]
- [[`__front__(s)`] [Any type] [] [Constant]]
- [[`__front__(s) = o`] [Any type] [`s` is mutable and
- `e = o`, where `e`
- is the first element
- in the sequence, is
- a valid expression.] [Constant]]
- ]
- [heading Result Type Expressions]
- [table
- [[Expression] [Compile Time Complexity]]
- [[`__result_of_begin__<S>::type`] [Amortized constant time]]
- [[`__result_of_end__<S>::type`] [Amortized constant time]]
- [[`__result_of_size__<S>::type`] [Unspecified]]
- [[`__result_of_empty__<S>::type`] [Constant time]]
- [[`__result_of_front__<S>::type`] [Amortized constant time]]
- ]
- [heading Expression Semantics]
- [table
- [[Expression] [Semantics]]
- [[`__begin__(s)`] [An iterator to the first element of the sequence; see __begin__.]]
- [[`__end__(s)`] [A past-the-end iterator to the sequence; see __end__.]]
- [[`__size__(s)`] [The size of the sequence; see __size__.]]
- [[`__empty__(s)`] [A boolean Integral Constant `c` such that
- `c::value == true` if and only if the sequence
- is empty; see __empty__.]]
- [[`__front__(s)`] [The first element in the sequence; see __front__.]]
- ]
- [heading Invariants]
- For any Forward Sequence s the following invariants always hold:
- * `[__begin__(s), __end__(s))` is always a valid range.
- * An __algorithm__ that iterates through the range `[__begin__(s), __end__(s))`
- will pass through every element of `s` exactly once.
- * `__begin__(s)` is identical to `__end__(s))` if and only if `s` is empty.
- * Two different iterations through `s` will access its elements in
- the same order.
- [heading Models]
- * __std_pair__
- * __boost_array__
- * __vector__
- * __cons__
- * __list__
- * __set__
- * __map__
- * __single_view__
- * __filter_view__
- * __iterator_range__
- * __joint_view__
- * __transform_view__
- * __reverse_view__
- * __zip_view__
- [endsect]
- [section Bidirectional Sequence]
- [heading Description]
- A Bidirectional Sequence is a __forward_sequence__ whose iterators model
- __bidirectional_iterator__.
- [heading Refinement of]
- __forward_sequence__
- [variablelist Notation
- [[`s`] [A Bidirectional Sequence]]
- [[`S`] [A Bidirectional Sequence type]]
- [[`o`] [An arbitrary object]]
- [[`e`] [A Sequence element]]
- ]
- [heading Valid Expressions]
- In addition to the requirements defined in __forward_sequence__, for any
- Bidirectional Sequence the following must be met:
- [table
- [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
- [[`__begin__(s)`] [__bidirectional_iterator__] [] [Constant]]
- [[`__end__(s)`] [__bidirectional_iterator__] [] [Constant]]
- [[`__back__(s)`] [Any type] [] [Constant]]
- [[`__back__(s) = o`] [Any type] [`s` is mutable and
- `e = o`, where `e`
- is the first element
- in the sequence, is
- a valid expression.] [Constant]]
- ]
- [heading Result Type Expressions]
- [table
- [[Expression] [Compile Time Complexity]]
- [[`__result_of_begin__<S>::type`] [Amortized constant time]]
- [[`__result_of_end__<S>::type`] [Amortized constant time]]
- [[`__result_of_back__<S>::type`] [Amortized constant time]]
- ]
- [heading Expression Semantics]
- The semantics of an expression are defined only where they differ from, or
- are not defined in __forward_sequence__.
- [table
- [[Expression] [Semantics]]
- [[`__back__(s)`] [The last element in the sequence; see __back__.]]
- ]
- [heading Models]
- * __std_pair__
- * __boost_array__
- * __vector__
- * __map__
- * __reverse_view__
- * __single_view__
- * __iterator_range__ (where adapted sequence is a Bidirectional Sequence)
- * __transform_view__ (where adapted sequence is a Bidirectional Sequence)
- * __zip_view__ (where adapted sequences are models of Bidirectional Sequence)
- [endsect]
- [section Random Access Sequence]
- [heading Description]
- A Random Access Sequence is a __bidirectional_sequence__ whose iterators
- model __random_access_iterator__. It guarantees constant time access to
- arbitrary sequence elements.
- [heading Refinement of]
- __bidirectional_sequence__
- [variablelist Notation
- [[`s`] [A Random Access Sequence]]
- [[`S`] [A Random Access Sequence type]]
- [[`M`] [An __mpl__ integral constant]]
- [[`N`] [An integral constant]]
- [[`o`] [An arbitrary object]]
- [[`e`] [A Sequence element]]
- ]
- [heading Valid Expressions]
- In addition to the requirements defined in __bidirectional_sequence__, for
- any Random Access Sequence the following must be met:
- [table
- [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
- [[`__begin__(s)`] [__random_access_iterator__] [] [Constant]]
- [[`__end__(s)`] [__random_access_iterator__] [] [Constant]]
- [[`__at_c__<N>(s)`] [Any type] [] [Constant]]
- [[`__at_c__<N>(s) = o`] [Any type] [`s` is mutable and
- `e = o`, where `e`
- is the first element
- in the sequence, is
- a valid expression.] [Constant]]
- [[`__at__<M>(s)`] [Any type] [] [Constant]]
- [[`__at__<M>(s) = o`] [Any type] [`s` is mutable and
- `e = o`, where `e`
- is the first element
- in the sequence, is
- a valid expression.] [Constant]]
- ]
- [heading Result Type Expressions]
- [table
- [[Expression] [Compile Time Complexity]]
- [[`__result_of_begin__<S>::type`] [Amortized constant time]]
- [[`__result_of_end__<S>::type`] [Amortized constant time]]
- [[`__result_of_at__<S, M>::type`] [Amortized constant time]]
- [[`__result_of_at_c__<S, N>::type`] [Amortized constant time]]
- [[`__result_of_value_at__<S, M>::type`] [Amortized constant time]]
- [[`__result_of_value_at_c__<S, N>::type`] [Amortized constant time]]
- ]
- [note `__result_of_at__<S, M>` returns the actual type returned by
- `__at__<M>(s)`. In most cases, this is a reference. Hence, there is no way to
- know the exact element type using `__result_of_at__<S, M>`.The element at `M`
- may actually be a reference to begin with. For this purpose, you can use
- `__result_of_value_at__<S, M>` (Note that, `__result_of_value_at_c__<S, N>`
- is a counterpart of `__result_of_at_c__<S, N>` as well).]
- [heading Expression Semantics]
- The semantics of an expression are defined only where they differ from, or
- are not defined in __bidirectional_sequence__.
- [table
- [[Expression] [Semantics]]
- [[`__at__<M>(s)`] [The Mth element from the beginning of the sequence; see __at__.]]
- [[`__at_c__<N>(s)`] [The Nth element from the beginning of the sequence; see __at_c__.]]
- ]
- [heading Models]
- * __std_pair__
- * __boost_array__
- * __vector__
- * __map__
- * __reverse_view__
- * __single_view__
- * __iterator_range__ (where adapted sequence is a Random Access Sequence)
- * __transform_view__ (where adapted sequence is a Random Access Sequence)
- * __zip_view__ (where adapted sequences are models of Random Access Sequence)
- [endsect]
- [section Associative Sequence]
- [heading Description]
- An Associative Sequence allows efficient retrieval of elements based on keys.
- Like associative sequences in __mpl__, and unlike associative containers in
- __stl__, Fusion associative sequences have no implied ordering relation.
- Instead, type identity is used to impose an equivalence relation on keys.
- Keys are not checked for uniqueness.
- [variablelist Notation
- [[`s`] [An Associative Sequence]]
- [[`S`] [An Associative Sequence type]]
- [[`K`] [An arbitrary /key/ type]]
- [[`o`] [An arbitrary object]]
- [[`e`] [A Sequence element]]
- ]
- [heading Valid Expressions]
- For any Associative Sequence the following expressions must be valid:
- [table
- [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
- [[`__has_key__<K>(s)`] [__mpl_boolean_constant__.
- Convertible to bool.] [] [Constant]]
- [[`__at_key__<K>(s)`] [Any type] [] [Constant]]
- [[`__at_key__<K>(s) = o`] [Any type] [`s` is mutable and
- `e = o`, where `e`
- is the first element
- in the sequence, is
- a valid expression.] [Constant]]
- ]
- [heading Result Type Expressions]
- [table
- [[Expression] [Compile Time Complexity]]
- [[`__result_of_has_key__<S, K>::type`] [Amortized constant time]]
- [[`__result_of_at_key__<S, K>::type`] [Amortized constant time]]
- [[`__result_of_value_at_key__<S, K>::type`] [Amortized constant time]]
- ]
- [note `__result_of_at_key__<S, K>` returns the actual type returned
- by `__at_key__<K>(s)`. In most cases, this is a reference. Hence, there is no
- way to know the exact element type using `__result_of_at_key__<S, K>`.The
- element at `K` may actually be a reference to begin with. For this purpose,
- you can use `__result_of_value_at_key__<S, K>`.]
- [heading Expression Semantics]
- [table
- [[Expression] [Semantics]]
- [[`__has_key__<K>(s)`] [A boolean Integral Constant `c` such that
- `c::value == true` if and only if there is
- one or more elements with the key `k` in `s`;
- see __has_key__.]]
- [[`__at_key__<K>(s)`] [The element associated with the key
- `K` in the sequence `s`; see __at__.]]
- ]
- [heading Models]
- * __set__
- * __map__
- * __filter_view__ (where adapted sequence is an __associative_sequence__ and a __forward_sequence__)
- * __iterator_range__ (where adapted iterators are __associative_iterator__\ s)
- * __joint_view__ (where adapted sequences are __associative_sequence__\ s and __forward_sequence__\ s)
- * __reverse_view__ (where adapted sequence is an __associative_sequence__ and a __bidirectional_sequence__)
- [endsect]
- [section Unbounded Sequence]
- [heading Description]
- A Unbounded Sequence allows Out-of-Bounds access: it will achieve something like a __window_function__.
- Most of the sequences do not meet this concept, but some special usecases do.
- [important User extending sequences should handle any parameters or be SFINAE-friendly.]
- [variablelist Notation
- [[`s`] [An Fusion Sequence]]
- [[`S`] [An Fusion Sequence type]]
- [[`M`] [An __mpl__ integral constant]]
- [[`N`] [An integral constant]]
- [[`K`] [An arbitrary /key/ type]]
- [[`o`] [An arbitrary object]]
- [[`e`] [A Sequence element]]
- ]
- [heading Valid Expressions]
- [table
- [[Expression] [Return type] [Type Requirements] [Runtime Complexity]]
- [[`__at_c__<N>(s)`] [Any type] [] [Depends on its traversability]]
- [[`__at_c__<N>(s) = o`] [Any type] [] [Depends on its traversability]]
- [[`__at__<M>(s)`] [Any type] [] [Depends on its traversability]]
- [[`__at__<M>(s) = o`] [Any type] [] [Depends on its traversability]]
- [[`__at_key__<K>(s)`] [Any type] [`S` should be __associative_sequence__] [Depends on its traversability]]
- [[`__at_key__<K>(s) = o`] [Any type] [`S` should be __associative_sequence__] [Depends on its traversability]]
- ]
- [heading Result Type Expressions]
- [table
- [[Expression] [Compile Time Complexity]]
- [[`__result_of_at__<S, M>::type`] [Depends on its traversability]]
- [[`__result_of_at_c__<S, N>::type`] [Depends on its traversability]]
- [[`__result_of_value_at__<S, M>::type`] [Depends on its traversability]]
- [[`__result_of_value_at_c__<S, N>::type`] [Depends on its traversability]]
- [[`__result_of_at_key__<S, K>::type`] [Depends on its traversability]]
- [[`__result_of_value_at_key__<S, K>::type`] [Depends on its traversability]]
- ]
- [heading Models]
- * none.
- [endsect]
- [endsect]
- [section Intrinsic]
- Intrinsic form the essential interface of every Fusion __sequence__. __stl__
- counterparts of these functions are usually implemented as member
- functions. Intrinsic functions, unlike __algorithms__, are not generic
- across the full __sequence__ repertoire. They need to be implemented for
- each Fusion __sequence__[footnote In practice, many of intrinsic functions
- have default implementations that will work in majority of cases].
- [heading Header]
- #include <boost/fusion/sequence/intrinsic.hpp>
- #include <boost/fusion/include/intrinsic.hpp>
- [section Functions]
- [section begin]
- [heading Description]
- Returns an iterator pointing to the first element in the sequence.
- [heading Synopsis]
- template <typename Sequence>
- typename __result_of_begin__<Sequence>::type
- begin(Sequence& seq);
- template <typename Sequence>
- typename __result_of_begin__<Sequence const>::type
- begin(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __forward_sequence__] [The sequence we wish to get an iterator from.]]
- ]
- [heading Expression Semantics]
- begin(seq);
- [*Return type]:
- * A model of __forward_iterator__ if `seq` is a __forward_sequence__
- else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
- else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
- * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
- [*Semantics]: Returns an iterator pointing to the first element in the sequence.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/begin.hpp>
- #include <boost/fusion/include/begin.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(__deref__(begin(v)) == 1);
- [endsect]
- [section end]
- [heading Description]
- Returns an iterator pointing to one element past the end of the sequence.
- [heading Synopsis]
- template <typename Sequence>
- typename __result_of_end__<Sequence>::type
- end(Sequence& seq);
- template <typename Sequence>
- typename __result_of_end__<Sequence const>::type
- end(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __forward_sequence__] [The sequence we wish to get an iterator from.]]
- ]
- [heading Expression Semantics]
- end(seq);
- [*Return type]:
- * A model of __forward_iterator__ if `seq` is a __forward_sequence__
- else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
- else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
- * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
- [*Semantics]: Returns an iterator pointing to one element past the end of
- the sequence.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/end.hpp>
- #include <boost/fusion/include/end.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(__deref__(__prior__(end(v))) == 3);
- [endsect]
- [section empty]
- [heading Description]
- Returns a type convertible to `bool` that evaluates to `true` if the
- sequence is empty, else, evaluates to `false`.
- [heading Synopsis]
- template <typename Sequence>
- typename __result_of_empty__<Sequence>::type
- empty(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __forward_sequence__] [The sequence we wish to investigate.]]
- ]
- [heading Expression Semantics]
- empty(seq);
- [*Return type]: Convertible to `bool`.
- [*Semantics]: Evaluates to `true` if the sequence is empty, else, evaluates
- to `false`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/empty.hpp>
- #include <boost/fusion/include/empty.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(empty(v) == false);
- [endsect]
- [section front]
- [heading Description]
- Returns the first element in the sequence.
- [heading Synopsis]
- template <typename Sequence>
- typename __result_of_front__<Sequence>::type
- front(Sequence& seq);
- template <typename Sequence>
- typename __result_of_front__<Sequence const>::type
- front(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __forward_sequence__] [The sequence we wish to investigate.]]
- ]
- [heading Expression Semantics]
- front(seq);
- [*Return type]: Returns a reference to the first element in the sequence
- `seq` if `seq` is mutable and `e = o`, where `e` is the first element in
- the sequence, is a valid expression. Else, returns a type convertible to
- the first element in the sequence.
- [*Precondition]: `__empty__(seq) == false`
- [*Semantics]: Returns the first element in the sequence.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/front.hpp>
- #include <boost/fusion/include/front.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(front(v) == 1);
- [endsect]
- [section back]
- [heading Description]
- Returns the last element in the sequence.
- [heading Synopsis]
- template <typename Sequence>
- typename __result_of_back__<Sequence>::type
- back(Sequence& seq);
- template <typename Sequence>
- typename __result_of_back__<Sequence const>::type
- back(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __bidirectional_sequence__] [The sequence we wish to investigate.]]
- ]
- [heading Expression Semantics]
- back(seq);
- [*Return type]: Returns a reference to the last element in the sequence
- `seq` if `seq` is mutable and `e = o`, where `e` is the last element in the
- sequence, is a valid expression. Else, returns a type convertible to the
- last element in the sequence.
- [*Precondition]: `__empty__(seq) == false`
- [*Semantics]: Returns the last element in the sequence.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/back.hpp>
- #include <boost/fusion/include/back.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(back(v) == 3);
- [endsect]
- [section size]
- [heading Description]
- Returns a type convertible to `int` that evaluates the number of elements
- in the sequence.
- [heading Synopsis]
- template <typename Sequence>
- typename __result_of_size__<Sequence>::type
- size(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __forward_sequence__] [The sequence we wish to investigate.]]
- ]
- [heading Expression Semantics]
- size(seq);
- [*Return type]: Convertible to `int`.
- [*Semantics]: Returns the number of elements in the sequence.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/size.hpp>
- #include <boost/fusion/include/size.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(size(v) == 3);
- [endsect]
- [section at]
- [heading Description]
- Returns the M-th element from the beginning of the sequence.
- [heading Synopsis]
- template <typename M, typename Sequence>
- typename __result_of_at__<Sequence, N>::type
- at(Sequence& seq);
- template <typename M, typename Sequence>
- typename __result_of_at__<Sequence const, N>::type
- at(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __random_access_sequence__] [The sequence we wish to investigate.]]
- [[`M`] [An __mpl_integral_constant__] [An index from the beginning of the
- sequence.]]
- ]
- [heading Expression Semantics]
- at<M>(seq);
- [*Return type]: Returns a reference to the M-th element from the beginning
- of the sequence `seq` if `seq` is mutable and `e = o`, where `e` is the M-th
- element from the beginning of the sequence, is a valid expression. Else,
- returns a type convertible to the M-th element from the beginning of the
- sequence.
- [*Precondition]: `0 <= M::value < __size__(seq)` (where `seq` is not __unbounded_sequence__)
- [*Semantics]: Equivalent to
- __deref__(__advance__<M>(__begin__(s)))
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/at.hpp>
- #include <boost/fusion/include/at.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(at<mpl::int_<1> >(v) == 2);
- [endsect]
- [section at_c]
- [heading Description]
- Returns the N-th element from the beginning of the sequence.
- [heading Synopsis]
- template <int N, typename Sequence>
- typename __result_of_at_c__<Sequence, N>::type
- at_c(Sequence& seq);
- template <int N, typename Sequence>
- typename __result_of_at_c__<Sequence const, N>::type
- at_c(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __random_access_sequence__] [The sequence we wish to investigate.]]
- [[`N`] [An integral constant] [An index from the beginning of the
- sequence.]]
- ]
- [heading Expression Semantics]
- at_c<N>(seq);
- [*Return type]: Returns a reference to the N-th element from the beginning
- of the sequence `seq` if `seq` is mutable and `e = o`, where `e` is the N-th
- element from the beginning of the sequence, is a valid expression. Else,
- returns a type convertible to the N-th element from the beginning of the
- sequence.
- [*Precondition]: `0 <= N < __size__(seq)` (where `seq` is not __unbounded_sequence__)
- [*Semantics]: Equivalent to
- __deref__(__advance__<N>(__begin__(s)))
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/at_c.hpp>
- #include <boost/fusion/include/at_c.hpp>
- [heading Example]
- __vector__<int, int, int> v(1, 2, 3);
- assert(at_c<1>(v) == 2);
- [endsect]
- [section has_key]
- [heading Description]
- Returns a type convertible to `bool` that evaluates to `true` if the
- sequence contains an element associated with a Key, else, evaluates to
- `false`.
- [heading Synopsis]
- template <typename Key, typename Sequence>
- typename __result_of_has_key__<Sequence, Key>::type
- has_key(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __associative_sequence__] [The sequence we wish to investigate.]]
- [[`Key`] [Any type] [The queried key.]]
- ]
- [heading Expression Semantics]
- has_key<Key>(seq);
- [*Return type]: Convertible to `bool`.
- [*Semantics]: Evaluates to `true` if the sequence contains an element
- associated with Key, else, evaluates to `false`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/has_key.hpp>
- #include <boost/fusion/include/has_key.hpp>
- [heading Example]
- __set__<int, char, bool> s(1, 'x', true);
- assert(has_key<char>(s) == true);
- [endsect]
- [section at_key]
- [heading Description]
- Returns the element associated with a Key from the sequence.
- [heading Synopsis]
- template <typename Key, typename Sequence>
- typename __result_of_at_key__<Sequence, Key>::type
- at_key(Sequence& seq);
- template <typename Key, typename Sequence>
- typename __result_of_at_key__<Sequence const, Key>::type
- at_key(Sequence const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Model of __associative_sequence__] [The sequence we wish to investigate.]]
- [[`Key`] [Any type] [The queried key.]]
- ]
- [heading Expression Semantics]
- at_key<Key>(seq);
- [*Return type]: Returns a reference to the element associated with Key from
- the sequence `seq` if `seq` is mutable and `e = o`, where `e` is the
- element associated with Key, is a valid expression. Else, returns a type
- convertible to the element associated with Key.
- [*Precondition]: `has_key<Key>(seq) == true` (where `seq` is not __unbounded_sequence__)
- [*Semantics]: Returns the element associated with Key.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/at_key.hpp>
- #include <boost/fusion/include/at_key.hpp>
- [heading Example]
- __set__<int, char, bool> s(1, 'x', true);
- assert(at_key<char>(s) == 'x');
- [endsect]
- [section swap]
- [heading Description]
- Performs an element by element swap of the elements in 2 sequences.
- [heading Synopsis]
- template<typename Seq1, typename Seq2>
- typename __result_of_swap__<Seq1, Seq2>::type
- swap(Seq1& seq1, Seq2& seq2);
- [heading Parameters]
- [table
- [[Parameters] [Requirement] [Description]]
- [[`seq1`, `seq2`][Models of __forward_sequence__][The sequences whose elements we wish to swap.]]
- ]
- [heading Expression Semantics]
- swap(seq1, seq2);
- [*Return type]: `void`
- [*Precondition]: `__size__(seq1) == __size__(seq2)`
- [*Semantics]: Calls `swap(a1, b1)` for corresponding elements in `seq1` and `seq2`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/swap.hpp>
- #include <boost/fusion/include/swap.hpp>
- [heading Example]
- __vector__<int, std::string> v1(1, "hello"), v2(2, "world");
- swap(v1, v2);
- assert(v1 == __make_vector__(2, "world"));
- assert(v2 == __make_vector__(1, "hello"));
- [endsect]
- [endsect]
- [section Metafunctions]
- [section begin]
- [heading Description]
- Returns the result type of __begin__.
- [heading Synopsis]
- template<typename Seq>
- struct begin
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __forward_sequence__][Argument sequence]]
- ]
- [heading Expression Semantics]
- result_of::begin<Seq>::type
- [*Return type]:
- * A model of __forward_iterator__ if `seq` is a __forward_sequence__
- else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
- else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
- * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
- [*Semantics]: Returns the type of an iterator to the first element of `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/begin.hpp>
- #include <boost/fusion/include/begin.hpp>
- [heading Example]
- typedef __vector__<int> vec;
- typedef __result_of_begin__<vec>::type it;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_deref__<it>::type, int&>))
- [endsect]
- [section end]
- [heading Description]
- Returns the result type of __end__.
- [heading Synopsis]
- template<typename Seq>
- struct end
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __forward_sequence__][Argument sequence]]
- ]
- [heading Expression Semantics]
- result_of::end<Seq>::type
- [*Return type]:
- * A model of __forward_iterator__ if `seq` is a __forward_sequence__
- else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
- else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
- * A model of __associative_iterator__ if `seq` is an __associative_sequence__.
- [*Semantics]: Returns the type of an iterator one past the end of `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/end.hpp>
- #include <boost/fusion/include/end.hpp>
- [heading Example]
- typedef __vector__<int> vec;
- typedef __result_of_prior__<__result_of_end__<vec>::type>::type first;
- BOOST_MPL_ASSERT((__result_of_equal_to__<first, __result_of_begin__<vec>::type>))
- [endsect]
- [section empty]
- [heading Description]
- Returns the result type of __empty__.
- [heading Synopsis]
- template<typename Seq>
- struct empty
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __forward_sequence__][Argument sequence]]
- ]
- [heading Expression Semantics]
- result_of::empty<Seq>::type
- [*Return type]: An __mpl_integral_constant__
- [*Semantics]: Returns `mpl::true_` if `Seq` has zero elements, `mpl::false_` otherwise.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/empty.hpp>
- #include <boost/fusion/include/empty.hpp>
- [heading Example]
- typedef __vector__<> empty_vec;
- typedef __vector__<int,float,char> vec;
- BOOST_MPL_ASSERT((__result_of_empty__<empty_vec>));
- BOOST_MPL_ASSERT_NOT((__result_of_empty__<vec>));
- [endsect]
- [section front]
- [heading Description]
- Returns the result type of __front__.
- [heading Synopsis]
- template<typename Seq>
- struct front
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __forward_sequence__][Argument sequence]]
- ]
- [heading Expression Semantics]
- result_of::front<Seq>::type
- [*Return type]: Any type
- [*Semantics]: The type returned by dereferencing an iterator to the first element in `Seq`. Equivalent to `__result_of_deref__<__result_of_begin__<Seq>::type>::type`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/front.hpp>
- #include <boost/fusion/include/front.hpp>
- [heading Example]
- typedef __vector__<int,char> vec;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_front__<vec>::type, int&>));
- [endsect]
- [section back]
- [heading Description]
- Returns the result type of __back__.
- [heading Synopsis]
- template<typename Seq>
- struct back
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __forward_sequence__][Argument sequence]]
- ]
- [heading Expression Semantics]
- result_of::back<Seq>::type
- [*Return type]: Any type
- [*Semantics]: The type returned by dereferencing an iterator to the last element in the sequence. Equivalent to `__result_of_deref__<__result_of_prior__<__result_of_end__<Seq>::type>::type>::type`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/back.hpp>
- #include <boost/fusion/include/back.hpp>
- [heading Example]
- typedef __vector__<int,char> vec;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_back__<vec>::type, char&>));
- [endsect]
- [section size]
- [heading Description]
- Returns the result type of __size__.
- [heading Synopsis]
- template<typename Seq>
- struct size
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __forward_sequence__][Argument sequence]]
- ]
- [heading Expression Semantics]
- result_of::size<Seq>::type
- [*Return type]: An __mpl_integral_constant__.
- [*Semantics]: Returns the number of elements in `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/size.hpp>
- #include <boost/fusion/include/size.hpp>
- [heading Example]
- typedef __vector__<int,float,char> vec;
- typedef __result_of_size__<vec>::type size_mpl_integral_constant;
- BOOST_MPL_ASSERT_RELATION(size_mpl_integral_constant::value, ==, 3);
- [endsect]
- [section at]
- [heading Description]
- Returns the result type of __at__[footnote __result_of_at__ reflects the
- actual return type of the function __at__. __sequence__(s) typically return
- references to its elements via the __at__ function. If you want to get
- the actual element type, use __result_of_value_at__].
- [heading Synopsis]
- template<
- typename Seq,
- typename M>
- struct at
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
- [[`M`][An __mpl_integral_constant__][Index of element]]
- ]
- [heading Expression Semantics]
- result_of::at<Seq, M>::type
- [*Return type]: Any type.
- [*Precondition]: `0 <= M::value < __result_of_size__<Seq>::value` (where `Seq` is not __unbounded_sequence__)
- [*Semantics]: Returns the result type of using __at__ to access the `M`th element of `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/at.hpp>
- #include <boost/fusion/include/at.hpp>
- [heading Example]
- typedef __vector__<int,float,char> vec;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_at__<vec, boost::mpl::int_<1> >::type, float&>));
- [endsect]
- [section at_c]
- [heading Description]
- Returns the result type of __at_c__[footnote __result_of_at_c__ reflects
- the actual return type of the function __at_c__. __sequence__(s) typically
- return references to its elements via the __at_c__ function. If you want to
- get the actual element type, use __result_of_value_at_c__].
- [heading Synopsis]
- template<
- typename Seq,
- int N>
- struct at_c
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
- [[`N`][Positive integer index][Index of element]]
- ]
- [heading Expression Semantics]
- result_of::at_c<Seq, N>::type
- [*Return type]: Any type
- [*Precondition]: `0 <= N < __result_of_size__<Seq>::value` (where `Seq` is not __unbounded_sequence__)
- [*Semantics]: Returns the result type of using __at_c__ to access the `N`th element of `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/at.hpp>
- #include <boost/fusion/include/at.hpp>
- [heading Example]
- typedef __vector__<int,float,char> vec;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_at_c__<vec, 1>::type, float&>));
- [endsect]
- [section value_at]
- [heading Description]
- Returns the actual type at a given index from the __sequence__.
- [heading Synopsis]
- template<
- typename Seq,
- typename M>
- struct value_at
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
- [[`M`][An __mpl_integral_constant__][Index of element]]
- ]
- [heading Expression Semantics]
- result_of::value_at<Seq, M>::type
- [*Return type]: Any type.
- [*Semantics]: Returns the actual type at the `M`th element of `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/value_at.hpp>
- #include <boost/fusion/include/value_at.hpp>
- [heading Example]
- typedef __vector__<int,float,char> vec;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at__<vec, boost::mpl::int_<1> >::type, float>));
- [endsect]
- [section value_at_c]
- [heading Description]
- Returns the actual type at a given index from the __sequence__.
- [heading Synopsis]
- template<
- typename Seq,
- int N>
- struct value_at_c
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __random_access_sequence__][Argument sequence]]
- [[`N`][Positive integer index][Index of element]]
- ]
- [heading Expression Semantics]
- result_of::value_at_c<Seq, N>::type
- [*Return type]: Any type
- [*Semantics]: Returns the actual type at the `N`th element of `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/value_at.hpp>
- #include <boost/fusion/include/value_at.hpp>
- [heading Example]
- typedef __vector__<int,float,char> vec;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at_c__<vec, 1>::type, float>));
- [endsect]
- [section has_key]
- [heading Description]
- Returns the result type of __has_key__.
- [heading Synopsis]
- template<
- typename Seq,
- typename Key>
- struct has_key
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __associative_sequence__][Argument sequence]]
- [[`Key`][Any type][Key type]]
- ]
- [heading Expression Semantics]
- result_of::has_key<Seq, Key>::type
- [*Return type]: An __mpl_integral_constant__.
- [*Semantics]: Returns `mpl::true_` if `Seq` contains an element with key type `Key`, returns `mpl::false_` otherwise.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/has_key.hpp>
- #include <boost/fusion/include/has_key.hpp>
- [heading Example]
- typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
- BOOST_MPL_ASSERT((__result_of_has_key__<mymap, int>));
- BOOST_MPL_ASSERT_NOT((__result_of_has_key__<mymap, void*>));
- [endsect]
- [section at_key]
- [heading Description]
- Returns the result type of __at_key__[footnote __result_of_at_key__
- reflects the actual return type of the function __at_key__. __sequence__(s)
- typically return references to its elements via the __at_key__ function. If
- you want to get the actual element type, use __result_of_value_at_key__].
- [heading Synopsis]
- template<
- typename Seq,
- typename Key>
- struct at_key
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __associative_sequence__][Argument sequence]]
- [[`Key`][Any type][Key type]]
- ]
- [heading Expression Semantics]
- result_of::at_key<Seq, Key>::type
- [*Return type]: Any type.
- [*Precondition]: `has_key<Seq, Key>::type::value == true` (where `Seq` is not __unbounded_sequence__)
- [*Semantics]: Returns the result of using __at_key__ to access the element with key type `Key` in `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/at_key.hpp>
- #include <boost/fusion/include/at_key.hpp>
- [heading Example]
- typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_at_key__<mymap, int>::type, char&>));
- [endsect]
- [section value_at_key]
- [heading Description]
- Returns the actual element type associated with a Key from the __sequence__.
- [heading Synopsis]
- template<
- typename Seq,
- typename Key>
- struct value_at_key
- {
- typedef __unspecified__ type;
- };
- [table Parameters
- [[Parameter] [Requirement] [Description]]
- [[`Seq`][A model of __associative_sequence__][Argument sequence]]
- [[`Key`][Any type][Key type]]
- ]
- [heading Expression Semantics]
- result_of::value_at_key<Seq, Key>::type
- [*Return type]: Any type.
- [*Precondition]: `has_key<Seq, Key>::type::value == true` (where `Seq` is not __unbounded_sequence__)
- [*Semantics]: Returns the actual element type associated with key type
- `Key` in `Seq`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
- #include <boost/fusion/include/value_at_key.hpp>
- [heading Example]
- typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
- BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at_key__<mymap, int>::type, char>));
- [endsect]
- [section swap]
- [heading Description]
- Returns the return type of swap.
- [heading Synopsis]
- template<typename Seq1, typename Seq2>
- struct swap
- {
- typedef void type;
- };
- [table Parameters
- [[Parameters] [Requirement] [Description]]
- [[`Seq1`, `Seq2`][Models of __forward_sequence__][The sequences being swapped]]
- ]
- [heading Expression Semantics]
- result_of::swap<Seq1, Seq2>::type
- [*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence.
- Otherwise, none.
- [*Semantics]: Returns the return type of __swap__ for 2 sequences of types `Seq1` and `Seq2`.
- [heading Header]
- #include <boost/fusion/sequence/intrinsic/swap.hpp>
- #include <boost/fusion/include/swap.hpp>
- [endsect]
- [endsect]
- [endsect]
- [section Operator]
- These operators, like the __algorithms__, work generically on all Fusion
- sequences. All conforming Fusion sequences automatically get these
- operators for free.
- [section I/O]
- The I/O operators: `<<` and `>>` work generically on all Fusion
- sequences. The I/O operators are overloaded in namespace `boost::fusion`
- [footnote __sequence__(s) and __views__ residing in different namespaces
- will have to either provide their own I/O operators (possibly forwarding
- to fusion's I/O operators) or hoist fusion's I/O operators (using
- declaration), in their own namespaces for proper argument dependent
- lookup.]
- The `operator<<` has been overloaded for generic output streams such
- that __sequence__(s) are output by recursively calling `operator<<` for
- each element. Analogously, the global `operator>>` has been overloaded
- to extract __sequence__(s) from generic input streams by recursively
- calling `operator>>` for each element.
- Please note that, to display your adapted types via fusion IO system,
- corresponding overloaded operators should be introduced to same namespace
- of the type.
- namespace your_awesome_library
- {
- using boost::fusion::operators::operator>>; // for input
- using boost::fusion::operators::operator<<; // for output
- ...
- The default delimiter between the elements is space, and the __sequence__
- is enclosed in parenthesis. For Example:
- __vector__<float, int, std::string> a(1.0f, 2, std::string("Howdy folks!");
- cout << a;
- outputs the __vector__ as: (1.0 2 Howdy folks!)
- The library defines three manipulators for changing the default behavior:
- [variablelist Manipulators
- [[`tuple_open(arg)`] [Defines the character that is output before the first element.]]
- [[`tuple_close(arg)`] [Defines the character that is output after the last element.]]
- [[`tuple_delimiter(arg)`] [Defines the delimiter character between elements.]]
- ]
- The argument to `tuple_open`, `tuple_close` and `tuple_delimiter` may be a
- `char`, `wchar_t`, a C-string, or a wide C-string.
- Example:
- std::cout << tuple_open('[') << tuple_close(']') << tuple_delimiter(", ") << a;
- outputs the same __vector__, `a` as: [1.0, 2, Howdy folks!]
- The same manipulators work with `operator>>` and `istream` as well. Suppose
- the `std::cin` stream contains the following data:
- (1 2 3) [4:5]
- The code:
- __vector__<int, int, int> i;
- __vector__<int, int> j;
- std::cin >> i;
- std::cin >> tuple_open('[') >> tuple_close(']') >> tuple_delimiter(':');
- std::cin >> j;
- reads the data into the __vector__(s) `i` and `j`.
- Note that extracting __sequence__(s) with `std::string` or C-style string
- elements does not generally work, since the streamed __sequence__
- representation may not be unambiguously parseable.
- [heading Header]
- #include <boost/fusion/sequence/io.hpp>
- #include <boost/fusion/include/io.hpp>
- [section in]
- [heading Description]
- Read a __sequence__ from an input stream.
- [heading Synopsis]
- template <typename IStream, typename Sequence>
- IStream&
- operator>>(IStream& is, Sequence& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[is] [An input stream.] [Stream to extract information from.]]
- [[seq] [A __sequence__.] [The sequence to read.]]
- ]
- [heading Expression Semantics]
- is >> seq
- [*Return type]: IStream&
- [*Semantics]: For each element, `e`, in sequence, `seq`, call `is >> e`.
- [heading Header]
- #include <boost/fusion/sequence/io/in.hpp>
- #include <boost/fusion/include/in.hpp>
- [heading Example]
- __vector__<int, std::string, char> v;
- std::cin >> v;
- [endsect]
- [section out]
- [heading Description]
- Write a __sequence__ to an output stream.
- [heading Synopsis]
- template <typename OStream, typename Sequence>
- OStream&
- operator<<(OStream& os, Sequence& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[os] [An output stream.] [Stream to write information to.]]
- [[seq] [A __sequence__.] [The sequence to write.]]
- ]
- [heading Expression Semantics]
- os << seq
- [*Return type]: OStream&
- [*Semantics]: For each element, `e`, in sequence, `seq`, call `os << e`.
- [heading Header]
- #include <boost/fusion/sequence/io/out.hpp>
- #include <boost/fusion/include/out.hpp>
- [heading Example]
- std::cout << __make_vector__(123, "Hello", 'x') << std::endl;
- [endsect]
- [endsect]
- [section Comparison]
- The Comparison operators: `==`, `!=`, `<`, `<=`, `>=` and `>=` work
- generically on all Fusion sequences. Comparison operators are "short-
- circuited": elementary comparisons start from the first elements and are
- performed only until the result is clear.
- [heading Header]
- #include <boost/fusion/sequence/comparison.hpp>
- #include <boost/fusion/include/comparison.hpp>
- [section equal]
- [heading Description]
- Compare two sequences for equality.
- [heading Synopsis]
- template <typename Seq1, typename Seq2>
- bool
- operator==(Seq1 const& a, Seq2 const& b);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
- ]
- [heading Expression Semantics]
- a == b
- [*Return type]: `bool`
- [*Requirements]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `a == b` is a valid expression returning a type that is
- convertible to bool.
- An attempt to compare two Sequences of different lengths results in a
- compile time error.
- [*Semantics]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `e1 == e2` returns true. For any 2 zero length __sequence__(s),
- e and f, e == f returns true.
- [heading Header]
- #include <boost/fusion/sequence/comparison/equal_to.hpp>
- #include <boost/fusion/include/equal_to.hpp>
- [heading Example]
- __vector__<int, char> v1(5, 'a');
- __vector__<int, char> v2(5, 'a');
- assert(v1 == v2);
- [endsect]
- [section not equal]
- Compare two sequences for inequality.
- [heading Synopsis]
- template <typename Seq1, typename Seq2>
- bool
- operator!=(Seq1 const& a, Seq2 const& b);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
- ]
- [heading Expression Semantics]
- a != b
- [*Return type]: `bool`
- [*Requirements]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `a == b` is a valid expression returning a type that is
- convertible to bool.
- An attempt to compare two Sequences of different lengths results in a
- compile time error.
- [*Semantics]:
- Returns !(a == b).
- [heading Header]
- #include <boost/fusion/sequence/comparison/not_equal_to.hpp>
- #include <boost/fusion/include/not_equal_to.hpp>
- [heading Example]
- __vector__<int, char> v3(5, 'b');
- __vector__<int, char> t4(2, 'a');
- assert(v1 != v3);
- assert(v1 != t4);
- assert(!(v1 != v2));
- [endsect]
- [section less than]
- Lexicographically compare two sequences.
- [heading Synopsis]
- template <typename Seq1, typename Seq2>
- bool
- operator<(Seq1 const& a, Seq2 const& b);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
- ]
- [heading Expression Semantics]
- a < b
- [*Return type]: `bool`
- [*Requirements]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `a < b` is a valid expression returning a type that is
- convertible to bool.
- An attempt to compare two Sequences of different lengths results in a
- compile time error.
- [*Semantics]: Returns the lexicographical comparison of between `a` and `b`.
- [heading Header]
- #include <boost/fusion/sequence/comparison/less.hpp>
- #include <boost/fusion/include/less.hpp>
- [heading Example]
- __vector__<int, float> v1(4, 3.3f);
- __vector__<short, float> v2(5, 3.3f);
- __vector__<long, double> v3(5, 4.4);
- assert(v1 < v2);
- assert(v2 < v3);
- [endsect]
- [section less than equal]
- Lexicographically compare two sequences.
- [heading Synopsis]
- template <typename Seq1, typename Seq2>
- bool
- operator<=(Seq1 const& a, Seq2 const& b);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
- ]
- [heading Expression Semantics]
- a <= b
- [*Return type]: `bool`
- [*Requirements]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `a < b` is a valid expression returning a type that is
- convertible to bool.
- An attempt to compare two Sequences of different lengths results in a
- compile time error.
- [*Semantics]: Returns !(b < a).
- [heading Header]
- #include <boost/fusion/sequence/comparison/less_equal.hpp>
- #include <boost/fusion/include/less_equal.hpp>
- [heading Example]
- __vector__<int, float> v1(4, 3.3f);
- __vector__<short, float> v2(5, 3.3f);
- __vector__<long, double> v3(5, 4.4);
- assert(v1 <= v2);
- assert(v2 <= v3);
- [endsect]
- [section greater than]
- Lexicographically compare two sequences.
- [heading Synopsis]
- template <typename Seq1, typename Seq2>
- bool
- operator>(Seq1 const& a, Seq2 const& b);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
- ]
- [heading Expression Semantics]
- a > b
- [*Return type]: `bool`
- [*Requirements]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `a < b` is a valid expression returning a type that is
- convertible to bool.
- An attempt to compare two Sequences of different lengths results in a
- compile time error.
- [*Semantics]: Returns b < a.
- [heading Header]
- #include <boost/fusion/sequence/comparison/less_equal.hpp>
- #include <boost/fusion/include/less_equal.hpp>
- [heading Example]
- __vector__<int, float> v1(4, 3.3f);
- __vector__<short, float> v2(5, 3.3f);
- __vector__<long, double> v3(5, 4.4);
- assert(v2 > v1);
- assert(v3 > v2);
- [endsect]
- [section greater than equal]
- Lexicographically compare two sequences.
- [heading Synopsis]
- template <typename Seq1, typename Seq2>
- bool
- operator>=(Seq1 const& a, Seq2 const& b);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
- ]
- [heading Expression Semantics]
- a >= b
- [*Return type]: `bool`
- [*Requirements]:
- For each element, `e1`, in sequence `a`, and for each element, `e2`, in
- sequence `b`, `a < b` is a valid expression returning a type that is
- convertible to bool.
- An attempt to compare two Sequences of different lengths results in a
- compile time error.
- [*Semantics]: Returns !(a < b).
- [heading Header]
- #include <boost/fusion/sequence/comparison/greater_equal.hpp>
- #include <boost/fusion/include/greater_equal.hpp>
- [heading Example]
- __vector__<int, float> v1(4, 3.3f);
- __vector__<short, float> v2(5, 3.3f);
- __vector__<long, double> v3(5, 4.4);
- assert(v2 >= v1);
- assert(v3 >= v2);
- [endsect]
- [endsect]
- [section Hashing]
- Automatically create a `boost::hash` conforming `hash_value` function.
- [heading Synopsis]
- template <typename Seq>
- std::size_t
- hash_value(Seq const& seq);
- [heading Parameters]
- [table
- [[Parameter] [Requirement] [Description]]
- [[`seq`] [Instance of __sequence__] [__sequence__ to compute hash value of]]
- ]
- [*Return type]: `std::size_t`
- [*Requirements]:
- For each element `e` in sequence `seq`, `hash_value(seq)` is a valid expression
- returning a type that is convertible to `std::size_t`.
- [*Semantics]: Returns a combined hash value for all elements of `seq`.
- [heading Header]
- #include <boost/fusion/sequence/hash.hpp>
- #include <boost/fusion/include/hash.hpp>
- [heading Example]
- #include <boost/fusion/include/equal_to.hpp>
- #include <boost/fusion/include/hash.hpp>
- #include <boost/fusion/include/vector.hpp>
- #include <boost/unordered_map.hpp>
-
- void foo()
- {
- typedef boost::fusion::vector<int, std::string, char> Vec;
- const Vec v = {42, "Hello World", 't'};
- // Compute a hash value directly.
- std::cout << "hash_value(v) = " << boost::fusion::hash_value(v) << '\n';
- // Or use it to create an unordered_map.
- boost::unordered_map<Vec, bool> map;
- map[v] = true;
- assert(map.size() == 1 && map.count(v) == 1);
- }
- [heading Example]
- #include <boost/fusion/include/define_struct.hpp>
- #include <boost/fusion/include/equal_to.hpp>
- #include <boost/fusion/include/hash.hpp>
- #include <boost/unordered_set.hpp>
-
- // We would like to define a struct that we can form unordered_sets of.
- BOOST_FUSION_DEFINE_STRUCT(
- (demo), Key,
- (bool, b)
- (std::string, s)
- (int, i)
- )
-
- namespace demo {
- // Make operator== and hash_value ADL accessible.
- using boost::fusion::operator==;
- using boost::fusion::hash_value;
- typedef boost::unordered_set<demo::Key> Set;
- }
-
- void foo()
- {
- demo::Set set;
- demo::Key key;
- assert(set.count(key) == 0);
- }
- [heading See also]
- __boost_func_hash__
- [endsect]
- [endsect]
- [endsect]
|