...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Front Page / Sequences / Classes / set |
set is a variadic, associative, extensible sequence of types that supports constant-time insertion and removal of elements, and testing for membership. A set may contain at most one element for each key.
Sequence form | Header |
---|---|
Variadic | #include <boost/mpl/set.hpp> |
Numbered | #include |
In the following table, s is an instance of set, pos is an iterator into s, and x, k, and t1,t2,... tn is a set of unique arbitrary types. [Note: See below for an example of how to construct a set from a list of potentially non-unique types — end note]
Expression | Semantics |
---|---|
set<t1,t2,... tn> setn<t1,t2,... tn> |
set of elements t1,t2,... tn; see Variadic Sequence. |
set<t1,t2,... tn>::type setn<t1,t2,... tn>::type |
Identical to setn<t1,t2,... tn>; see Variadic Sequence. |
begin |
An iterator pointing to the beginning of s; see Associative Sequence. |
end |
An iterator pointing to the end of s; see Associative Sequence. |
size |
The size of s; see Associative Sequence. |
empty |
A boolean Integral Constant c such that c::value == true if and only if s is empty; see Associative Sequence. |
front |
The first element in s; see Associative Sequence. |
has_key |
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 Associative Sequence. |
count |
The number of elements with the key k in s; see Associative Sequence. |
order |
A unique unsigned Integral Constant associated with the key k in s; see Associative Sequence. |
at |
The element associated with the key k in s; see Associative Sequence. |
key_type |
Identical to x; see Associative Sequence. |
value_type |
Identical to x; see Associative Sequence. |
insert |
A new set equivalent to s except that at< t, key_type is identical to value_type |
insert |
Equivalent to insert |
erase_key |
A new set equivalent to s except that
has_key |
erase |
Equivalent to erase |
clear |
An empty set; see clear. |
Basic set invariants:
typedef set< int,long,double,int_<5> > s; BOOST_MPL_ASSERT_RELATION( size::value, ==, 4 ); BOOST_MPL_ASSERT_NOT(( empty)); BOOST_MPL_ASSERT(( is_same< at::type, int > )); BOOST_MPL_ASSERT(( is_same< at::type, long > )); BOOST_MPL_ASSERT(( is_same< atint_<5> >::type, int_<5> > )); BOOST_MPL_ASSERT(( is_same< at::type, void_ > ));
Constructing a set from a list of potentially non-unique types:
typedef fold< vector, set0<> , insert<_1,_2> >::type s; BOOST_MPL_ASSERT_RELATION( size ::value, ==, 2 );