]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Sequences/Classes//set |40 |
2 | ||
3 | set | |
4 | === | |
5 | ||
6 | Description | |
7 | ----------- | |
8 | ||
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. | |
12 | ||
13 | __ `Associative Sequence`_ | |
14 | __ `Extensible Associative Sequence`_ | |
15 | ||
16 | Header | |
17 | ------ | |
18 | ||
19 | +-------------------+-------------------------------------------------------+ | |
20 | | Sequence form | Header | | |
21 | +===================+=======================================================+ | |
22 | | Variadic | ``#include <boost/mpl/set.hpp>`` | | |
23 | +-------------------+-------------------------------------------------------+ | |
24 | | Numbered | ``#include <boost/mpl/set/set``\ *n*\ ``.hpp>`` | | |
25 | +-------------------+-------------------------------------------------------+ | |
26 | ||
27 | ||
28 | Model of | |
29 | -------- | |
30 | ||
31 | * |Variadic Sequence| | |
32 | * |Associative Sequence| | |
33 | * |Extensible Associative Sequence| | |
34 | ||
35 | ||
36 | Expression semantics | |
37 | -------------------- | |
38 | ||
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*\] | |
42 | ||
43 | __ nonunique-set-example_ | |
44 | ||
45 | +---------------------------------------+-----------------------------------------------------------+ | |
46 | | Expression | Semantics | | |
47 | +=======================================+===========================================================+ | |
48 | | .. parsed-literal:: | ``set`` of elements |t1...tn|; see | | |
49 | | | |Variadic Sequence|. | | |
50 | | set<|t1...tn|> | | | |
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|. | | |
83 | | at<s,k>::type | | | |
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 | | |
91 | | | :: | | |
92 | | | | | |
93 | | | at< t, key_type<s,x>::type >::type | | |
94 | | | | | |
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 | +---------------------------------------+-----------------------------------------------------------+ | |
106 | ||
107 | ||
108 | Example | |
109 | ------- | |
110 | ||
111 | Basic ``set`` invariants: | |
112 | ||
113 | .. parsed-literal:: | |
114 | ||
115 | typedef set< int,long,double,int_<5> > s; | |
116 | ||
117 | BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 4 ); | |
118 | BOOST_MPL_ASSERT_NOT(( empty<s> )); | |
119 | ||
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\_ > )); | |
124 | ||
125 | ||
126 | .. _nonunique-set-example: | |
127 | ||
128 | Constructing a ``set`` from a list of potentially non-unique types: | |
129 | ||
130 | .. parsed-literal:: | |
131 | ||
132 | typedef fold< | |
133 | vector<int,int,long,long> | |
134 | , set0<> | |
135 | , insert<_1,_2> | |
136 | >::type s; | |
137 | ||
138 | BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 2 ); | |
139 | ||
140 | ||
141 | See also | |
142 | -------- | |
143 | ||
144 | |Sequences|, |Variadic Sequence|, |Associative Sequence|, |Extensible Associative Sequence|, |set_c|, |map|, |vector| | |
145 | ||
146 | ||
147 |