2007-11-07 02:12:28 +00:00
[/==============================================================================
2011-10-10 10:37:53 +00:00
Copyright (C) 2001-2011 Joel de Guzman
Copyright (C) 2006 Dan Marsden
2014-07-24 14:22:55 +02:00
Copyright (C) 2014 Christoph Weiss
2007-11-07 02:12:28 +00:00
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)
===============================================================================/]
2007-11-06 10:09:38 +00:00
[section Sequence]
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
Sequence's elements.
[heading Header]
#include <boost/fusion/sequence.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/sequence.hpp>
2006-08-22 15:57:13 +00:00
[section Concepts]
2007-04-10 22:27:41 +00:00
Fusion Sequences are organized into a hierarchy of concepts.
2006-08-22 15:57:13 +00:00
[heading Traversal]
2007-04-10 22:27:41 +00:00
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__.
2006-08-22 15:57:13 +00:00
These concepts pertain to sequence traversal.
[heading Associativity]
2007-04-10 22:27:41 +00:00
The __associative_sequence__ concept is orthogonal to traversal. An Associative
2006-08-22 15:57:13 +00:00
Sequence allows efficient retrieval of elements based on keys.
2015-03-22 09:45:17 +09:00
[heading Boundary]
2015-06-25 22:42:44 +09:00
The __unbounded_sequence__ concept is also orthogonal to traversal and associativity.
A Unbounded Sequence allows out-of-bounds access.
2015-03-22 09:45:17 +09:00
2006-08-22 15:57:13 +00:00
[section Forward Sequence]
[heading Description]
2007-04-10 22:27:41 +00:00
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).
2006-08-22 15:57:13 +00:00
[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
2007-04-10 22:27:41 +00:00
`e = o`, where `e`
is the first element
in the sequence, is
2006-08-22 15:57:13 +00:00
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__.]]
2007-04-10 22:27:41 +00:00
[[`__empty__(s)`] [A boolean Integral Constant `c` such that
`c::value == true` if and only if the sequence
2006-08-22 15:57:13 +00:00
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.
2007-04-10 22:27:41 +00:00
* An __algorithm__ that iterates through the range `[__begin__(s), __end__(s))`
2006-08-22 15:57:13 +00:00
will pass through every element of `s` exactly once.
* `__begin__(s)` is identical to `__end__(s))` if and only if `s` is empty.
2007-04-10 22:27:41 +00:00
* Two different iterations through `s` will access its elements in
2006-08-22 15:57:13 +00:00
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__
2007-06-16 11:56:14 +00:00
* __zip_view__
2006-08-22 15:57:13 +00:00
[endsect]
[section Bidirectional Sequence]
[heading Description]
2007-04-10 22:27:41 +00:00
A Bidirectional Sequence is a __forward_sequence__ whose iterators model
2006-08-22 15:57:13 +00:00
__bidirectional_iterator__.
[heading Refinement of]
__forward_sequence__
[variablelist Notation
2013-05-22 23:28:12 +00:00
[[`s`] [A Bidirectional Sequence]]
[[`S`] [A Bidirectional Sequence type]]
2006-08-22 15:57:13 +00:00
[[`o`] [An arbitrary object]]
[[`e`] [A Sequence element]]
]
[heading Valid Expressions]
2007-04-10 22:27:41 +00:00
In addition to the requirements defined in __forward_sequence__, for any
2006-08-22 15:57:13 +00:00
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
2007-04-10 22:27:41 +00:00
`e = o`, where `e`
2022-09-26 08:11:49 +08:00
is the last element
2007-04-10 22:27:41 +00:00
in the sequence, is
2006-08-22 15:57:13 +00:00
a valid expression.] [Constant]]
]
[heading Result Type Expressions]
2007-04-10 22:27:41 +00:00
[table
2006-08-22 15:57:13 +00:00
[[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]
2007-04-10 22:27:41 +00:00
The semantics of an expression are defined only where they differ from, or
2006-08-22 15:57:13 +00:00
are not defined in __forward_sequence__.
2007-04-10 22:27:41 +00:00
[table
2006-08-22 15:57:13 +00:00
[[Expression] [Semantics]]
[[`__back__(s)`] [The last element in the sequence; see __back__.]]
]
[heading Models]
* __std_pair__
* __boost_array__
* __vector__
2011-10-10 09:55:52 +00:00
* __map__
2007-06-16 11:56:14 +00:00
* __reverse_view__
2011-07-08 19:42:35 +00:00
* __single_view__
2006-08-22 15:57:13 +00:00
* __iterator_range__ (where adapted sequence is a Bidirectional Sequence)
* __transform_view__ (where adapted sequence is a Bidirectional Sequence)
2009-12-11 21:01:22 +00:00
* __zip_view__ (where adapted sequences are models of Bidirectional Sequence)
2006-08-22 15:57:13 +00:00
[endsect]
[section Random Access Sequence]
[heading Description]
2007-04-10 22:27:41 +00:00
A Random Access Sequence is a __bidirectional_sequence__ whose iterators
model __random_access_iterator__. It guarantees constant time access to
arbitrary sequence elements.
2006-08-22 15:57:13 +00:00
[heading Refinement of]
__bidirectional_sequence__
[variablelist Notation
[[`s`] [A Random Access Sequence]]
[[`S`] [A Random Access Sequence type]]
2013-05-22 23:28:12 +00:00
[[`M`] [An __mpl__ integral constant]]
[[`N`] [An integral constant]]
2006-08-22 15:57:13 +00:00
[[`o`] [An arbitrary object]]
[[`e`] [A Sequence element]]
]
[heading Valid Expressions]
2007-04-10 22:27:41 +00:00
In addition to the requirements defined in __bidirectional_sequence__, for
2006-08-22 15:57:13 +00:00
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]]
2013-05-22 23:28:12 +00:00
[[`__at_c__<N>(s)`] [Any type] [] [Constant]]
[[`__at_c__<N>(s) = o`] [Any type] [`s` is mutable and
2007-04-10 22:27:41 +00:00
`e = o`, where `e`
2022-09-26 08:11:49 +08:00
is the N-th element from the beginning
of the sequence, is
2013-05-22 23:28:12 +00:00
a valid expression.] [Constant]]
[[`__at__<M>(s)`] [Any type] [] [Constant]]
[[`__at__<M>(s) = o`] [Any type] [`s` is mutable and
`e = o`, where `e`
2022-09-26 08:11:49 +08:00
is the M-th element from the beginning
of the sequence, is
2013-05-22 23:28:12 +00:00
a valid expression.] [Constant]]
2006-08-22 15:57:13 +00:00
]
[heading Result Type Expressions]
2007-04-10 22:27:41 +00:00
[table
2006-08-22 15:57:13 +00:00
[[Expression] [Compile Time Complexity]]
[[`__result_of_begin__<S>::type`] [Amortized constant time]]
[[`__result_of_end__<S>::type`] [Amortized constant time]]
2015-01-15 17:48:17 +09:00
[[`__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]]
2006-08-22 15:57:13 +00:00
]
2015-02-21 19:58:15 +09:00
[note `__result_of_at__<S, M>` returns the actual type returned by
2015-01-15 17:48:17 +09:00
`__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`
2007-04-10 22:27:41 +00:00
may actually be a reference to begin with. For this purpose, you can use
2015-01-15 17:48:17 +09:00
`__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).]
2006-08-22 15:57:13 +00:00
[heading Expression Semantics]
2007-04-10 22:27:41 +00:00
The semantics of an expression are defined only where they differ from, or
2006-08-22 15:57:13 +00:00
are not defined in __bidirectional_sequence__.
2007-04-10 22:27:41 +00:00
[table
2006-08-22 15:57:13 +00:00
[[Expression] [Semantics]]
2013-05-22 23:28:12 +00:00
[[`__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__.]]
2006-08-22 15:57:13 +00:00
]
[heading Models]
* __std_pair__
* __boost_array__
* __vector__
2011-10-10 09:55:52 +00:00
* __map__
2007-06-16 11:56:14 +00:00
* __reverse_view__
2011-07-08 19:42:35 +00:00
* __single_view__
2006-08-22 15:57:13 +00:00
* __iterator_range__ (where adapted sequence is a Random Access Sequence)
* __transform_view__ (where adapted sequence is a Random Access Sequence)
2009-12-11 21:01:22 +00:00
* __zip_view__ (where adapted sequences are models of Random Access Sequence)
2006-08-22 15:57:13 +00:00
[endsect]
[section Associative Sequence]
[heading Description]
2007-04-10 22:27:41 +00:00
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.
2009-10-30 00:19:19 +00:00
Instead, type identity is used to impose an equivalence relation on keys.
2012-12-13 09:41:50 +00:00
Keys are not checked for uniqueness.
2006-08-22 15:57:13 +00:00
[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
2007-04-10 22:27:41 +00:00
`e = o`, where `e`
2022-09-26 08:11:49 +08:00
is the element associated with K, is
2006-08-22 15:57:13 +00:00
a valid expression.] [Constant]]
]
[heading Result Type Expressions]
2007-04-10 22:27:41 +00:00
[table
2006-08-22 15:57:13 +00:00
[[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]]
]
2015-02-21 19:58:15 +09:00
[note `__result_of_at_key__<S, K>` returns the actual type returned
2007-04-10 22:27:41 +00:00
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,
2015-01-15 17:48:17 +09:00
you can use `__result_of_value_at_key__<S, K>`.]
2006-08-22 15:57:13 +00:00
[heading Expression Semantics]
2007-04-10 22:27:41 +00:00
[table
2006-08-22 15:57:13 +00:00
[[Expression] [Semantics]]
2007-04-10 22:27:41 +00:00
[[`__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`;
2006-08-22 15:57:13 +00:00
see __has_key__.]]
2007-04-10 22:27:41 +00:00
[[`__at_key__<K>(s)`] [The element associated with the key
2006-08-22 15:57:13 +00:00
`K` in the sequence `s`; see __at__.]]
]
[heading Models]
* __set__
* __map__
2009-12-11 21:01:22 +00:00
* __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__)
2022-09-26 08:11:49 +08:00
* __transform_view__ (where adapted sequence is an __associative_sequence__ and a __forward_sequence__)
2006-08-22 15:57:13 +00:00
[endsect]
2015-06-25 22:42:44 +09:00
[section Unbounded Sequence]
2015-03-22 09:45:17 +09:00
[heading Description]
2015-06-25 22:42:44 +09:00
A Unbounded Sequence allows Out-of-Bounds access: it will achieve something like a __window_function__.
2015-03-22 09:45:17 +09:00
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]
2006-08-22 15:57:13 +00:00
[endsect]
2007-11-06 10:09:38 +00:00
[section Intrinsic]
2006-08-22 15:57:13 +00:00
2007-11-06 10:09:38 +00:00
Intrinsic form the essential interface of every Fusion __sequence__. __stl__
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
have default implementations that will work in majority of cases].
[heading Header]
#include <boost/fusion/sequence/intrinsic.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/intrinsic.hpp>
2006-08-22 15:57:13 +00:00
[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);
2009-10-30 00:19:19 +00:00
[*Return type]:
* A model of __forward_iterator__ if `seq` is a __forward_sequence__
2007-04-10 22:27:41 +00:00
else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
2006-08-22 15:57:13 +00:00
else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
2009-10-30 00:19:19 +00:00
* A model of __associative_iterator__ if `seq` is an __associative_sequence__.
2006-08-22 15:57:13 +00:00
[*Semantics]: Returns an iterator pointing to the first element in the sequence.
[heading Header]
#include <boost/fusion/sequence/intrinsic/begin.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/begin.hpp>
2006-08-22 15:57:13 +00:00
[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);
2009-10-30 00:19:19 +00:00
[*Return type]:
* A model of __forward_iterator__ if `seq` is a __forward_sequence__
2007-04-10 22:27:41 +00:00
else, __bidirectional_iterator__ if `seq` is a __bidirectional_sequence__
2006-08-22 15:57:13 +00:00
else, __random_access_iterator__ if `seq` is a __random_access_sequence__.
2009-10-30 00:19:19 +00:00
* A model of __associative_iterator__ if `seq` is an __associative_sequence__.
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
[*Semantics]: Returns an iterator pointing to one element past the end of
2006-08-22 15:57:13 +00:00
the sequence.
[heading Header]
#include <boost/fusion/sequence/intrinsic/end.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/end.hpp>
2006-08-22 15:57:13 +00:00
[heading Example]
__vector__<int, int, int> v(1, 2, 3);
assert(__deref__(__prior__(end(v))) == 3);
[endsect]
[section empty]
[heading Description]
2007-04-10 22:27:41 +00:00
Returns a type convertible to `bool` that evaluates to `true` if the
2006-08-22 15:57:13 +00:00
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`.
2007-04-10 22:27:41 +00:00
[*Semantics]: Evaluates to `true` if the sequence is empty, else, evaluates
2006-08-22 15:57:13 +00:00
to `false`.
[heading Header]
#include <boost/fusion/sequence/intrinsic/empty.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/empty.hpp>
2006-08-22 15:57:13 +00:00
[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);
2007-04-10 22:27:41 +00:00
[*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
2014-11-07 18:34:18 +01:00
the sequence, is a valid expression. Else, returns a type convertible to
2006-08-22 15:57:13 +00:00
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>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/front.hpp>
2006-08-22 15:57:13 +00:00
[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);
2007-04-10 22:27:41 +00:00
[*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
2014-11-07 18:34:18 +01:00
sequence, is a valid expression. Else, returns a type convertible to the
2006-08-22 15:57:13 +00:00
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>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/back.hpp>
2006-08-22 15:57:13 +00:00
[heading Example]
__vector__<int, int, int> v(1, 2, 3);
assert(back(v) == 3);
[endsect]
[section size]
[heading Description]
2007-04-10 22:27:41 +00:00
Returns a type convertible to `int` that evaluates the number of elements
2006-08-22 15:57:13 +00:00
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>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/size.hpp>
2006-08-22 15:57:13 +00:00
[heading Example]
__vector__<int, int, int> v(1, 2, 3);
assert(size(v) == 3);
[endsect]
[section at]
[heading Description]
2013-05-22 23:28:12 +00:00
Returns the M-th element from the beginning of the sequence.
2006-08-22 15:57:13 +00:00
[heading Synopsis]
2013-05-22 23:28:12 +00:00
template <typename M, typename Sequence>
2022-09-26 08:11:49 +08:00
typename __result_of_at__<Sequence, M>::type
2006-08-22 15:57:13 +00:00
at(Sequence& seq);
2013-05-22 23:28:12 +00:00
template <typename M, typename Sequence>
2022-09-26 08:11:49 +08:00
typename __result_of_at__<Sequence const, M>::type
2006-08-22 15:57:13 +00:00
at(Sequence const& seq);
[heading Parameters]
[table
[[Parameter] [Requirement] [Description]]
[[`seq`] [Model of __random_access_sequence__] [The sequence we wish to investigate.]]
2013-05-22 23:28:12 +00:00
[[`M`] [An __mpl_integral_constant__] [An index from the beginning of the
2006-08-22 15:57:13 +00:00
sequence.]]
]
[heading Expression Semantics]
2013-05-22 23:28:12 +00:00
at<M>(seq);
2006-08-22 15:57:13 +00:00
2013-05-22 23:28:12 +00:00
[*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
2007-04-10 22:27:41 +00:00
element from the beginning of the sequence, is a valid expression. Else,
2014-11-07 18:34:18 +01:00
returns a type convertible to the M-th element from the beginning of the
2006-08-22 15:57:13 +00:00
sequence.
2015-06-25 22:42:44 +09:00
[*Precondition]: `0 <= M::value < __size__(seq)` (where `seq` is not __unbounded_sequence__)
2006-08-22 15:57:13 +00:00
[*Semantics]: Equivalent to
2013-05-22 23:28:12 +00:00
__deref__(__advance__<M>(__begin__(s)))
2006-08-22 15:57:13 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/at.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/at.hpp>
2006-08-22 15:57:13 +00:00
[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.]]
2007-04-10 22:27:41 +00:00
[[`N`] [An integral constant] [An index from the beginning of the
2006-08-22 15:57:13 +00:00
sequence.]]
]
[heading Expression Semantics]
at_c<N>(seq);
2007-04-10 22:27:41 +00:00
[*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,
2014-11-07 18:34:18 +01:00
returns a type convertible to the N-th element from the beginning of the
2006-08-22 15:57:13 +00:00
sequence.
2015-06-25 22:42:44 +09:00
[*Precondition]: `0 <= N < __size__(seq)` (where `seq` is not __unbounded_sequence__)
2006-08-22 15:57:13 +00:00
[*Semantics]: Equivalent to
__deref__(__advance__<N>(__begin__(s)))
[heading Header]
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/at_c.hpp>
2006-08-22 15:57:13 +00:00
[heading Example]
__vector__<int, int, int> v(1, 2, 3);
assert(at_c<1>(v) == 2);
[endsect]
[section has_key]
[heading Description]
2007-04-10 22:27:41 +00:00
Returns a type convertible to `bool` that evaluates to `true` if the
sequence contains an element associated with a Key, else, evaluates to
2006-08-22 15:57:13 +00:00
`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`.
2007-04-10 22:27:41 +00:00
[*Semantics]: Evaluates to `true` if the sequence contains an element
2006-08-22 15:57:13 +00:00
associated with Key, else, evaluates to `false`.
[heading Header]
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/has_key.hpp>
2006-08-22 15:57:13 +00:00
[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);
2007-04-10 22:27:41 +00:00
[*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
2014-11-07 18:34:18 +01:00
convertible to the element associated with Key.
2006-08-22 15:57:13 +00:00
2015-06-25 22:42:44 +09:00
[*Precondition]: `has_key<Key>(seq) == true` (where `seq` is not __unbounded_sequence__)
2006-08-22 15:57:13 +00:00
[*Semantics]: Returns the element associated with Key.
[heading Header]
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/at_key.hpp>
2006-08-22 15:57:13 +00:00
[heading Example]
__set__<int, char, bool> s(1, 'x', true);
assert(at_key<char>(s) == 'x');
[endsect]
2007-05-02 22:47:23 +00:00
[section swap]
[heading Description]
Performs an element by element swap of the elements in 2 sequences.
[heading Synopsis]
template<typename Seq1, typename Seq2>
2014-11-10 14:38:42 +09:00
typename __result_of_swap__<Seq1, Seq2>::type
swap(Seq1& seq1, Seq2& seq2);
2007-05-02 22:47:23 +00:00
[heading Parameters]
[table
[[Parameters] [Requirement] [Description]]
2014-11-07 18:34:18 +01:00
[[`seq1`, `seq2`][Models of __forward_sequence__][The sequences whose elements we wish to swap.]]
2007-05-02 22:47:23 +00:00
]
[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`.
2014-11-10 14:38:42 +09:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/swap.hpp>
#include <boost/fusion/include/swap.hpp>
2007-05-02 22:47:23 +00:00
[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]
2006-08-22 15:57:13 +00:00
[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
2009-10-30 00:19:19 +00:00
[*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__.
2006-08-22 15:57:13 +00:00
[*Semantics]: Returns the type of an iterator to the first element of `Seq`.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/include/begin.hpp>
2006-08-22 15:57:13 +00:00
[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
2009-10-30 00:19:19 +00:00
[*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__.
2006-08-22 15:57:13 +00:00
[*Semantics]: Returns the type of an iterator one past the end of `Seq`.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/include/end.hpp>
2006-08-22 15:57:13 +00:00
[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.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/empty.hpp>
#include <boost/fusion/include/empty.hpp>
2006-08-22 15:57:13 +00:00
[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`.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/front.hpp>
#include <boost/fusion/include/front.hpp>
2006-08-22 15:57:13 +00:00
[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`.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/back.hpp>
#include <boost/fusion/include/back.hpp>
2006-08-22 15:57:13 +00:00
[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`.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/include/size.hpp>
2006-08-22 15:57:13 +00:00
[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]
2007-04-10 22:27:41 +00:00
Returns the result type of __at__[footnote __result_of_at__ reflects the
2007-11-06 12:13:52 +00:00
actual return type of the function __at__. __sequence__(s) typically return
2006-08-22 15:57:13 +00:00
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,
2013-05-22 23:28:12 +00:00
typename M>
2006-08-22 15:57:13 +00:00
struct at
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __random_access_sequence__][Argument sequence]]
2013-05-22 23:28:12 +00:00
[[`M`][An __mpl_integral_constant__][Index of element]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
2013-05-22 23:28:12 +00:00
result_of::at<Seq, M>::type
2006-08-22 15:57:13 +00:00
[*Return type]: Any type.
2015-06-25 22:42:44 +09:00
[*Precondition]: `0 <= M::value < __result_of_size__<Seq>::value` (where `Seq` is not __unbounded_sequence__)
2015-03-22 09:45:17 +09:00
2013-05-22 23:28:12 +00:00
[*Semantics]: Returns the result type of using __at__ to access the `M`th element of `Seq`.
2006-08-22 15:57:13 +00:00
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/at.hpp>
2006-08-22 15:57:13 +00:00
[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]
2007-04-10 22:27:41 +00:00
Returns the result type of __at_c__[footnote __result_of_at_c__ reflects
2007-11-06 12:13:52 +00:00
the actual return type of the function __at_c__. __sequence__(s) typically
2007-04-10 22:27:41 +00:00
return references to its elements via the __at_c__ function. If you want to
2006-08-22 15:57:13 +00:00
get the actual element type, use __result_of_value_at_c__].
[heading Synopsis]
template<
typename Seq,
2013-05-22 23:28:12 +00:00
int N>
2006-08-22 15:57:13 +00:00
struct at_c
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __random_access_sequence__][Argument sequence]]
2013-05-22 23:28:12 +00:00
[[`N`][Positive integer index][Index of element]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
2013-05-22 23:28:12 +00:00
result_of::at_c<Seq, N>::type
2006-08-22 15:57:13 +00:00
[*Return type]: Any type
2015-06-25 22:42:44 +09:00
[*Precondition]: `0 <= N < __result_of_size__<Seq>::value` (where `Seq` is not __unbounded_sequence__)
2015-03-22 09:45:17 +09:00
2013-05-22 23:28:12 +00:00
[*Semantics]: Returns the result type of using __at_c__ to access the `N`th element of `Seq`.
2006-08-22 15:57:13 +00:00
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/at.hpp>
2006-08-22 15:57:13 +00:00
[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,
2013-05-22 23:28:12 +00:00
typename M>
2006-08-22 15:57:13 +00:00
struct value_at
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __random_access_sequence__][Argument sequence]]
2013-05-22 23:28:12 +00:00
[[`M`][An __mpl_integral_constant__][Index of element]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
2013-05-22 23:28:12 +00:00
result_of::value_at<Seq, M>::type
2006-08-22 15:57:13 +00:00
[*Return type]: Any type.
2013-05-22 23:28:12 +00:00
[*Semantics]: Returns the actual type at the `M`th element of `Seq`.
2006-08-22 15:57:13 +00:00
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/include/value_at.hpp>
2006-08-22 15:57:13 +00:00
[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,
2013-05-22 23:28:12 +00:00
int N>
2006-08-22 15:57:13 +00:00
struct value_at_c
{
typedef __unspecified__ type;
};
[table Parameters
[[Parameter] [Requirement] [Description]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __random_access_sequence__][Argument sequence]]
2013-05-22 23:28:12 +00:00
[[`N`][Positive integer index][Index of element]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
2013-05-22 23:28:12 +00:00
result_of::value_at_c<Seq, N>::type
2006-08-22 15:57:13 +00:00
[*Return type]: Any type
2013-05-22 23:28:12 +00:00
[*Semantics]: Returns the actual type at the `N`th element of `Seq`.
2006-08-22 15:57:13 +00:00
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/include/value_at.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __associative_sequence__][Argument sequence]]
2006-08-22 15:57:13 +00:00
[[`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.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
#include <boost/fusion/include/has_key.hpp>
2006-08-22 15:57:13 +00:00
[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]
2007-04-10 22:27:41 +00:00
Returns the result type of __at_key__[footnote __result_of_at_key__
2015-01-15 18:24:44 +09:00
reflects the actual return type of the function __at_key__. __sequence__(s)
2007-04-10 22:27:41 +00:00
typically return references to its elements via the __at_key__ function. If
2006-08-22 15:57:13 +00:00
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]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __associative_sequence__][Argument sequence]]
2006-08-22 15:57:13 +00:00
[[`Key`][Any type][Key type]]
]
[heading Expression Semantics]
result_of::at_key<Seq, Key>::type
[*Return type]: Any type.
2015-06-25 22:42:44 +09:00
[*Precondition]: `has_key<Seq, Key>::type::value == true` (where `Seq` is not __unbounded_sequence__)
2015-03-22 09:45:17 +09:00
2006-08-22 15:57:13 +00:00
[*Semantics]: Returns the result of using __at_key__ to access the element with key type `Key` in `Seq`.
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
#include <boost/fusion/include/at_key.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2011-03-21 04:08:44 +00:00
[[`Seq`][A model of __associative_sequence__][Argument sequence]]
2006-08-22 15:57:13 +00:00
[[`Key`][Any type][Key type]]
]
[heading Expression Semantics]
result_of::value_at_key<Seq, Key>::type
[*Return type]: Any type.
2015-06-25 22:42:44 +09:00
[*Precondition]: `has_key<Seq, Key>::type::value == true` (where `Seq` is not __unbounded_sequence__)
2015-03-22 09:45:17 +09:00
2007-04-10 22:27:41 +00:00
[*Semantics]: Returns the actual element type associated with key type
2006-08-22 15:57:13 +00:00
`Key` in `Seq`.
2009-10-30 00:19:19 +00:00
[heading Header]
2006-08-22 15:57:13 +00:00
2009-10-30 00:19:19 +00:00
#include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
#include <boost/fusion/include/value_at_key.hpp>
2011-03-21 04:08:44 +00:00
2006-08-22 15:57:13 +00:00
[heading Example]
typedef __map__<__pair__<int, char>, __pair__<char, char>, __pair__<double, char> > mymap;
2014-11-10 16:03:36 +09:00
BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at_key__<mymap, int>::type, char>));
2006-08-22 15:57:13 +00:00
[endsect]
2007-05-02 22:47:23 +00:00
[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
2014-11-10 14:38:42 +09:00
[*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence.
Otherwise, none.
2007-05-02 22:47:23 +00:00
2014-11-10 14:38:42 +09:00
[*Semantics]: Returns the return type of __swap__ for 2 sequences of types `Seq1` and `Seq2`.
2007-05-02 22:47:23 +00:00
2009-10-30 00:19:19 +00:00
[heading Header]
#include <boost/fusion/sequence/intrinsic/swap.hpp>
#include <boost/fusion/include/swap.hpp>
2007-05-02 22:47:23 +00:00
[endsect]
2006-08-22 15:57:13 +00:00
[endsect]
[endsect]
2007-11-06 10:09:38 +00:00
[section Operator]
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
These operators, like the __algorithms__, work generically on all Fusion
sequences. All conforming Fusion sequences automatically get these
operators for free.
2006-08-22 15:57:13 +00:00
[section I/O]
2011-07-19 23:29:06 +00:00
The I/O operators: `<<` and `>>` work generically on all Fusion
sequences. The I/O operators are overloaded in namespace `boost::fusion`
2015-01-15 18:24:44 +09:00
[footnote __sequence__(s) and __views__ residing in different namespaces
2011-07-19 23:29:06 +00:00
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.
2006-08-22 15:57:13 +00:00
2018-07-05 22:15:33 +09:00
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
...
2007-04-10 22:27:41 +00:00
The default delimiter between the elements is space, and the __sequence__
2006-08-22 15:57:13 +00:00
is enclosed in parenthesis. For Example:
__vector__<float, int, std::string> a(1.0f, 2, std::string("Howdy folks!");
2007-04-10 22:27:41 +00:00
cout << a;
2006-08-22 15:57:13 +00:00
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.]]
]
2007-04-10 22:27:41 +00:00
The argument to `tuple_open`, `tuple_close` and `tuple_delimiter` may be a
2006-08-22 15:57:13 +00:00
`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!]
2007-04-10 22:27:41 +00:00
The same manipulators work with `operator>>` and `istream` as well. Suppose
2006-08-22 15:57:13 +00:00
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;
2014-11-02 18:25:10 +09:00
std::cin >> tuple_open('[') >> tuple_close(']') >> tuple_delimiter(':');
2006-08-22 15:57:13 +00:00
std::cin >> j;
2007-11-06 12:13:52 +00:00
reads the data into the __vector__(s) `i` and `j`.
2006-08-22 15:57:13 +00:00
2007-11-06 12:13:52 +00:00
Note that extracting __sequence__(s) with `std::string` or C-style string
2007-04-10 22:27:41 +00:00
elements does not generally work, since the streamed __sequence__
representation may not be unambiguously parseable.
2006-08-22 15:57:13 +00:00
[heading Header]
#include <boost/fusion/sequence/io.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/io.hpp>
2006-08-22 15:57:13 +00:00
[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>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/in.hpp>
2006-08-22 15:57:13 +00:00
[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>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/out.hpp>
2006-08-22 15:57:13 +00:00
[heading Example]
std::cout << __make_vector__(123, "Hello", 'x') << std::endl;
[endsect]
[endsect]
[section Comparison]
2007-04-10 22:27:41 +00:00
The Comparison operators: `==`, `!=`, `<`, `<=`, `>=` and `>=` work
2006-08-22 15:57:13 +00:00
generically on all Fusion sequences. Comparison operators are "short-
2007-04-10 22:27:41 +00:00
circuited": elementary comparisons start from the first elements and are
2006-08-22 15:57:13 +00:00
performed only until the result is clear.
[heading Header]
#include <boost/fusion/sequence/comparison.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/comparison.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2007-11-06 12:13:52 +00:00
[[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
a == b
[*Return type]: `bool`
2007-04-10 22:27:41 +00:00
[*Requirements]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
convertible to bool.
2007-04-10 22:27:41 +00:00
An attempt to compare two Sequences of different lengths results in a
2006-08-22 15:57:13 +00:00
compile time error.
2007-04-10 22:27:41 +00:00
[*Semantics]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
For each element, `e1`, in sequence `a`, and for each element, `e2`, in
2015-01-15 18:24:44 +09:00
sequence `b`, `e1 == e2` returns true. For any 2 zero length __sequence__(s),
2006-08-22 15:57:13 +00:00
e and f, e == f returns true.
[heading Header]
#include <boost/fusion/sequence/comparison/equal_to.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/equal_to.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2007-11-06 12:13:52 +00:00
[[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
a != b
[*Return type]: `bool`
2007-04-10 22:27:41 +00:00
[*Requirements]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
convertible to bool.
2007-04-10 22:27:41 +00:00
An attempt to compare two Sequences of different lengths results in a
2006-08-22 15:57:13 +00:00
compile time error.
2007-04-10 22:27:41 +00:00
[*Semantics]:
2006-08-22 15:57:13 +00:00
Returns !(a == b).
[heading Header]
#include <boost/fusion/sequence/comparison/not_equal_to.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/not_equal_to.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2007-11-06 12:13:52 +00:00
[[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
a < b
[*Return type]: `bool`
2007-04-10 22:27:41 +00:00
[*Requirements]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
convertible to bool.
2007-04-10 22:27:41 +00:00
An attempt to compare two Sequences of different lengths results in a
2006-08-22 15:57:13 +00:00
compile time error.
[*Semantics]: Returns the lexicographical comparison of between `a` and `b`.
[heading Header]
#include <boost/fusion/sequence/comparison/less.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/less.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2007-11-06 12:13:52 +00:00
[[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
a <= b
[*Return type]: `bool`
2007-04-10 22:27:41 +00:00
[*Requirements]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
convertible to bool.
2007-04-10 22:27:41 +00:00
An attempt to compare two Sequences of different lengths results in a
2006-08-22 15:57:13 +00:00
compile time error.
[*Semantics]: Returns !(b < a).
[heading Header]
#include <boost/fusion/sequence/comparison/less_equal.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/less_equal.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2007-11-06 12:13:52 +00:00
[[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
a > b
[*Return type]: `bool`
2007-04-10 22:27:41 +00:00
[*Requirements]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
convertible to bool.
2007-04-10 22:27:41 +00:00
An attempt to compare two Sequences of different lengths results in a
2006-08-22 15:57:13 +00:00
compile time error.
[*Semantics]: Returns b < a.
[heading Header]
#include <boost/fusion/sequence/comparison/less_equal.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/less_equal.hpp>
2006-08-22 15:57:13 +00:00
[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]]
2007-11-06 12:13:52 +00:00
[[`a, b`] [Instances of __sequence__] [__sequence__(s) to compare]]
2006-08-22 15:57:13 +00:00
]
[heading Expression Semantics]
a >= b
[*Return type]: `bool`
2007-04-10 22:27:41 +00:00
[*Requirements]:
2006-08-22 15:57:13 +00:00
2007-04-10 22:27:41 +00:00
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
2006-08-22 15:57:13 +00:00
convertible to bool.
2007-04-10 22:27:41 +00:00
An attempt to compare two Sequences of different lengths results in a
2006-08-22 15:57:13 +00:00
compile time error.
[*Semantics]: Returns !(a < b).
[heading Header]
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
2007-11-06 11:40:27 +00:00
#include <boost/fusion/include/greater_equal.hpp>
2006-08-22 15:57:13 +00:00
[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]
2014-07-24 14:22:55 +02:00
[section Hashing]
2014-07-24 17:44:37 +02:00
Automatically create a `boost::hash` conforming `hash_value` function.
2014-07-24 14:22:55 +02:00
[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);
}
2014-07-24 17:44:37 +02:00
[heading See also]
__boost_func_hash__
2014-07-24 14:22:55 +02:00
[endsect]
2006-08-22 15:57:13 +00:00
[endsect]
[endsect]