]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Sequences/Intrinsic Metafunctions//has_key |
2 | ||
3 | has_key | |
4 | ======= | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename Key | |
14 | > | |
15 | struct has_key | |
16 | { | |
17 | typedef |unspecified| type; | |
18 | }; | |
19 | ||
20 | ||
21 | ||
22 | Description | |
23 | ----------- | |
24 | ||
25 | Returns a true-valued |Integral Constant| if ``Sequence`` contains an element | |
26 | with key ``Key``. | |
27 | ||
28 | ||
29 | Header | |
30 | ------ | |
31 | ||
32 | .. parsed-literal:: | |
33 | ||
34 | #include <boost/mpl/has_key.hpp> | |
35 | ||
36 | ||
37 | Model of | |
38 | -------- | |
39 | ||
40 | |Tag Dispatched Metafunction| | |
41 | ||
42 | ||
43 | Parameters | |
44 | ---------- | |
45 | ||
46 | +---------------+---------------------------+-----------------------------------------------+ | |
47 | | Parameter | Requirement | Description | | |
48 | +===============+===========================+===============================================+ | |
49 | | ``Sequence`` | |Associative Sequence| | A sequence to query. | | |
50 | +---------------+---------------------------+-----------------------------------------------+ | |
51 | | ``Key`` | Any type | The queried key. | | |
52 | +---------------+---------------------------+-----------------------------------------------+ | |
53 | ||
54 | ||
55 | Expression semantics | |
56 | -------------------- | |
57 | ||
58 | For any |Associative Sequence| ``s``, and arbitrary type ``key``: | |
59 | ||
60 | .. parsed-literal:: | |
61 | ||
62 | typedef has_key<s,key>::type c; | |
63 | ||
64 | :Return type: | |
65 | Boolean |Integral Constant|. | |
66 | ||
67 | :Semantics: | |
68 | ``c::value == true`` if ``key`` is in ``s``'s set of keys; otherwise | |
69 | ``c::value == false``. | |
70 | ||
71 | ||
72 | Complexity | |
73 | ---------- | |
74 | ||
75 | Amortized constant time. | |
76 | ||
77 | ||
78 | Example | |
79 | ------- | |
80 | ||
81 | .. parsed-literal:: | |
82 | ||
83 | typedef map< pair<int,unsigned>, pair<char,long> > m; | |
84 | BOOST_MPL_ASSERT_NOT(( has_key<m,long> )); | |
85 | ||
86 | typedef insert< m, pair<long,unsigned long> > m1; | |
87 | BOOST_MPL_ASSERT(( has_key<m1,long> )); | |
88 | ||
89 | ||
90 | See also | |
91 | -------- | |
92 | ||
93 | |Associative Sequence|, |count|, |insert|, |erase_key| | |
94 | ||
95 | ||
96 |