1 .. Sequences/Classes//set |40
9 ``set`` is a |variadic|, `associative`__, `extensible`__ sequence of types that
10 supports constant-time insertion and removal of elements, and testing for membership.
11 A ``set`` may contain at most one element for each key.
13 __ `Associative Sequence`_
14 __ `Extensible Associative Sequence`_
19 +-------------------+-------------------------------------------------------+
20 | Sequence form | Header |
21 +===================+=======================================================+
22 | Variadic | ``#include <boost/mpl/set.hpp>`` |
23 +-------------------+-------------------------------------------------------+
24 | Numbered | ``#include <boost/mpl/set/set``\ *n*\ ``.hpp>`` |
25 +-------------------+-------------------------------------------------------+
32 * |Associative Sequence|
33 * |Extensible Associative Sequence|
39 In the following table, ``s`` is an instance of ``set``, ``pos`` is an iterator into ``s``,
40 and ``x``, ``k``, and |t1...tn| is a set of *unique* arbitrary types. [*Note:* See `below`__ for
41 an example of how to construct a ``set`` from a list of potentially non-unique types |--| *end note*\]
43 __ nonunique-set-example_
45 +---------------------------------------+-----------------------------------------------------------+
46 | Expression | Semantics |
47 +=======================================+===========================================================+
48 | .. parsed-literal:: | ``set`` of elements |t1...tn|; see |
49 | | |Variadic Sequence|. |
51 | set\ *n*\ <|t1...tn|> | |
52 +---------------------------------------+-----------------------------------------------------------+
53 | .. parsed-literal:: | Identical to ``set``\ *n*\ ``<``\ |t1...tn|\ ``>``; |
54 | | see |Variadic Sequence|. |
55 | set<|t1...tn|>::type | |
56 | set\ *n*\ <|t1...tn|>::type | |
57 +---------------------------------------+-----------------------------------------------------------+
58 | ``begin<s>::type`` | An iterator pointing to the beginning of ``s``; |
59 | | see |Associative Sequence|. |
60 +---------------------------------------+-----------------------------------------------------------+
61 | ``end<s>::type`` | An iterator pointing to the end of ``s``; |
62 | | see |Associative Sequence|. |
63 +---------------------------------------+-----------------------------------------------------------+
64 | ``size<s>::type`` | The size of ``s``; see |Associative Sequence|. |
65 +---------------------------------------+-----------------------------------------------------------+
66 | ``empty<s>::type`` | |true if and only if| ``s`` is empty; see |
67 | | |Associative Sequence|. |
68 +---------------------------------------+-----------------------------------------------------------+
69 | ``front<s>::type`` | The first element in ``s``; see |
70 | | |Associative Sequence|. |
71 +---------------------------------------+-----------------------------------------------------------+
72 | ``has_key<s,k>::type`` | |true if and only if| there is one or more elements |
73 | | with the key ``k`` in ``s``; see |Associative Sequence|. |
74 +---------------------------------------+-----------------------------------------------------------+
75 | ``count<s,k>::type`` | The number of elements with the key ``k`` in ``s``; |
76 | | see |Associative Sequence|. |
77 +---------------------------------------+-----------------------------------------------------------+
78 | ``order<s,k>::type`` | A unique unsigned |Integral Constant| associated with |
79 | | the key ``k`` in ``s``; see |Associative Sequence|. |
80 +---------------------------------------+-----------------------------------------------------------+
81 | .. parsed-literal:: | The element associated with the key ``k`` in |
82 | | ``s``; see |Associative Sequence|. |
84 | at<s,k,def>::type | |
85 +---------------------------------------+-----------------------------------------------------------+
86 | ``key_type<s,x>::type`` | Identical to ``x``; see |Associative Sequence|. |
87 +---------------------------------------+-----------------------------------------------------------+
88 | ``value_type<s,x>::type`` | Identical to ``x``; see |Associative Sequence|. |
89 +---------------------------------------+-----------------------------------------------------------+
90 | ``insert<s,x>::type`` | A new ``set`` equivalent to ``s`` except that |
93 | | at< t, key_type<s,x>::type >::type |
95 | | is identical to ``value_type<s,x>::type``. |
96 +---------------------------------------+-----------------------------------------------------------+
97 | ``insert<s,pos,x>::type`` | Equivalent to ``insert<s,x>::type``; ``pos`` is ignored. |
98 +---------------------------------------+-----------------------------------------------------------+
99 | ``erase_key<s,k>::type`` | A new ``set`` equivalent to ``s`` except that |
100 | | ``has_key<t, k>::value == false``. |
101 +---------------------------------------+-----------------------------------------------------------+
102 | ``erase<s,pos>::type`` | Equivalent to ``erase<s, deref<pos>::type >::type``. |
103 +---------------------------------------+-----------------------------------------------------------+
104 | ``clear<s>::type`` | An empty ``set``; see |clear|. |
105 +---------------------------------------+-----------------------------------------------------------+
111 Basic ``set`` invariants:
115 typedef set< int,long,double,int_<5> > s;
117 BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 4 );
118 BOOST_MPL_ASSERT_NOT(( empty<s> ));
120 BOOST_MPL_ASSERT(( is_same< at<s,int>::type, int > ));
121 BOOST_MPL_ASSERT(( is_same< at<s,long>::type, long > ));
122 BOOST_MPL_ASSERT(( is_same< at<s,int_<5> >::type, int_<5> > ));
123 BOOST_MPL_ASSERT(( is_same< at<s,char>::type, void\_ > ));
126 .. _nonunique-set-example:
128 Constructing a ``set`` from a list of potentially non-unique types:
133 vector<int,int,long,long>
138 BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 2 );
144 |Sequences|, |Variadic Sequence|, |Associative Sequence|, |Extensible Associative Sequence|, |set_c|, |map|, |vector|
147 .. copyright:: Copyright © 2001-2011 Aleksey Gurtovoy and David Abrahams
148 Distributed under the Boost Software License, Version 1.0. (See accompanying
149 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)