Ticket #816: set.rst

File set.rst, 8.7 KB (added by cppljevans@…, 13 years ago)

Solution which just adds warning in docs

set

Description

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.

Expression semantics

In the following table, s is an instance of set, pos is an iterator into s, and x, k, and |t1...tn| are arbitrary types containing no duplicates.

warning:

This no duplicates requirement is needed for erase_key correctness. If the no duplicates requirement is not met, then code like the following:

typedef erase_key<set<int,int>,int>::type should_be_empty;
typedef has_key<should_be_empty,int>::type empty_has_int;
BOOST_MPL_ASSERT_NOT((empty_has_int));

will fail when it should succeed according to the erase_key semantics shown in the table.

If the user requires a set template without this limitation, then he might try the solution shown here.

Expression Semantics
set<|t1...tn|>
setn<|t1...tn|>
set of elements |t1...tn|; see |Variadic Sequence|.
set<|t1...tn|>::type
setn<|t1...tn|>::type
Identical to setn<|t1...tn|>; see |Variadic Sequence|.
begin<s>::type An iterator pointing to the beginning of s; see |Associative Sequence|.
end<s>::type An iterator pointing to the end of s; see |Associative Sequence|.
size<s>::type The size of s; see |Associative Sequence|.
empty<s>::type |true if and only if| s is empty; see |Associative Sequence|.
front<s>::type The first element in s; see |Associative Sequence|.
has_key<s,k>::type |true if and only if| there is one or more elements with the key k in s; see |Associative Sequence|.
count<s,k>::type The number of elements with the key k in s; see |Associative Sequence|.
order<s,k>::type A unique unsigned |Integral Constant| associated with the key k in s; see |Associative Sequence|.
at<s,k>::type
at<s,k,def>::type
The element associated with the key k in s; see |Associative Sequence|.
key_type<s,x>::type Identical to x; see |Associative Sequence|.
value_type<s,x>::type Identical to x; see |Associative Sequence|.
insert<s,x>::type

A new set equivalent to s except that

at< t, key_type<s,x>::type >::type

is identical to value_type<s,x>::type.

insert<s,pos,x>::type Equivalent to insert<s,x>::type; pos is ignored.
erase_key<s,k>::type A new set equivalent to s except that has_key<t, k>::value == false.
erase<s,pos>::type Equivalent to erase<s, deref<pos>::type >::type.
clear<s>::type An empty set; see |clear|.

Example

typedef set< int,long,double,int_<5> > s;

BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 4 );
BOOST_MPL_ASSERT_NOT(( empty<s> ));

BOOST_MPL_ASSERT(( is_same< at<s,int>::type, int > ));
BOOST_MPL_ASSERT(( is_same< at<s,long>::type, long > ));
BOOST_MPL_ASSERT(( is_same< at<s,int_<5> >::type, int_<5> > ));
BOOST_MPL_ASSERT(( is_same< at<s,char>::type, void_ > ));

Docutils System Messages

?????????????????????????????????????