Project: ArangoDB (App Definition and Development / Database)
File: refmanual.pdf

The MPL Reference Manual2
Copyright : Copyright c/circlecopyrtAleksey Gurtovoy and David Abrahams, 2001-2005.
License: Distributed under the Boost Software License, Version 1.0. (See accompanying ﬁle
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Revision Date: 15th November 2004Contents
Contents 3
1 Sequences 9
1.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.1.1 Forward Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.1.2 Bidirectional Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1.3 Random Access Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1.4 Extensible Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.1.5 Front Extensible Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.1.6 Back Extensible Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.1.7 Associative Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.1.8 Extensible Associative Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.1.9 Integral Sequence Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.1.10 Variadic Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.2 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.2.1 vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.2.2 list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.2.3 deque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.2.4 set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.2.5 map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.2.6 range_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.2.7 vector_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
1.2.8 list_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
1.2.9 set_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.3 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.3.1 empty_sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.3.2 ﬁlter_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.3.3 iterator_range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.3.4 joint_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.3.5 single_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.3.6 transform_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.3.7 zip_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.4 Intrinsic Metafunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
1.4.1 at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.4.2 at_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.4.3 back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
1.4.4 begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.4.5 clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.4.6 empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
1.4.7 end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46CONTENTS CONTENTS 4
1.4.8 erase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
1.4.9 erase_key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
1.4.10 front . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
1.4.11 has_key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
1.4.12 insert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.4.13 insert_range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
1.4.14 is_sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
1.4.15 key_type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
1.4.16 order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
1.4.17 pop_back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
1.4.18 pop_front . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
1.4.19 push_back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
1.4.20 push_front . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
1.4.21 sequence_tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
1.4.22 size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
1.4.23 value_type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
2 Iterators 69
2.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.1.1 Forward Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.1.2 Bidirectional Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.1.3 Random Access Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
2.2 Iterator Metafunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.2.1 advance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.2.2 distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
2.2.3 next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.2.4 prior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
2.2.5 deref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.2.6 iterator_category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3 Algorithms 81
3.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.1.1 Inserter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.1.2 Reversible Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.2 Inserters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.2.1 back_inserter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.2.2 front_inserter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3.2.3 inserter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
3.3 Iteration Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
3.3.1 fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
3.3.2 iter_fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.3.3 reverse_fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
3.3.4 reverse_iter_fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.3.5 accumulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.4 Querying Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.4.1 ﬁnd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.4.2 ﬁnd_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.4.3 contains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
3.4.4 count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.4.5 count_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
3.4.6 lower_bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
3.4.7 upper_bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
3.4.8 min_element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Revision Date: 15th November 20045 CONTENTS CONTENTS
3.4.9 max_element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
3.4.10 equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.5 Transformation Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.5.1 copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.5.2 copy_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
3.5.3 transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
3.5.4 replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
3.5.5 replace_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
3.5.6 remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
3.5.7 remove_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
3.5.8 unique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
3.5.9 partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
3.5.10 stable_partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
3.5.11 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
3.5.12 reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
3.5.13 reverse_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
3.5.14 reverse_copy_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
3.5.15 reverse_transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
3.5.16 reverse_replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
3.5.17 reverse_replace_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
3.5.18 reverse_remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
3.5.19 reverse_remove_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
3.5.20 reverse_unique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
3.5.21 reverse_partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
3.5.22 reverse_stable_partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
4 Metafunctions 141
4.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
4.1.1 Metafunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
4.1.2 Metafunction Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
4.1.3 Lambda Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
4.1.4 Placeholder Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
4.1.5 Tag Dispatched Metafunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
4.1.6 Numeric Metafunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
4.1.7 Trivial Metafunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
4.2 Type Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
4.2.1 if_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
4.2.2 if_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
4.2.3 eval_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
4.2.4 eval_if_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
4.3 Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
4.3.1 apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
4.3.2 apply_wrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
4.3.3 unpack_args . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
4.4 Composition and Argument Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
4.4.1 Placeholders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
4.4.2 lambda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
4.4.3 bind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
4.4.4 quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
4.4.5 arg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
4.4.6 protect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
4.5 Arithmetic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
4.5.1 plus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Revision Date: 15th November 2004CONTENTS CONTENTS 6
4.5.2 minus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
4.5.3 times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
4.5.4 divides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
4.5.5 modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
4.5.6 negate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
4.6 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
4.6.1 less . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
4.6.2 less_equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
4.6.3 greater . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
4.6.4 greater_equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
4.6.5 equal_to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
4.6.6 not_equal_to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
4.7 Logical Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
4.7.1 and_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
4.7.2 or_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
4.7.3 not_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
4.8 Bitwise Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
4.8.1 bitand_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
4.8.2 bitor_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
4.8.3 bitxor_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
4.8.4 shift_left . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
4.8.5 shift_right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
4.9 Trivial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
4.9.1 Trivial MetafunctionsSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
4.10 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
4.10.1 identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
4.10.2 always . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
4.10.3 inherit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
4.10.4 inherit_linearly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
4.10.5 numeric_cast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
4.10.6 min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
4.10.7 max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
4.10.8 sizeof_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
5 Data Types 209
5.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
5.1.1 Integral Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
5.2 Numeric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
5.2.1 bool_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
5.2.2 int_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
5.2.3 long_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
5.2.4 size_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
5.2.5 integral_c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
5.3 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
5.3.1 pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
5.3.2 empty_base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
5.3.3 void_ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
6 Macros 219
6.1 Asserts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
6.1.1 BOOST_MPL_ASSERT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
6.1.2 BOOST_MPL_ASSERT_MSG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
6.1.3 BOOST_MPL_ASSERT_NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Revision Date: 15th November 20047 CONTENTS CONTENTS
6.1.4 BOOST_MPL_ASSERT_RELATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
6.2 Introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
6.2.1 BOOST_MPL_HAS_XXX_TRAIT_DEF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
6.2.2 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF . . . . . . . . . . . . . . . . . . . . . . . 225
6.3 Conﬁguration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
6.3.1 BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS . . . . . . . . . . . . . . . . . . . . 227
6.3.2 BOOST_MPL_CFG_NO_HAS_XXX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
6.3.3 BOOST_MPL_LIMIT_METAFUNCTION_ARITY . . . . . . . . . . . . . . . . . . . . . . . 228
6.3.4 BOOST_MPL_LIMIT_VECTOR_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
6.3.5 BOOST_MPL_LIMIT_LIST_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
6.3.6 BOOST_MPL_LIMIT_SET_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
6.3.7 BOOST_MPL_LIMIT_MAP_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
6.3.8 BOOST_MPL_LIMIT_UNROLLING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
6.4 Broken Compiler Workarounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
6.4.1 BOOST_MPL_AUX_LAMBDA_SUPPORT . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
7 Terminology 235
8 Categorized Index 237
8.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
8.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
9 Acknowledgements 243
Bibliography 245
Revision Date: 15th November 2004CONTENTS CONTENTS 8
Revision Date: 15th November 2004Chapter 1 Sequences
Compile-timesequencesoftypesareoneofthebasicconceptsofC++templatemetaprogramming. Differencesintypes
of objects being manipulated is the most common point of variability of similar, but not identical designs, and these
are a direct target for metaprogramming. Templates were originally designed to address this exact problem. However,
withoutpredeﬁnedmechanismsforrepresentingandmanipulating sequences oftypesasopposedtostandalonetemplate
parameters, high-level template metaprogramming is severely limited in its capabitilies.
The MPL recognizes the importance of type sequences as a fundamental building block of many higher-level metapro-
gramming designs by providing us with a conceptual framework for formal reasoning and understanding of sequence
properties, guarantees andcharacteristics, aswell as aﬁrst-class implementation ofthat framework— a wealthof tools
for concise, convenient, conceptually precise and efﬁcient sequence manipulation.
1.1 Concepts
The taxonomy of sequence concepts in MPL parallels the taxonomy of the MPL Iterators, with two additional classiﬁ-
cation dimensions: extensibility andassociativeness .
1.1.1 Forward Sequence
Description
AForward Sequence is an MPL concept representing a compile-time sequence of elements. Sequence elements are
types, and are accessible through Iterators. The beginandendmetafunctions provide iterators delimiting the range
of the sequence elements. A sequence guarantees that its elements are arranged in a deﬁnite, but possibly unspeciﬁed,
order. Every MPL sequence isa Forward Sequence .
Deﬁnitions
—Thesizeof a sequence is the number of elements it contains. The size is a nonnegative number.
—A sequence is emptyif its size is zero.
Expression requirements
For anyForward Sequence sthe following expressions must be valid:
Expression Type Complexity
begin
::type Forward Iterator Amortized constant time
end
::type Forward Iterator Amortized constant time
size
::type Integral Constant Unspeciﬁed
empty
::type BooleanIntegral Constant Constant time
front
::type Any type Amortized constant time1.1 Concepts Sequences 10
Expression semantics
Expression Semantics
begin
::type An iterator to the ﬁrst element of the sequence; see begin.
end
::type A past-the-end iterator to the sequence; see end.
size
::type The size of the sequence; see size.
empty
::type A boolean Integral Constant csuch that c::value == true if and only if the
sequence is empty; see empty.
front
::type The ﬁrst element in the sequence; see front.
Invariants
For anyForward Sequence sthe following invariants always hold:
—[begin
::type ,end
::type ) is always a valid range.
—Analgorithmthatiteratesthroughtherange[ begin
::type ,end
::type )willpassthrougheveryelement
ofsexactly once.
—begin
::type is identical to end
::type if and only if sis empty.
—Two different iterations through swill access its elements in the same order.
Models
—vector
—map
—range_c
—iterator_range
—filter_view
See also
Sequences ,Bidirectional Sequence ,Forward Iterator ,begin/end,size,empty,front
1.1.2 Bidirectional Sequence
Description
ABidirectional Sequence is aForward Sequence whose iterators model Bidirectional Iterator .
Reﬁnement of
Forward Sequence
Expression requirements
In addition to the requirements deﬁned in Forward Sequence , for anyBidirectional Sequence sthe following must be
met:
Revision Date: 15th November 200411 Sequences 1.1 Concepts
Expression Type Complexity
begin
::type Bidirectional Iterator Amortized constant time
end
::type Bidirectional Iterator Amortized constant time
back
::type Any type Amortized constant time
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Forward Sequence .
Expression Semantics
back
::type The last element in the sequence; see back.
Models
—vector
—range_c
See also
Sequences ,Forward Sequence ,Random Access Sequence ,Bidirectional Iterator ,begin/end,back
1.1.3 Random Access Sequence
Description
ARandom Access Sequence is aBidirectional Sequence whose iterators model Random Access Iterator . A random
access sequence guaranteesamortized constant time access to an arbitrary sequence element.
Reﬁnement of
Bidirectional Sequence
Expression requirements
In addition to the requirements deﬁned in Bidirectional Sequence , for any Random Access Sequence sthe following
must be met:
Expression Type Complexity
begin
::type Random Access Iterator Amortized constant time
end
::type Random Access Iterator Amortized constant time
at<s,n>::type Any type Amortized constant time
Expression semantics
Semantics of an expression is deﬁned only where it differs from, or is not deﬁned in Bidirectional Sequence .
Revision Date: 15th November 20041.1 Concepts Sequences 12
Expression Semantics
Expression Semantics
at<s,n>::type Thenth element from the beginning of the sequence; see at.
Models
—vector
—range_c
See also
Sequences ,Bidirectional Sequence ,Extensible Sequence ,Random Access Iterator ,begin/end,at
1.1.4 Extensible Sequence
Description
AnExtensible Sequence is a sequence that supports insertion and removal of elements. Extensibility is orthogonal to
sequence traversal characteristics.
Expression requirements
For anyExtensible Sequence s, its iterators posandlast,Forward Sequence r, and any type x, the following expres-
sions must be valid:
Expression Type Complexity
insert<s,pos,x>::type Extensible Sequence Unspeciﬁed
insert_range<s,pos,r>::type Extensible Sequence Unspeciﬁed
erase<s,pos>::type Extensible Sequence Unspeciﬁed
erase<s,pos,last>::type Extensible Sequence Unspeciﬁed
clear
::type Extensible Sequence Constant time
Expression semantics
Expression Semantics
insert<s,pos,x>::type A new sequence, concept-identical to s, of the following elements:
[begin
::type ,pos),x, [pos,end
::type ); see insert.
insert_range<s,pos,r>::type A new sequence, concept-identical to s, of the following elements:
[begin
::type ,pos), [begin<r>::type ,end<r>::type ), [pos,
end
::type ); see insert_range .
erase<s,pos>::type A new sequence, concept-identical to s, of the following elements:
[begin
::type ,pos), [next<pos>::type ,end
::type ); see
erase.
erase<s,pos,last>::type A new sequence, concept-identical to s, of the following elements:
[begin
::type ,pos), [last,end
::type ); see erase.
clear
::type An empty sequence concept-identical to s; see clear.
Revision Date: 15th November 200413 Sequences 1.1 Concepts
Models
—vector
—list
See also
Sequences ,Back Extensible Sequence ,insert,insert_range ,erase,clear
1.1.5 Front Extensible Sequence
Description
AFront Extensible Sequence is anExtensible Sequence that supports amortized constant time insertion and removal
operations at the beginning.
Reﬁnement of
Extensible Sequence
Expression requirements
Inadditiontotherequirementsdeﬁnedin ExtensibleSequence ,foranyBackExtensibleSequence sthefollowingmust
be met:
Expression Type Complexity
push_front<s,x>::type Front Extensible Sequence Amortized constant time
pop_front
::type Front Extensible Sequence Amortized constant time
front
::type Any type Amortized constant time
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Extensible Sequence .
Expression Semantics
push_front<s,x>::type Equivalent to insert<s,begin
::type,x>::type ; see push_-
front.
pop_front<v>::type Equivalent to erase<s,begin
::type>::type ; see pop_front .
front
::type The ﬁrst element in the sequence; see front.
Models
—vector
—list
See also
Sequences ,Extensible Sequence ,Back Extensible Sequence ,push_front ,pop_front ,front
Revision Date: 15th November 20041.1 Concepts Sequences 14
1.1.6 Back Extensible Sequence
Description
ABack Extensible Sequence is anExtensible Sequence that supports amortized constant time insertion and removal
operations at the end.
Reﬁnement of
Extensible Sequence
Expression requirements
Inadditiontotherequirementsdeﬁnedin ExtensibleSequence ,foranyBackExtensibleSequence sthefollowingmust
be met:
Expression Type Complexity
push_back<s,x>::type Back Extensible Sequence Amortized constant time
pop_back
::type Back Extensible Sequence Amortized constant time
back
::type Any type Amortized constant time
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Extensible Sequence .
Expression Semantics
push_back<s,x>::type Equivalent to insert<s,end
::type,x>::type ; see push_back .
pop_back<v>::type Equivalent to erase<s,end
::type>::type ; see pop_back .
back
::type The last element in the sequence; see back.
Models
—vector
—deque
See also
Sequences ,Extensible Sequence ,Front Extensible Sequence ,push_back ,pop_back ,back
1.1.7 Associative Sequence
Description
AnAssociative Sequence is aForward Sequence that allows efﬁcient retrieval of elements based on keys. Unlike
associative containers in the C++ Standard Library, MPL associative sequences have no associated ordering relation.
Instead,type identity is used to impose an equivalence relation on keys, and the order in which sequence elements are
traversed during iteration isleft unspeciﬁed.
Revision Date: 15th November 200415 Sequences 1.1 Concepts
Deﬁnitions
—Akeyis a part of the element type used to identify and retrieve the element within the sequence.
—Avalueis a part of the element type retrievied from the sequence by its key.
Expression requirements
In the following table and subsequent speciﬁcations, sis anAssociative Sequence ,xis a sequence element, and kand
defare arbitrary types.
In addition to the requirements deﬁned in Forward Sequence , the following must be met:
Expression Type Complexity
has_key<s,k>::type BooleanIntegral Constant Amortized constant time
count<s,k>::type Integral Constant Amortized constant time
order<s,k>::type Integral Constant orvoid_ Amortized constant time
at<s,k>::type Any type Amortized constant time
at<s,k,def>::type Any type Amortized constant time
key_type<s,x>::type Any type Amortized constant time
value_type<s,x>::type Any type Amortized constant time
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Forward Sequence .
Expression Semantics
has_key<s,k>::type A boolean Integral Constant csuch that c::value == true if and only
if there is one or more elements with the key kins; see has_key.
count<s,k>::type The number of elements with the key kins; see count.
order<s,k>::type A unique unsigned Integral Constant associated with the key kin the se-
quence s; see order.
at<s,k>::type
at<s,k,def>::typeThe ﬁrst element associated with the key kin the sequence s; see at.
key_type<s,x>::type The key part of the element xthat would be used to identify xins; see
key_type .
value_type<s,x>::type Thevaluepartoftheelement xthatwouldbeusedfor xins;see value_-
type.
Models
—set
—map
See also
Sequences ,Extensible Associative Sequence ,has_key,count,order,at,key_type ,value_type
Revision Date: 15th November 20041.1 Concepts Sequences 16
1.1.8 Extensible Associative Sequence
Description
AnExtensibleAssociativeSequence isanAssociativeSequence thatsupportsinsertionandremovalofelements. Incon-
trast toExtensible Sequence ,Extensible Associative Sequence does not provide a mechanism for inserting an element
at a speciﬁc position.
Expression requirements
Inthefollowingtableandsubsequentspeciﬁcations, sisanAssociativeSequence ,posisaniteratorinto s,and xandk
are arbitrary types.
In addition to the Associative Sequence requirements, the followingmust be met:
Expression Type Complexity
insert<s,x>::type Extensible Associative Sequence Amortized constant time
insert<s,pos,x>::type Extensible Associative Sequence Amortized constant time
erase_key<s,k>::type Extensible Associative Sequence Amortized constant time
erase<s,pos>::type Extensible Associative Sequence Amortized constant time
clear
::type Extensible Associative Sequence Amortized constant time
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Associative Sequence .
Expression Semantics
insert<s,x>::type Inserts xintos; the resulting sequence ris equivalent to sexcept that
at< r, key_type<s,x>::type >::type
is identical to value_type<s,x>::type ; see insert.
insert<s,pos,x>::type Equivalent to insert<s,x>::type ;posis ignored; see insert.
erase_key<s,k>::type Erases elements in sassociated with the key k; the resulting sequence
ris equivalent to sexcept that has_key<r,k>::value == false ; see
erase_key .
erase<s,pos>::type Erases the element at a speciﬁc position; equivalent to erase_key<s,
deref<pos>::type >::type ; see erase.
clear
::type An empty sequence concept-identical to s; see clear.
Models
—set
—map
See also
Sequences ,Associative Sequence ,insert,erase,clear
Revision Date: 15th November 200417 Sequences 1.1 Concepts
1.1.9 Integral Sequence Wrapper
Description
AnIntegralSequenceWrapper isaclasstemplatethatprovidesaconciseinterfaceforcreatingacorrespondingsequence
ofIntegral Constant s. In particular, assuming that seqis a name of the wrapper’s underlying sequence and c1,c2,...cn
are integral constants of an integral type Tto be stored in the sequence, the wrapper provides us with the following
notation:
seq_c<T,c1,c2,...cn>
Ifseqis aVariadic Sequence ,numbered wrapper forms are also avaialable:
seqn_c<T,c1,c2,...cn>
Expression requirements
In the following table and subsequent speciﬁcations, seqis a placeholder token for the Integral Sequence Wrapper ’s
underlying sequence’s name.
Expression Type Complexity
seq_c<T,c1,c2,...cn> Forward Sequence Amortized constant time.
seq_c<T,c1,c2,...cn>::type Forward Sequence Amortized constant time.
seq_c<T,c1,c2,...cn>::value_type An integral type Amortized constant time.
seqn_c<T,c1,c2,...cn> Forward Sequence Amortized constant time.
seqn_c<T,c1,c2,...cn>::type Forward Sequence Amortized constant time.
seqn_c<T,c1,c2,...cn>::value_type An integral type Amortized constant time.
Expression semantics
typedef seq_c<T, c1,c2,... cn> s;
typedef seq n_c<T, c1,c2,... cn> s;
Semantics: sis a sequence seqof integral constant wrappers integral_c<T, c1>,integral_c<T, c2>,
...integral_c<T, cn>.
Postcondition: size
::value == n .
typedef seq_c<T, c1,c2,... cn>::type s;
typedef seq n_c<T, c1,c2,... cn>::type s;
Semantics: sis identical to seqn<integral_c<T, c1>,integral_c<T, c2>, ...integral_c<T, cn> >.
typedef seq_c<T, c1,c2,... cn>::value_type t;
typedef seq n_c<T, c1,c2,... cn>::value_type t;
Semantics: is_same<t,T>::value == true .
Models
—vector_c
—list_c
—set_c
Revision Date: 15th November 20041.1 Concepts Sequences 18
See also
Sequences ,Variadic Sequence ,Integral Constant
1.1.10 Variadic Sequence
Description
AVariadic Sequence is a member of a family of sequence classes with both variadicandnumbered forms. If seqis a
genericnameforsome VariadicSequence ,itsvariadicform allowsustospecifyasequenceof nelements t1,t2,...tn,for
anynfrom 0 up to a preprocessor-conﬁgurable limit BOOST_MPL_LIMIT_ seq_SIZE, using the following notation:
seq<t1,t2,...tn>
By contrast, each numbered sequence form accepts the exact number of elements that is encoded in the name of the
corresponding class template:
seqn<t1,t2,...tn>
For numbered forms, there is no predeﬁned top limit for n, aside from compiler limitations on the number of template
parameters.
Expression requirements
In the following table and subsequent speciﬁcations, seqis a placeholder token for the actual Variadic Sequence name.
Expression Type Complexity
seq<t1,t2,...tn> Forward Sequence Amortized constant time
seq<t1,t2,...tn>::type Forward Sequence Amortized constant time
seqn<t1,t2,...tn> Forward Sequence Amortized constant time
seqn<t1,t2,...tn>::type Forward Sequence Amortized constant time
Expression semantics
typedef seq< t1,t2,... tn> s;
typedef seq n<t1,t2,... tn> s;
Semantics: sis a sequence of elements t1,t2,...tn.
Postcondition: size
::value == n .
typedef seq< t1,t2,... tn>::type s;
typedef seq n<t1,t2,... tn>::type s;
Semantics: sis identical to seqn<t1,t2,...tn>.
Postcondition: size
::value == n .
Models
—vector
—list
—map
Revision Date: 15th November 200419 Sequences 1.2 Classes
See also
Sequences ,Conﬁguration ,Integral Sequence Wrapper
1.2 Classes
TheMPLprovidesalargenumberofpredeﬁnedgeneral-purposesequenceclassescoveringmostofthetypicalmetapro-
gramming needs out-of-box.
1.2.1 vector
Description
vectoris avariadic,random access ,extensible sequence of types that supports constant-time insertion and removal of
elements at both ends, and linear-time insertion and removal of elements in the middle. On compilers that support the
typeofextension, vectoris the simplest and in many cases the most efﬁcient sequence.
Header
Sequence form Header
Variadic #include <boost/mpl/vector.hpp>
Numbered #include <boost/mpl/vector/vector n.hpp>
Model of
—Variadic Sequence
—Random Access Sequence
—Extensible Sequence
—Back Extensible Sequence
—Front Extensible Sequence
Expression semantics
In the following table, vis an instance of vector,posandlastare iterators into v,ris aForward Sequence ,nis an
Integral Constant , and xandt1,t2,...tnare arbitrary types.
Expression Semantics
vector< t1,t2,... tn>
vector n<t1,t2,... tn>vectorof elements t1,t2,...tn; seeVariadic Sequence .
vector< t1,t2,... tn>::type
vector n<t1,t2,... tn>::typeIdentical to vectorn<t1,t2,...tn>; seeVariadic Sequence .
begin<v>::type An iterator pointing to the beginning of v; seeRandom Access Se-
quence.
end<v>::type Aniteratorpointingtotheendof v;seeRandomAccessSequence .
size<v>::type The size of v; seeRandom Access Sequence .
empty<v>::type Aboolean IntegralConstant csuchthat c::value == true ifand
only if the sequence is empty; see Random Access Sequence .
Revision Date: 15th November 20041.2 Classes Sequences 20
Expression Semantics
front<v>::type The ﬁrst element in v; seeRandom Access Sequence .
back<v>::type The last element in v; seeRandom Access Sequence .
at<v,n>::type Thenth element from the beginning of v; seeRandom Access Se-
quence.
insert<v,pos,x>::type Anew vectoroffollowingelements: [ begin<v>::type ,pos),x,
[pos,end<v>::type ); seeExtensible Sequence .
insert_range<v,pos,r>::type A new vectorof following elements: [ begin<v>::type ,pos),
[begin<r>::type ,end<r>::type ) [pos,end<v>::type ); see
Extensible Sequence .
erase<v,pos>::type A new vectorof following elements: [ begin<v>::type ,pos),
[next<pos>::type ,end<v>::type ); seeExtensible Sequence .
erase<v,pos,last>::type A new vectorof following elements: [ begin<v>::type ,pos),
[last,end<v>::type ); seeExtensible Sequence .
clear<v>::type An empty vector; seeExtensible Sequence .
push_back<v,x>::type A new vector of following elements: [ begin<v>::type ,
end<v>::type ),x; seeBack Extensible Sequence .
pop_back<v>::type Anew vectoroffollowingelements: [ begin<v>::type ,prior<
end<v>::type >::type ); seeBack Extensible Sequence .
push_front<v,x>::type A new vector of following elements: [ begin<v>::type ,
end<v>::type ),x; seeFront Extensible Sequence .
pop_front<v>::type A new vectorof following elements: [ next< begin<v>::type
>::type,end<v>::type ); seeFront Extensible Sequence .
Example
typedef vector<float,double,long double> floats;
typedef push_back<floats,int>::type types;
BOOST_MPL_ASSERT(( is_same< at_c<types,3>::type, int > ));
See also
Sequences ,Variadic Sequence ,Random Access Sequence ,Extensible Sequence ,vector_c ,list
1.2.2 list
Description
Alistisavariadic,forward,extensible sequenceoftypesthatsupportsconstant-timeinsertionandremovalofelements
at the beginning, and linear-time insertion and removal of elements at the end and in the middle.
Header
Sequence form Header
Variadic #include <boost/mpl/list.hpp>
Numbered #include <boost/mpl/list/list n.hpp>
Revision Date: 15th November 200421 Sequences 1.2 Classes
Model of
—Variadic Sequence
—Forward Sequence
—Extensible Sequence
—Front Extensible Sequence
Expression semantics
In the following table, lis alist,posandlastare iterators into l,ris aForward Sequence , andt1,t2,...tnandxare
arbitrary types.
Expression Semantics
list< t1,t2,... tn>
list n<t1,t2,... tn>listof elements t1,t2,...tn; seeVariadic Sequence .
list< t1,t2,... tn>::type
list n<t1,t2,... tn>::typeIdentical to listn<t1,t2,...tn>; seeVariadic Sequence .
begin<l>::type An iterator to the beginningof l; seeForward Sequence .
end<l>::type An iterator to the end of l; seeForward Sequence .
size<l>::type The size of l; seeForward Sequence .
empty<l>::type Aboolean IntegralConstant csuchthat c::value == true ifand
only if lis empty; see Forward Sequence .
front<l>::type The ﬁrst element in l; seeForward Sequence .
insert<l,pos,x>::type A new listof following elements: [ begin<l>::type ,pos),x,
[pos,end<l>::type ); seeExtensible Sequence .
insert_range<l,pos,r>::type A new listof following elements: [ begin<l>::type ,pos),
[begin<r>::type ,end<r>::type ) [pos,end<l>::type ); see
Extensible Sequence .
erase<l,pos>::type A new listof following elements: [ begin<l>::type ,pos),
[next<pos>::type ,end<l>::type ); seeExtensible Sequence .
erase<l,pos,last>::type A new listof following elements: [ begin<l>::type ,pos),
[last,end<l>::type ); seeExtensible Sequence .
clear<l>::type An empty list; seeExtensible Sequence .
push_front<l,x>::type A new listcontaining xas its ﬁrst element; see Front Extensible
Sequence .
pop_front<l>::type A new listcontaining all but the ﬁrst elements of lin the same
order; see Front Extensible Sequence .
Example
typedef list<float,double,long double> floats;
typedef push_front<floating_types,int>::type types;
BOOST_MPL_ASSERT(( is_same< front<types>::type, int > ));
Revision Date: 15th November 20041.2 Classes Sequences 22
See also
Sequences ,Variadic Sequence ,Forward Sequence ,Extensible Sequence ,vector,list_c
1.2.3 deque
Description
dequeis avariadic,random access ,extensible sequence of types that supports constant-time insertion and removal of
elements at both ends, and linear-time insertion and removal of elements in the middle. In this implementation of the
library, dequeis a synonym for vector.
Header
#include <boost/mpl/deque.hpp>
Model of
—Variadic Sequence
—Random Access Sequence
—Extensible Sequence
—Back Extensible Sequence
—Front Extensible Sequence
Expression semantics
Seevectorspeciﬁcation.
Example
typedef deque<float,double,long double> floats;
typedef push_back<floats,int>::type types;
BOOST_MPL_ASSERT(( is_same< at_c<types,3>::type, int > ));
See also
Sequences ,vector,list,set
1.2.4 set
Description
setisavariadic,associative ,extensible sequenceoftypesthatsupportsconstant-timeinsertionandremovalofelements,
and testing for membership. A setmay contain at most one element for each key.
Header
Revision Date: 15th November 200423 Sequences 1.2 Classes
Sequence form Header
Variadic #include <boost/mpl/set.hpp>
Numbered #include <boost/mpl/set/set n.hpp>
Model of
—Variadic Sequence
—Associative Sequence
—Extensible Associative Sequence
Expression semantics
In the following table, sis an instance of set,posis an iterator into s, and x,k, andt1,t2,...tnare arbitrary types.
Expression Semantics
set< t1,t2,... tn>
setn<t1,t2,... tn>setof elements t1,t2,...tn; seeVariadic Sequence .
set< t1,t2,... tn>::type
setn<t1,t2,... tn>::typeIdentical to setn<t1,t2,...tn>; seeVariadic Sequence .
begin
::type An iterator pointing to the beginning of s; seeAssociative Se-
quence.
end
::type An iterator pointing to the end of s; seeAssociative Sequence .
size
::type The size of s; seeAssociative Sequence .
empty
::type Aboolean IntegralConstant csuchthat c::value == true ifand
only if sis empty; see Associative Sequence .
front
::type The ﬁrst element in s; seeAssociative Sequence .
has_key<s,k>::type Aboolean IntegralConstant csuchthat c::value == true ifand
onlyifthereisoneormoreelementswiththekey kins;seeAsso-
ciative Sequence .
count<s,k>::type The number of elements with the key kins; seeAssociative Se-
quence.
order<s,k>::type A unique unsigned Integral Constant associated with the key kin
s; seeAssociative Sequence .
at<s,k>::type
at<s,k,def>::typeThe element associated with the key kins; seeAssociative Se-
quence.
key_type<s,x>::type Identical to x; seeAssociative Sequence .
value_type<s,x>::type Identical to x; seeAssociative Sequence .
insert<s,x>::type A new setequivalent to sexcept 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 ;posis ignored.
erase_key<s,k>::type A new setequivalent to sexcept that has_key<t, k>::value
== false .
erase<s,pos>::type Equivalent to erase<s, deref<pos>::type >::type .
clear
::type An empty set; see clear.
Revision Date: 15th November 20041.2 Classes Sequences 24
Example
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<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_ > ));
See also
Sequences ,Variadic Sequence ,Associative Sequence ,Extensible Associative Sequence ,set_c,map,vector
1.2.5 map
Description
mapis avariadic,associative ,extensible sequence of type pairs that supports constant-time insertion and removal of
elements, and testing for membership. A mapmay contain at most one element for each key.
Header
Sequence form Header
Variadic #include <boost/mpl/map.hpp>
Numbered #include <boost/mpl/map/map n.hpp>
Model of
—Variadic Sequence
—Associative Sequence
—Extensible Associative Sequence
Expression semantics
In the following table and subsequent speciﬁcations, mis an instance of map,posis an iterator into m,xandp1,p2,...pn
arepairs, and kis an arbitrary type.
Expression Semantics
map< p1,p2,... pn>
mapn<p1,p2,... pn>mapof elements p1,p2,...pn; seeVariadic Sequence .
map< p1,p2,... pn>::type
mapn<p1,p2,... pn>::typeIdentical to mapn<p1,p2,...pn>; seeVariadic Sequence .
begin<m>::type An iterator pointing to the beginning of m; seeAssociative Se-
quence.
end<m>::type An iterator pointing to the end of m; seeAssociative Sequence .
size<m>::type The size of m; seeAssociative Sequence .
Revision Date: 15th November 200425 Sequences 1.2 Classes
Expression Semantics
empty<m>::type Aboolean IntegralConstant csuchthat c::value == true ifand
only if mis empty; see Associative Sequence .
front<m>::type The ﬁrst element in m; seeAssociative Sequence .
has_key<m,k>::type Queries the presence of elements with the key kinm; seeAssocia-
tive Sequence .
count<m,k>::type The number of elements with the key kinm; seeAssociative Se-
quence.
order<m,k>::type A unique unsigned Integral Constant associated with the key kin
m; seeAssociative Sequence .
at<m,k>::type
at<m,k,default>::typeThe element associated with the key kinm; seeAssociative Se-
quence.
key_type<m,x>::type Identical to x::first ; seeAssociative Sequence .
value_type<m,x>::type Identical to x::second ; seeAssociative Sequence .
insert<m,x>::type A new mapequivalent to mexcept that
at< t, key_type<m,x>::type >::type
is identical to value_type<m,x>::type .
insert<m,pos,x>::type Equivalent to insert<m,x>::type ;posis ignored.
erase_key<m,k>::type A new mapequivalent to mexcept that has_key<t, k>::value
== false .
erase<m,pos>::type Equivalent to erase<m, deref<pos>::type >::type .
clear<m>::type An empty map; see clear.
Example
typedef map<
pair<int,unsigned>
, pair<char,unsigned char>
, pair<long_<5>,char[17]>
, pair<int[42],bool>
> m;
BOOST_MPL_ASSERT_RELATION( size<m>::value, ==, 4 );
BOOST_MPL_ASSERT_NOT(( empty<m> ));
BOOST_MPL_ASSERT(( is_same< at<m,int>::type, unsigned > ));
BOOST_MPL_ASSERT(( is_same< at<m,long_<5> >::type, char[17] > ));
BOOST_MPL_ASSERT(( is_same< at<m,int[42]>::type, bool > ));
BOOST_MPL_ASSERT(( is_same< at<m,long>::type, void_ > ));
See also
Sequences ,Variadic Sequence ,Associative Sequence ,Extensible Associative Sequence ,set,vector
1.2.6 range_c
Synopsis
template<
Revision Date: 15th November 20041.2 Classes Sequences 26
typename T
, T Start
, T Finish
>
struct range_c
{
typedef integral_c<T,Start> start;
typedef integral_c<T,Finish> finish;
//unspecified
//...
};
Description
range_c isasorted RandomAccessSequence ofIntegralConstant s. Notethatbecauseitisnotan ExtensibleSequence ,
sequence-buildingintrinsicmetafunctionssuchas push_front andtransformationalgorithmssuchas replace arenot
directly applicable — to be able to use them, you’d ﬁrst need to copy the content of the range into a more suitable
sequence.
Header
#include <boost/mpl/range_c.hpp>
Model of
Random Access Sequence
Expression semantics
Inthefollowingtable, risaninstanceof range_c,nisanIntegralConstant ,Tisanarbitraryintegraltype,and nandm
are integral constant valuesof type T.
Expression Semantics
range_c<T,n,m>
range_c<T,n,m>::typeA sorted Random Access Sequence of integral constant wrappers for
the half-open range of values [ n,m):integral_c<T,n> ,integral_-
c<T,n+1> ,...integral_c<T,m-1> .
begin<r>::type Aniteratorpointingtothebeginningof r;seeRandomAccessSequence .
end<r>::type An iterator pointing to the endof r; seeRandom Access Sequence .
size<r>::type The size of r; seeRandom Access Sequence .
empty<r>::type Aboolean IntegralConstant csuchthat c::value == true ifandonly
ifris empty; see Random Access Sequence .
front<r>::type The ﬁrst element in r; seeRandom Access Sequence .
back<r>::type The last element in r; seeRandom Access Sequence .
at<r,n>::type Thenthelementfromthebeginningof r;seeRandomAccessSequence .
Example
typedef range_c<int,0,0> range0;
typedef range_c<int,0,1> range1;
Revision Date: 15th November 200427 Sequences 1.2 Classes
typedef range_c<int,0,10> range10;
BOOST_MPL_ASSERT_RELATION( size<range0>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( size<range1>::value, ==, 1 );
BOOST_MPL_ASSERT_RELATION( size<range10>::value, ==, 10 );
BOOST_MPL_ASSERT(( empty<range0> ));
BOOST_MPL_ASSERT_NOT(( empty<range1> ));
BOOST_MPL_ASSERT_NOT(( empty<range10> ));
BOOST_MPL_ASSERT(( is_same< begin<range0>::type, end<range0>::type > ));
BOOST_MPL_ASSERT_NOT(( is_same< begin<range1>::type, end<range1>::type > ));
BOOST_MPL_ASSERT_NOT(( is_same< begin<range10>::type, end<range10>::type > ));
BOOST_MPL_ASSERT_RELATION( front<range1>::type::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( back<range1>::type::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( front<range10>::type::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( back<range10>::type::value, ==, 9 );
See also
Sequences ,Random Access Sequence ,vector_c ,set_c,list_c
1.2.7 vector_c
Description
vector_c isanIntegralSequenceWrapper forvector. Assuch,itsharesall vectorcharacteristicsandrequirements,
and differs only in the way theoriginal sequence content is speciﬁed.
Header
Sequence form Header
Variadic #include <boost/mpl/vector_c.hpp>
Numbered #include <boost/mpl/vector/vector n_c.hpp>
Model of
—Integral Sequence Wrapper
—Variadic Sequence
—Random Access Sequence
—Extensible Sequence
—Back Extensible Sequence
—Front Extensible Sequence
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin vector.
Revision Date: 15th November 20041.2 Classes Sequences 28
Expression Semantics
vector_c<T, c1,c2,... cn>
vector n_c<T, c1,c2,... cn>Avectorof integral constant wrappers integral_-
c<T,c1>,integral_c<T, c2>, ... integral_c<T, cn>;
seeIntegral Sequence Wrapper .
vector_c<T, c1,c2,... cn>::type
vector n_c<T, c1,c2,... cn>::typeIdentical to vectorn< integral_c<T, c1>,integral_-
c<T,c2>, ...integral_c<T, cn> >; seeIntegral Sequence
Wrapper.
vector_c<T, c1,c2,... cn>::value_type
vector n_c<T, c1,c2,... cn>::value_typeIdentical to T; seeIntegral Sequence Wrapper .
Example
typedef vector_c<int,1,2,3,5,7,12,19,31> fibonacci;
typedef push_back<fibonacci,int_<50> >::type fibonacci2;
BOOST_MPL_ASSERT_RELATION( front<fibonacci2>::type::value, ==, 1 );
BOOST_MPL_ASSERT_RELATION( back<fibonacci2>::type::value, ==, 50 );
See also
Sequences ,Integral Sequence Wrapper ,vector,integral_c ,set_c,list_c,range_c
1.2.8 list_c
Description
list_cis anIntegral Sequence Wrapper forlist. As such, it shares all listcharacteristics and requirements, and
differs only in the way the original sequence content is speciﬁed.
Header
Sequence form Header
Variadic #include <boost/mpl/list_c.hpp>
Numbered #include <boost/mpl/list/list n_c.hpp>
Model of
—Integral Sequence Wrapper
—Variadic Sequence
—Forward Sequence
—Extensible Sequence
—Front Extensible Sequence
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin list.
Revision Date: 15th November 200429 Sequences 1.2 Classes
Expression Semantics
list_c<T, c1,c2,... cn>
list n_c<T, c1,c2,... cn>Alistof integral constant wrappers integral_c<T, c1>,
integral_c<T, c2>, ... integral_c<T, cn>; seeIntegral
Sequence Wrapper .
list_c<T, c1,c2,... cn>::type
list n_c<T, c1,c2,... cn>::typeIdentical to listn< integral_c<T, c1>,integral_-
c<T,c2>, ... integral_c<T, cn> >; seeIntegral Sequence
Wrapper.
list_c<T, c1,c2,... cn>::value_type
list n_c<T, c1,c2,... cn>::value_typeIdentical to T; seeIntegral Sequence Wrapper .
Example
typedef list_c<int,1,2,3,5,7,12,19,31> fibonacci;
typedef push_front<fibonacci,int_<1> >::type fibonacci2;
BOOST_MPL_ASSERT_RELATION( front<fibonacci2>::type::value, ==, 1 );
See also
Sequences ,Integral Sequence Wrapper ,list,integral_c ,vector_c ,set_c,range_c
1.2.9 set_c
Description
set_cis anIntegral Sequence Wrapper forset. As such, it shares all setcharacteristics and requirements, and differs
only in the way the original sequence content is speciﬁed.
Header
Sequence form Header
Variadic #include <boost/mpl/set_c.hpp>
Numbered #include <boost/mpl/set/set n_c.hpp>
Model of
—Variadic Sequence
—Associative Sequence
—Extensible Associative Sequence
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin set.
Expression Semantics
set_c<T, c1,c2,... cn>
setn_c<T, c1,c2,... cn>Asetof integral constant wrappers integral_c<T, c1>,
integral_c<T, c2>, ... integral_c<T, cn>; seeIntegral
Sequence Wrapper .
Revision Date: 15th November 20041.3 Views Sequences 30
Expression Semantics
set_c<T, c1,c2,... cn>::type
setn_c<T, c1,c2,... cn>::typeIdentical to setn< integral_c<T, c1>,integral_-
c<T,c2>, ... integral_c<T, cn> >; seeIntegral Sequence
Wrapper.
set_c<T, c1,c2,... cn>::value_type
setn_c<T, c1,c2,... cn>::value_typeIdentical to T; seeIntegral Sequence Wrapper .
Example
typedef set_c< int,1,3,5,7,9 > odds;
BOOST_MPL_ASSERT_RELATION( size<odds>::value, ==, 5 );
BOOST_MPL_ASSERT_NOT(( empty<odds> ));
BOOST_MPL_ASSERT(( has_key< odds, integral_c<int,5> > ));
BOOST_MPL_ASSERT_NOT(( has_key< odds, integral_c<int,4> > ));
BOOST_MPL_ASSERT_NOT(( has_key< odds, integral_c<int,15> > ));
See also
Sequences ,Integral Sequence Wrapper ,set,integral_c ,vector_c ,list_c,range_c
1.3 Views
Aviewis a sequence adaptor delivering an altered presentation of one or more underlying sequences. Views are lazy,
meaningthattheirelementsareonlycomputedondemand. Similarlytotheshort-circuit logicaloperations andeval_-
if, views make it possible to avoid premature errors and inefﬁciencies from computations whose results will never be
used. When approached with views in mind, many algorithmic problems can be solved in a simpler, more conceptually
precise, more expressive way.
1.3.1 empty_sequence
Synopsis
struct empty_sequence
{
//unspecified
//...
};
Description
Represents a sequence containing no elements.
Header
#include <boost/mpl/empty_sequence.hpp>
Revision Date: 15th November 200431 Sequences 1.3 Views
Expression semantics
Thesemanticsofanexpressionaredeﬁnedonlywheretheydifferfrom,orarenotdeﬁnedin RandomAccessSequence .
In the following table, sis an instance of empty_sequence .
Expression Semantics
empty_sequence An empty Random Access Sequence .
size
::type size
::value == 0 ; seeRandom Access Sequence .
Example
typedef begin<empty_sequence>::type first;
typedef end<empty_sequence>::type last;
BOOST_MPL_ASSERT(( is_same<first,last> ));
BOOST_MPL_ASSERT_RELATION( size<empty_sequence>::value, ==, 0 );
typedef transform_view<
empty_sequence
, add_pointer<_>
> empty_view;
BOOST_MPL_ASSERT_RELATION( size<empty_sequence>::value, ==, 0 );
See also
Sequences ,Views,vector,list,single_view
1.3.2 ﬁlter_view
Synopsis
template<
typename Sequence
, typename Pred
>
struct filter_view
{
//unspecified
//...
};
Description
A view into a subset of Sequence ’s elements satisfying the predicate Pred.
Header
#include <boost/mpl/filter_view.hpp>
Revision Date: 15th November 20041.3 Views Sequences 32
Model of
—Forward Sequence
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to wrap.
Pred UnaryLambda Expression A ﬁltering predicate.
Expression semantics
Semantics of an expression is deﬁned only where it differs from, or is not deﬁned in Forward Sequence .
In the following table, vis an instance of filter_view ,sis an arbitrary Forward Sequence ,predis an unary Lambda
Expression .
Expression Semantics
filter_view<s,pred>
filter_view<s,pred>::typeA lazyForward Sequence sequence of all the elements in the
range [ begin
::type ,end
::type ) that satisfy the predi-
catepred.
size<v>::type The size of v; size<v>::value == count_-
if<s,pred>::value ; linear complexity; see Forward Sequence .
Example
Find the largest ﬂoating typein a sequence.
typedef vector<int,float,long,float,char[50],long double,char> types;
typedef max_element<
transform_view< filter_view< types,boost::is_float<_> >, size_of<_> >
>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter::base>::type, long double > ));
See also
Sequences ,Views,transform_view ,joint_view ,zip_view ,iterator_range
1.3.3 iterator_range
Synopsis
template<
typename First
, typename Last
>
struct iterator_range
{
//unspecified
//...
Revision Date: 15th November 200433 Sequences 1.3 Views
};
Description
A view into subset of sequence elements identiﬁed by a pair of iterators.
Header
#include <boost/mpl/fold.hpp>
Model of
—Forward,Bidirectional , orRandom Access Sequence , depending on the category of the underlaying iterators.
Parameters
Parameter Requirement Description
First,Last Forward Iterator Iterators identifying the view’s boundaries.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Forward Sequence .
In the following table, vis an instance of iterator_range ,firstandlastare iterators into a Forward Sequence ,
and [ first,last) form a valid range.
Expression Semantics
iterator_range<first,last>
iterator_range<first,last>::typeA lazy sequence all the elements in the range [ first,last).
Example
typedef range_c<int,0,100> r;
typedef advance_c< begin<r>::type,10 >::type first;
typedef advance_c< end<r>::type,-10 >::type last;
BOOST_MPL_ASSERT(( equal<
iterator_range<first,last>
, range_c<int,10,90>
> ));
See also
Sequences ,Views,filter_view ,transform_view ,joint_view ,zip_view ,max_element
1.3.4 joint_view
Synopsis
template<
Revision Date: 15th November 20041.3 Views Sequences 34
typename Sequence1
, typename Sequence2
>
struct joint_view
{
//unspecified
//...
};
Description
A view into the sequence of elements formed by concatenating Sequence1 andSequence2 elements.
Header
#include <boost/mpl/joint_view.hpp>
Model of
—Forward Sequence
Parameters
Parameter Requirement Description
Sequence1 ,Sequence2 Forward Sequence Sequences to create a view on.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Forward Sequence .
In the following table, vis an instance of joint_view ,s1ands2are arbitrary Forward Sequence s.
Expression Semantics
joint_view<s1,s2>
joint_view<s1,s2>::typeA lazy Forward Sequence of all the elements in the ranges
[begin<s1>::type , end<s1>::type ), [ begin<s2>::type ,
end<s2>::type ).
size<v>::type The size of v; size<v>::value == size<s1>::value +
size<s2>::value ; linear complexity; see Forward Sequence .
Example
typedef joint_view<
range_c<int,0,10>
, range_c<int,10,15>
> numbers;
BOOST_MPL_ASSERT(( equal< numbers, range_c<int,0,15> > ));
Revision Date: 15th November 200435 Sequences 1.3 Views
See also
Sequences ,Views,filter_view ,transform_view ,zip_view ,iterator_range
1.3.5 single_view
Synopsis
template<
typename T
>
struct single_view
{
//unspecified
//...
};
Description
A view onto an arbitrary type Tas on a single-element sequence.
Header
#include <boost/mpl/single_view.hpp>
Model of
—Random Access Sequence
Parameters
Parameter Requirement Description
T Any type The type to be wrapped in a sequence.
Expression semantics
Thesemanticsofanexpressionaredeﬁnedonlywheretheydifferfrom,orarenotdeﬁnedin RandomAccessSequence .
In the following table, vis an instance of single_view ,xis an arbitrary type.
Expression Semantics
single_view<x>
single_view<x>::typeA single-element Random Access Sequence vsuch that
front<v>::type is identical to x.
size<v>::type The size of v;size<v>::value == 1 ; seeRandom Access Sequence .
Example
typedef single_view<int> view;
typedef begin<view>::type first;
typedef end<view>::type last;
Revision Date: 15th November 20041.3 Views Sequences 36
BOOST_MPL_ASSERT(( is_same< deref<first>::type,int > ));
BOOST_MPL_ASSERT(( is_same< next<first>::type,last > ));
BOOST_MPL_ASSERT(( is_same< prior<last>::type,first > ));
BOOST_MPL_ASSERT_RELATION( size<view>::value, ==, 1 );
See also
Sequences ,Views,iterator_range ,filter_view ,transform_view ,joint_view ,zip_view
1.3.6 transform_view
Synopsis
template<
typename Sequence
, typename F
>
struct transform_view
{
//unspecified
//...
};
Description
A view the full range of Sequence ’s transformed elements.
Header
#include <boost/mpl/transform_view.hpp>
Model of
—Forward Sequence
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to wrap.
F UnaryLambda Expression A transformation.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Forward Sequence .
In the following table, vis an instance of transform_view ,sis an arbitrary Forward Sequence , and fis an unary
Lambda Expression .
Revision Date: 15th November 200437 Sequences 1.3 Views
Expression Semantics
transform_view<s,f>
transform_view<s,f>::typeA lazyForward Sequence such that for each iin the range
[begin<v>::type ,end<v>::type ) and each jin for in the range
[begin
::type ,end
::type )deref<i>::type is identical to
apply< f, deref<j>::type >::type .
size<v>::type The size of v;size<v>::value == size
::value ; linear com-
plexity; see Forward Sequence .
Example
Find the largest type in a sequence.
typedef vector<int,long,char,char[50],double> types;
typedef max_element<
transform_view< types, size_of<_> >
>::type iter;
BOOST_MPL_ASSERT_RELATION( deref<iter>::type::value, ==, 50 );
See also
Sequences ,Views,filter_view ,joint_view ,zip_view ,iterator_range
1.3.7 zip_view
Synopsis
template<
typename Sequences
>
struct zip_view
{
//unspecified
//...
};
Description
Provides a “zipped” view onto several sequences; that is, represents several sequences as a single sequence of elements
each of which, in turn, is a sequence of the corresponding Sequences ’ elements.
Header
#include <boost/mpl/zip_view.hpp>
Model of
—Forward Sequence
Parameters
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 38
Parameter Requirement Description
Sequences AForward Sequence ofForward Sequence sSequences to be “zipped”.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Forward Sequence .
In the following table, vis an instance of zip_view ,seqaForward Sequence ofnForward Sequence s.
Expression Semantics
zip_view<seq>
zip_view<seq>::typeA lazyForward Sequence vsuch that for each iin [begin<v>::type ,
end<v>::type ) and for each jin [ begin<seq>::type ,
end<seq>::type )deref<i>::type is identical to transform<
deref<j>::type, deref<_1> >::type .
size<v>::type The size of v;size<v>::value is equal to
deref< min_element<
transform_view< seq, size<_1> >
>::type >::type::value;
linear complexity; see Forward Sequence .
Example
Element-wise sum of threevectors.
typedef vector_c<int,1,2,3,4,5> v1;
typedef vector_c<int,5,4,3,2,1> v2;
typedef vector_c<int,1,1,1,1,1> v3;
typedef transform_view<
zip_view< vector<v1,v2,v3> >
, unpack_args< plus<_1,_2,_3> >
> sum;
BOOST_MPL_ASSERT(( equal< sum, vector_c<int,7,7,7,7,7> > ));
See also
Sequences ,Views,filter_view ,transform_view ,joint_view ,single_view ,iterator_range
1.4 Intrinsic Metafunctions
The metafunctions that form the essential interface of sequence classesdocumented in the corresponding sequence
concepts are known as intrinsic sequence operations . They differ from generic sequence algorithms in that, in general,
they need to be implementedfrom scratch for each new sequence class1).
It’s worth noting that STL counterparts of these metafunctions are usually implemented as member functions.
1)Inpractice,manyofintrinsicmetafunctionsofferadefaultimplementationthatwillworkinmajorityofcases,giventhatyou’veimplementedthe
core functionality they rely on (such as begin/end).
Revision Date: 15th November 200439 Sequences 1.4 Intrinsic Metafunctions
1.4.1 at
Synopsis
template<
typename Sequence
, typename N
>
struct at
{
typedef unspecified type;
};
template<
typename AssocSeq
, typename Key
, typename Default = unspecified
>
struct at
{
typedef unspecified type;
};
Description
atis anoverloaded name :
—at<Sequence,N> returns the N-th element from the beginning of the Forward Sequence Sequence .
—at<AssocSeq,Key,Default> returnstheﬁrstelementassociatedwith KeyintheAssociativeSequence Assoc-
Seq, orDefault if no such element exists.
Header
#include <boost/mpl/at.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
AssocSeq Associative Sequence A sequence to be examined.
N Integral Constant An offset from the beginning of the sequence specifying
the element to be retrieved.
Key Any type A key for the element to beretrieved.
Default Any type A default value to return ifthe element is not found.
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 40
Expression semantics
For anyForward Sequence s, andIntegral Constant n:
typedef at<s,n>::type t;
Return type: A type.
Precondition: 0 <= n::value < size
::value .
Semantics: Equivalent to
typedef deref< advance< begin
::type,n >::type >::type t;
For anyAssociative Sequence s, and arbitrary types keyandx:
typedef at<s,key,x>::type t;
Return type: A type.
Semantics: Ifhas_key<s,key>::value == true ,tis the value type associated with key; otherwise t
is identical to x.
typedef at<s,key>::type t;
Return type: A type.
Semantics: Equivalent to
typedef at<s,key,void_>::type t;
Complexity
Sequence archetype Complexity
Forward Sequence Linear.
Random Access Sequence Amortized constant time.
Associative Sequence Amortized constant time.
Example
typedef range_c<long,10,50> range;
BOOST_MPL_ASSERT_RELATION( (at< range, int_<0> >::value), ==, 10 );
BOOST_MPL_ASSERT_RELATION( (at< range, int_<10> >::value), ==, 20 );
BOOST_MPL_ASSERT_RELATION( (at< range, int_<40> >::value), ==, 50 );
typedef set< int const,long*,double > s;
BOOST_MPL_ASSERT(( is_same< at<s,char>::type, void_ > ));
BOOST_MPL_ASSERT(( is_same< at<s,int>::type, int > ));
See also
Forward Sequence ,Random Access Sequence ,Associative Sequence ,at_c,front,back
Revision Date: 15th November 200441 Sequences 1.4 Intrinsic Metafunctions
1.4.2 at_c
Synopsis
template<
typename Sequence
, long n
>
struct at_c
{
typedef unspecified type;
};
Description
Returnsatypeidenticaltothe nthelementfromthebeginningofthesequence. at_c<Sequence,n>::type isashorcut
notation for at< Sequence, long_<n> >::type .
Header
#include <boost/mpl/at.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
n A compile-time integral constant Anoffsetfromthebeginningofthesequencespecify-
ing the element to be retrieved.
Expression semantics
typedef at_c<Sequence,n>::type t;
Return type: A type
Precondition: 0 <= n < size<Sequence>::value
Semantics: Equivalent to
typedef at< Sequence, long_<n> >::type t;
Complexity
Sequence archetype Complexity
Forward Sequence Linear.
Random Access Sequence Amortized constant time.
Example
typedef range_c<long,10,50> range;
BOOST_MPL_ASSERT_RELATION( (at_c< range,0 >::value), ==, 10 );
BOOST_MPL_ASSERT_RELATION( (at_c< range,10 >::value), ==, 20 );
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 42
BOOST_MPL_ASSERT_RELATION( (at_c< range,40 >::value), ==, 50 );
See also
Forward Sequence ,Random Access Sequence ,at,front,back
1.4.3 back
Synopsis
template<
typename Sequence
>
struct back
{
typedef unspecified type;
};
Description
Returns the last element inthe sequence.
Header
#include <boost/mpl/back.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Bidirectional Sequence A sequence to be examined.
Expression semantics
For anyBidirectional Sequence s:
typedef back
::type t;
Return type: A type.
Precondition: empty
::value == false .
Semantics: Equivalent to
typedef deref< prior< end
::type >::type >::type t;
Complexity
Amortized constant time.
Revision Date: 15th November 200443 Sequences 1.4 Intrinsic Metafunctions
Example
typedef range_c<int,0,1> range1;
typedef range_c<int,0,10> range2;
typedef range_c<int,-10,0> range3;
BOOST_MPL_ASSERT_RELATION( back<range1>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( back<range2>::value, ==, 9 );
BOOST_MPL_ASSERT_RELATION( back<range3>::value, ==, -1 );
See also
Bidirectional Sequence ,front,push_back ,end,deref,at
1.4.4 begin
Synopsis
template<
typename X
>
struct begin
{
typedef unspecified type;
};
Description
Returns an iterator that points to the ﬁrst element of the sequence. If the argument is not a Forward Sequence , returns
void_.
Header
#include <boost/mpl/begin_end.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
X Any type A type whose begin iterator, if any, will be returned.
Expression semantics
For any arbitrary type x:
typedef begin<x>::type first;
Return type: Forward Iterator orvoid_.
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 44
Semantics: Ifxis aForward Sequence ,firstis an iterator pointing to the ﬁrst element of s; otherwise
firstisvoid_.
Postcondition: Iffirstis an iterator, it is either dereferenceable or past-the-end; it is past-the-end if and
only if size<x>::value == 0 .
Complexity
Amortized constant time.
Example
typedef vector< unsigned char,unsigned short,
unsigned int,unsigned long > unsigned_types;
typedef begin<unsigned_types>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned char > ));
BOOST_MPL_ASSERT(( is_same< begin<int>::type, void_ > ));
See also
Iterators,Forward Sequence ,end,size,empty
1.4.5 clear
Synopsis
template<
typename Sequence
>
struct clear
{
typedef unspecified type;
};
Description
Returns an empty sequence concept-identical toSequence .
Header
#include <boost/mpl/clear.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Revision Date: 15th November 200445 Sequences 1.4 Intrinsic Metafunctions
Parameter Requirement Description
Sequence Extensible Sequence orExtensible Associa-
tive SequenceA sequence to get an empty “copy” of.
Expression semantics
For anyExtensible Sequence orExtensible Associative Sequence s:
typedef clear
::type t;
Return type: Extensible Sequence orExtensible Associative Sequence .
Semantics: Equivalent to
typedef erase< s, begin
::type, end
::type >::type t;
Postcondition: empty
::value == true .
Complexity
Amortized constant time.
Example
typedef vector_c<int,1,3,5,7,9,11> odds;
typedef clear<odds>::type nothing;
BOOST_MPL_ASSERT(( empty<nothing> ));
See also
Extensible Sequence ,Extensible Associative Sequence ,erase,empty,begin,end
1.4.6 empty
Synopsis
template<
typename Sequence
>
struct empty
{
typedef unspecified type;
};
Description
Returns an Integral Constant csuch that c::value == true if and only if the sequence is empty.
Header
#include <boost/mpl/empty.hpp>
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 46
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to test.
Expression semantics
For anyForward Sequence s:
typedef empty
::type c;
Return type: BooleanIntegral Constant .
Semantics: Equivalent to typedef is_same< begin
::type,end
::type >::type c; .
Postcondition: empty
::value == ( size
::value == 0 ) .
Complexity
Amortized constant time.
Example
typedef range_c<int,0,0> empty_range;
typedef vector<long,float,double> types;
BOOST_MPL_ASSERT( empty<empty_range> );
BOOST_MPL_ASSERT_NOT( empty<types> );
See also
Forward Sequence ,Integral Constant ,size,begin/end
1.4.7 end
Synopsis
template<
typename X
>
struct end
{
typedef unspecified type;
};
Description
Returns the sequence’s past-the-end iterator. If the argument is not a Forward Sequence , returns void_.
Revision Date: 15th November 200447 Sequences 1.4 Intrinsic Metafunctions
Header
#include <boost/mpl/begin_end.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
X Any type A type whose end iterator, if any, will be returned.
Expression semantics
For any arbitrary type x:
typedef end<x>::type last;
Return type: Forward Iterator orvoid_.
Semantics: IfxisForwardSequence ,lastisaniteratorpointingonepastthelastelementin s;otherwise
lastisvoid_.
Postcondition: Iflastis an iterator, it is past-the-end.
Complexity
Amortized constant time.
Example
typedef vector<long> v;
typedef begin<v>::type first;
typedef end<v>::type last;
BOOST_MPL_ASSERT(( is_same< next<first>::type, last > ));
See also
Iterators,Forward Sequence ,begin,end,next
1.4.8 erase
Synopsis
template<
typename Sequence
, typename First
, typename Last = unspecified
>
struct erase
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 48
{
typedef unspecified type;
};
Description
eraseperforms a removal of one ormore adjacent elements in the sequence starting from an arbitrary position.
Header
#include <boost/mpl/erase.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence ExtensibleSequence orExtensibleAsso-
ciative SequenceA sequence to erase from.
First Forward Iterator An iterator to the beginning ofthe range to be erased.
Last Forward Iterator An iterator past-the-end of the range to be erased.
Expression semantics
For anyExtensible Sequence s, and iterators pos,firstandlastintos:
typedef erase<s,first,last>::type r;
Return type: Extensible Sequence .
Precondition: [first,last) is a valid range in s.
Semantics: ris a new sequence, concept-identical tos, of the following elements: [ begin
::type ,
pos), [last,end
::type ).
Postcondition: The relative order of the elements in ris the same as in s;
size<r>::value == size
::value - distance<first,last>::value
typedef erase<s,pos>::type r;
Return type: Extensible Sequence .
Precondition: posis a dereferenceable iterator in s.
Semantics: Equivalent to
typedef erase< s,pos,next<pos>::type >::type r;
For anyExtensible Associative Sequence s, and iterator posintos:
typedef erase<s,pos>::type r;
Return type: Extensible Sequence .
Revision Date: 15th November 200449 Sequences 1.4 Intrinsic Metafunctions
Precondition: posis a dereferenceable iterator to s.
Semantics: Erases the element at a speciﬁc position pos; equivalent to erase_key<s,
deref<pos>::type >::type .
Postcondition: size<r>::value == size
::value - 1 .
Complexity
Sequence archetype Complexity (the range form)
Extensible Associative Sequence Amortized constant time.
Extensible Sequence Quadratic in the worst case, linear at best.
Example
typedef vector_c<int,1,0,5,1,7,5,0,5> values;
typedef find< values, integral_c<int,7> >::type pos;
typedef erase<values,pos>::type result;
BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 7 );
typedef find<result, integral_c<int,7> >::type iter;
BOOST_MPL_ASSERT(( is_same< iter, end<result>::type > ));
See also
Extensible Sequence ,Extensible Associative Sequence ,erase_key ,pop_front ,pop_back ,insert
1.4.9 erase_key
Synopsis
template<
typename AssocSeq
, typename Key
>
struct erase_key
{
typedef unspecified type;
};
Description
Erases elements associated with the key Keyin theExtensible Associative Sequence AssocSeq .
Header
#include <boost/mpl/erase_key.hpp>
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 50
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
AssocSeq Extensible Associative Sequence A sequence to erase elements from.
Key Any type A key for the elements to be removed.
Expression semantics
For anyExtensible Associative Sequence s, and arbitrary type key:
typedef erase_key<s,key>::type r;
Return type: Extensible Associative Sequence .
Semantics: risconcept-identical and equivalent to sexcept that has_key<r,k>::value == false .
Postcondition: size<r>::value == size
::value - 1 .
Complexity
Amortized constant time.
Example
typedef map< pair<int,unsigned>, pair<char,long> > m;
typedef erase_key<m,char>::type m1;
BOOST_MPL_ASSERT_RELATION( size<m1>::type::value, ==, 1 );
BOOST_MPL_ASSERT(( is_same< at<m1,char>::type,void_ > ));
BOOST_MPL_ASSERT(( is_same< at<m1,int>::type,unsigned > ));
See also
Extensible Associative Sequence ,erase,has_key,insert
1.4.10 front
Synopsis
template<
typename Sequence
>
struct front
{
typedef unspecified type;
};
Revision Date: 15th November 200451 Sequences 1.4 Intrinsic Metafunctions
Description
Returns the ﬁrst element inthe sequence.
Header
#include <boost/mpl/front.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
Expression semantics
For anyForward Sequence s:
typedef front
::type t;
Return type: A type.
Precondition: empty
::value == false .
Semantics: Equivalent to
typedef deref< begin
::type >::type t;
Complexity
Amortized constant time.
Example
typedef list<long>::type types1;
typedef list<int,long>::type types2;
typedef list<char,int,long>::type types3;
BOOST_MPL_ASSERT(( is_same< front<types1>::type, long > ));
BOOST_MPL_ASSERT(( is_same< front<types2>::type, int> ));
BOOST_MPL_ASSERT(( is_same< front<types3>::type, char> ));
See also
Forward Sequence ,back,push_front ,begin,deref,at
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 52
1.4.11 has_key
Synopsis
template<
typename Sequence
, typename Key
>
struct has_key
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant ifSequence contains an element with key Key.
Header
#include <boost/mpl/has_key.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Associative Sequence A sequence to query.
Key Any type The queried key.
Expression semantics
For anyAssociative Sequence s, and arbitrary type key:
typedef has_key<s,key>::type c;
Return type: BooleanIntegral Constant .
Semantics: c::value == true ifkeyis ins’s set of keys; otherwise c::value == false .
Complexity
Amortized constant time.
Example
typedef map< pair<int,unsigned>, pair<char,long> > m;
BOOST_MPL_ASSERT_NOT(( has_key<m,long> ));
typedef insert< m, pair<long,unsigned long> > m1;
BOOST_MPL_ASSERT(( has_key<m1,long> ));
Revision Date: 15th November 200453 Sequences 1.4 Intrinsic Metafunctions
See also
Associative Sequence ,count,insert,erase_key
1.4.12 insert
Synopsis
template<
typename Sequence
, typename Pos
, typename T
>
struct insert
{
typedef unspecified type;
};
template<
typename Sequence
, typename T
>
struct insert
{
typedef unspecified type;
};
Description
insertis anoverloaded name :
—insert<Sequence,Pos,T> performs an insertion of type Tat an arbitrary position PosinSequence .Posis
ignored is Sequence is a model of Extensible Associative Sequence .
—insert<Sequence,T> is a shortcut notation for insert<Sequence,Pos,T> for the case when Sequence is a
model of Extensible Associative Sequence .
Header
#include <boost/mpl/insert.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence ExtensibleSequence orExtensibleAsso-
ciative SequenceA sequence to insert into.
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 54
Parameter Requirement Description
Pos Forward Iterator An iterator in Sequence specifying the insertion po-
sition.
T Any type The element to be inserted.
Expression semantics
For anyExtensible Sequence s, iterator posins, and arbitrary type x:
typedef insert<s,pos,x>::type r;
Return type: Extensible Sequence
Precondition: posis an iterator in s.
Semantics: ris a sequence, concept-identical tos, of the following elements: [ begin
::type ,pos),
x, [pos,end
::type ).
Postcondition: The relative order of the elements in ris the same as in s.
at< r, distance< begin
::type,pos >::type >::type
is identical to x;
size<r>::value == size
::value + 1;
For anyExtensible Associative Sequence s, iterator posins, and arbitrary type x:
typedef insert<s,x>::type r;
Return type: Extensible Associative Sequence
Semantics: risconcept-identical and equivalent to s, except that at< r, key_type<s,x>::type
>::type is identical to value_type<s,x>::type .
Postcondition: size<r>::value == size
::value + 1 .
typedef insert<s,pos,x>::type r;
Return type: Extensible Associative Sequence
Precondition: posis an iterator in s.
Semantics: Equivalent to typedef insert<s,x>::type r ;posis ignored.
Complexity
Sequence archetype Complexity
Extensible Associative Sequence Amortized constant time.
Extensible Sequence Linear in the worst case, or amortized constant time.
Example
typedef vector_c<int,0,1,3,4,5,6,7,8,9> numbers;
typedef find< numbers,integral_c<int,3> >::type pos;
typedef insert< numbers,pos,integral_c<int,2> >::type range;
BOOST_MPL_ASSERT_RELATION( size<range>::value, ==, 10 );
BOOST_MPL_ASSERT(( equal< range,range_c<int,0,10> > ));
Revision Date: 15th November 200455 Sequences 1.4 Intrinsic Metafunctions
typedef map< mpl::pair<int,unsigned> > m;
typedef insert<m,mpl::pair<char,long> >::type m1;
BOOST_MPL_ASSERT_RELATION( size<m1>::value, ==, 2 );
BOOST_MPL_ASSERT(( is_same< at<m1,int>::type,unsigned > ));
BOOST_MPL_ASSERT(( is_same< at<m1,char>::type,long > ));
See also
Extensible Sequence ,Extensible Associative Sequence ,insert_range ,push_front ,push_back ,erase
1.4.13 insert_range
Synopsis
template<
typename Sequence
, typename Pos
, typename Range
>
struct insert_range
{
typedef unspecified type;
};
Description
insert_range performs an insertion of a range of elements at an arbitrary position in the sequence.
Header
#include <boost/mpl/insert_range.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence ExtensibleSequence orExtensibleAsso-
ciative SequenceA sequence to insert into.
Pos Forward Iterator An iterator in Sequence specifying the insertion po-
sition.
Range Forward Sequence The range of elements to be inserted.
Expression semantics
For anyExtensible Sequence s, iterator posins, andForward Sequence range:
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 56
typedef insert<s,pos,range>::type r;
Return type: Extensible Sequence .
Precondition: posis an iterator into s.
Semantics: ris a sequence, concept-identical tos, of the following elements: [ begin
::type ,pos),
[begin<r>::type ,end<r>::type ), [pos,end
::type ).
Postcondition: The relative order of the elements in ris the same as in s;
size<r>::value == size
::value + size<range>::value
Complexity
Sequence dependent. Quadratic in the worst case, linear at best; see the particular sequence class’ speciﬁcation for
details.
Example
typedef vector_c<int,0,1,7,8,9> numbers;
typedef find< numbers,integral_c<int,7> >::type pos;
typedef insert_range< numbers,pos,range_c<int,2,7> >::type range;
BOOST_MPL_ASSERT_RELATION( size<range>::value, ==, 10 );
BOOST_MPL_ASSERT(( equal< range,range_c<int,0,10> > ));
typedef insert_range<
list0<>
, end< list0<> >::type
, list<int>
>::type result2;
BOOST_MPL_ASSERT_RELATION( size<result2>::value, ==, 1 );
See also
Extensible Sequence ,insert,push_front ,push_back ,erase
1.4.14 is_sequence
Synopsis
template<
typename X
>
struct is_sequence
{
typedef unspecified type;
};
Description
Returns a boolean Integral Constant csuch that c::value == true if and only if Xis a model of Forward Sequence .
Revision Date: 15th November 200457 Sequences 1.4 Intrinsic Metafunctions
Header
#include <boost/mpl/is_sequence.hpp>
Parameters
Parameter Requirement Description
X Any type The type to query.
Expression semantics
typedef is_sequence<X>::type c;
Return type: BooleanIntegral Constant .
Semantics: Equivalent to
typedef not_< is_same< begin<T>::type,void_ > >::type c;
Complexity
Amortized constant time.
Example
struct UDT {};
BOOST_MPL_ASSERT_NOT(( is_sequence< std::vector<int> > ));
BOOST_MPL_ASSERT_NOT(( is_sequence< int > ));
BOOST_MPL_ASSERT_NOT(( is_sequence< int& > ));
BOOST_MPL_ASSERT_NOT(( is_sequence< UDT > ));
BOOST_MPL_ASSERT_NOT(( is_sequence< UDT* > ));
BOOST_MPL_ASSERT(( is_sequence< range_c<int,0,0> > ));
BOOST_MPL_ASSERT(( is_sequence< list<> > ));
BOOST_MPL_ASSERT(( is_sequence< list<int> > ));
BOOST_MPL_ASSERT(( is_sequence< vector<> > ));
BOOST_MPL_ASSERT(( is_sequence< vector<int> > ));
See also
Forward Sequence ,begin,end,vector,list,range_c
1.4.15 key_type
Synopsis
template<
typename Sequence
, typename X
>
struct key_type
{
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 58
typedef unspecified type;
};
Description
Returns the keythat would be used to identify XinSequence .
Header
#include <boost/mpl/key_type.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Associative Sequence A sequence to query.
X Any type The type to get the keyfor.
Expression semantics
For anyAssociative Sequence s, iterators pos1andpos2ins, and an artibrary type x:
typedef key_type<s,x>::type k;
Return type: A type.
Precondition: xcan be put in s.
Semantics: kis thekeythat would be used to identify xins.
Postcondition: Ifkey_type< s,deref<pos1>::type >::type is identical to key_type<
s,deref<pos2>::type >::type then pos1is identical to pos2.
Complexity
Amortized constant time.
Example
typedef key_type< map<>,pair<int,unsigned> >::type k1;
typedef key_type< set<>,pair<int,unsigned> >::type k2;
BOOST_MPL_ASSERT(( is_same< k1,int > ));
BOOST_MPL_ASSERT(( is_same< k2,pair<int,unsigned> > ));
See also
Associative Sequence ,value_type ,has_key,set,map
Revision Date: 15th November 200459 Sequences 1.4 Intrinsic Metafunctions
1.4.16 order
Synopsis
template<
typename Sequence
, typename Key
>
struct order
{
typedef unspecified type;
};
Description
Returns a unique unsigned Integral Constant associated with the key KeyinSequence .
Header
#include <boost/mpl/order.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Associative Sequence A sequence to query.
Key Any type The queried key.
Expression semantics
For anyAssociative Sequence s, and arbitrary type key:
typedef order<s,key>::type n;
Return type: Unsigned Integral Constant .
Semantics: Ifhas_key<s,key>::value == true ,nis a unique unsigned Integral Constant associated
with keyins; otherwise, nis identical to void_.
Complexity
Amortized constant time.
Example
typedef map< pair<int,unsigned>, pair<char,long> > m;
BOOST_MPL_ASSERT_NOT(( is_same< order<m,int>::type, void_ > ));
BOOST_MPL_ASSERT(( is_same< order<m,long>::type,void_ > ));
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 60
See also
Associative Sequence ,has_key,count,map
1.4.17 pop_back
Synopsis
template<
typename Sequence
>
struct pop_back
{
typedef unspecified type;
};
Description
pop_back performs a removal at the endof the sequence with guaranteed O(1)complexity.
Header
#include <boost/mpl/pop_back.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Back Extensible Sequence A sequence to erase the last element from.
Expression semantics
For anyBack Extensible Sequence s:
typedef pop_back
::type r;
Return type: Back Extensible Sequence .
Precondition: empty
::value == false .
Semantics: Equivalent to erase<s,end
::type>::type; .
Postcondition: size<r>::value == size
::value - 1 .
Complexity
Amortized constant time.
Revision Date: 15th November 200461 Sequences 1.4 Intrinsic Metafunctions
Example
typedef vector<long>::type types1;
typedef vector<long,int>::type types2;
typedef vector<long,int,char>::type types3;
typedef pop_back<types1>::type result1;
typedef pop_back<types2>::type result2;
typedef pop_back<types3>::type result3;
BOOST_MPL_ASSERT_RELATION( size<result1>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( size<result2>::value, ==, 1 );
BOOST_MPL_ASSERT_RELATION( size<result3>::value, ==, 2 );
BOOST_MPL_ASSERT(( is_same< back<result2>::type, long> ));
BOOST_MPL_ASSERT(( is_same< back<result3>::type, int > ));
See also
Back Extensible Sequence ,erase,push_back ,back,pop_front
1.4.18 pop_front
Synopsis
template<
typename Sequence
>
struct pop_front
{
typedef unspecified type;
};
Description
pop_front performs a removal at the beginning of the sequence with guaranteed O(1)complexity.
Header
#include <boost/mpl/pop_front.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Front Extensible Sequence A sequence to erase the ﬁrstelement from.
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 62
Expression semantics
For anyFront Extensible Sequence s:
typedef pop_front
::type r;
Return type: Front Extensible Sequence .
Precondition: empty
::value == false .
Semantics: Equivalent to erase<s,begin
::type>::type; .
Postcondition: size<r>::value == size
::value - 1 .
Complexity
Amortized constant time.
Example
typedef vector<long>::type types1;
typedef vector<int,long>::type types2;
typedef vector<char,int,long>::type types3;
typedef pop_front<types1>::type result1;
typedef pop_front<types2>::type result2;
typedef pop_front<types3>::type result3;
BOOST_MPL_ASSERT_RELATION( size<result1>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( size<result2>::value, ==, 1 );
BOOST_MPL_ASSERT_RELATION( size<result3>::value, ==, 2 );
BOOST_MPL_ASSERT(( is_same< front<result2>::type, long > ));
BOOST_MPL_ASSERT(( is_same< front<result3>::type, int > ));
See also
Front Extensible Sequence ,erase,push_front ,front,pop_back
1.4.19 push_back
Synopsis
template<
typename Sequence
, typename T
>
struct push_back
{
typedef unspecified type;
};
Revision Date: 15th November 200463 Sequences 1.4 Intrinsic Metafunctions
Description
push_back performs an insertion at the end of the sequence with guaranteed O(1)complexity.
Header
#include <boost/mpl/push_back.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Back Extensible Sequence A sequence to insert into.
T Any type The element to be inserted.
Expression semantics
For anyBack Extensible Sequence sand arbitrary type x:
typedef push_back<s,x>::type r;
Return type: Back Extensible Sequence .
Semantics: Equivalent to
typedef insert< s,end
::type,x >::type r;
Postcondition: back<r>::type is identical to x;
size<r>::value == size
::value + 1
Complexity
Amortized constant time.
Example
typedef vector_c<bool,false,false,false,
true,true,true,false,false> bools;
typedef push_back<bools,false_>::type message;
BOOST_MPL_ASSERT_RELATION( back<message>::type::value, ==, false );
BOOST_MPL_ASSERT_RELATION(
( count_if<message, equal_to<_1,false_> >::value ), ==, 6
);
See also
Back Extensible Sequence ,insert,pop_back ,back,push_front
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 64
1.4.20 push_front
Synopsis
template<
typename Sequence
, typename T
>
struct push_front
{
typedef unspecified type;
};
Description
push_front performs an insertion at thebeginning of the sequence with guaranteed O(1)complexity.
Header
#include <boost/mpl/push_front.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Front Extensible Sequence A sequence to insert into.
T Any type The element to be inserted.
Expression semantics
For anyFront Extensible Sequence sand arbitrary type x:
typedef push_front<s,x>::type r;
Return type: Front Extensible Sequence .
Semantics: Equivalent to
typedef insert< s,begin
::type,x >::type r;
Postcondition: size<r>::value == size
::value + 1 ;front<r>::type is identical to x.
Complexity
Amortized constant time.
Example
typedef vector_c<int,1,2,3,5,8,13,21> v;
BOOST_MPL_ASSERT_RELATION( size<v>::value, ==, 7 );
Revision Date: 15th November 200465 Sequences 1.4 Intrinsic Metafunctions
typedef push_front< v,integral_c<int,1> >::type fibonacci;
BOOST_MPL_ASSERT_RELATION( size<fibonacci>::value, ==, 8 );
BOOST_MPL_ASSERT(( equal<
fibonacci
, vector_c<int,1,1,2,3,5,8,13,21>
, equal_to<_,_>
> ));
See also
Front Extensible Sequence ,insert,pop_front ,front,push_back
1.4.21 sequence_tag
Synopsis
template<
typename X
>
struct sequence_tag
{
typedef unspecified type;
};
Description
sequence_tag is atag metafunction for alltag dispatched intrinsic sequence operations .
Header
#include <boost/mpl/sequence_tag.hpp>
Parameters
Parameter Requirement Description
X Any type A type to obtain a sequence tag for.
Expression semantics
For any arbitrary type x:
typedef sequence_tag<x>::type tag;
Return type: A type.
Semantics: tagis an unspeciﬁed tag type for x.
Complexity
Amortized constant time.
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 66
See also
Intrinsic Metafunctions ,Tag Dispatched Metafunction
1.4.22 size
Synopsis
template<
typename Sequence
>
struct size
{
typedef unspecified type;
};
Description
sizereturns the number of elements in the sequence, that is, the number of elements in the range
[begin<Sequence>::type ,end<Sequence>::type ).
Header
#include <boost/mpl/size.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to query.
Expression semantics
For anyForward Sequence s:
typedef size
::type n;
Return type: Integral Constant .
Semantics: Equivalent to
typedef distance< begin
::type,end
::type >::type n;
Postcondition: n::value >= 0 .
Complexity
Thecomplexityofthe sizemetafunctiondirectlydependsontheimplementationoftheparticularsequenceitisapplied
to. In the worst case, sizeguarantees a linear complexity.
Revision Date: 15th November 200467 Sequences 1.4 Intrinsic Metafunctions
If the sis aRandom Access Sequence ,size
::type is anO(1)operation. The opposite is not necessarily true —
for example, a sequence classthat models Forward Sequence might still give us an O(1) sizeimplementation.
Example
typedef list0<> empty_list;
typedef vector_c<int,0,1,2,3,4,5> numbers;
typedef range_c<int,0,100> more_numbers;
BOOST_MPL_ASSERT_RELATION( size<list>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( size<numbers>::value, ==, 5 );
BOOST_MPL_ASSERT_RELATION( size<more_numbers>::value, ==, 100 );
See also
Forward Sequence ,Random Access Sequence ,empty,begin,end,distance
1.4.23 value_type
Synopsis
template<
typename Sequence
, typename X
>
struct value_type
{
typedef unspecified type;
};
Description
Returns the valuethat would be used for element XinSequence .
Header
#include <boost/mpl/value_type.hpp>
Model of
Tag Dispatched Metafunction
Parameters
Parameter Requirement Description
Sequence Associative Sequence A sequence to query.
X Any type The type to get the valuefor.
Revision Date: 15th November 20041.4 Intrinsic Metafunctions Sequences 68
Expression semantics
For anyAssociative Sequence s, and an artibrary type x:
typedef value_type<s,x>::type v;
Return type: A type.
Precondition: xcan be put in s.
Semantics: vis thevaluethat would be used for xins.
Postcondition: If .. parsed-literal:
has_key< s,key_type<s,x>::type >::type
then .. parsed-literal:
at< s,key_type<s,x>::type >::type
is identical to value_type<s,x>::type .
Complexity
Amortized constant time.
Example
typedef value_type< map<>,pair<int,unsigned> >::type v1;
typedef value_type< set<>,pair<int,unsigned> >::type v2;
BOOST_MPL_ASSERT(( is_same< v1,unsigned > ));
BOOST_MPL_ASSERT(( is_same< v2,pair<int,unsigned> > ));
See also
Associative Sequence ,key_type ,at,set,map
Revision Date: 15th November 2004Chapter 2 Iterators
Iteratorsaregenericmeansofaddressingaparticularelementorarangeofsequentialelementsinasequence. Theyare
alsoamechanismthatmakesitpossibletodecouple algorithms fromconcretecompile-time sequenceimplementations .
Under the hood, all MPL sequence algorithms are implemented in terms of iterators. In particular, that means that they
will work on any custom compile-time sequence, given that the appropriate iterator inteface is provided.
2.1 Concepts
All iterators in MPL are classiﬁed into three iterator concepts, or categories , named according to the type of traversal
provided. The categories are: Forward Iterator ,Bidirectional Iterator , andRandom Access Iterator . The concepts are
hierarchical: Random Access Iterator is a reﬁnement of Bidirectional Iterator , which, in its turn, is a reﬁnement of
Forward Iterator .
Becauseoftheinherentlyimmutablenatureofthevalueaccess,MPLiteratorsescapetheproblemsofthetraversal-only
categorization discussed atlength in [ n1550].
2.1.1 Forward Iterator
Description
AForward Iterator iis a type that represents a positional reference to an element of a Forward Sequence . It allows to
access the element through a dereference operation, and provides a way to obtain an iterator to the next element in a
sequence.
Deﬁnitions
—An iterator can be dereferenceable , meaning that deref<i>::type is a well-deﬁned expression.
—An iterator is past-the-end if it points beyond the last element of a sequence; past-the-end iterators are non-
dereferenceable.
—An iterator iisincrementable if there is a “next” iterator, that is, if next<i>::type expression is well-deﬁned;
past-the-end iterators arenot incrementable.
—Two iterators into the same sequence are equivalent if they have the same type.
—An iterator jisreachable from an iterator iif , after recursive application of nextmetafunction to ia ﬁnite
number of times, iis equivalent to j.
—The notation [ i,j) refers to a rangeof iterators beginning with iand up to but not including j.
—The range [ i,j) is a valid range ifjis reachable from i.
Expression requirements2.1 Concepts Iterators 70
Expression Type Complexity
deref<i>::type Any type Amortized constant time
next<i>::type Forward Iterator Amortized constant time
i::category Integral Constant , convertible to forward_itera-
tor_tagConstant time
Expression semantics
typedef deref<i>::type j;
Precondition: iis dereferenceable
Semantics: jis identical to the type of thepointed element
typedef next<i>::type j;
Precondition: iis incrementable
Semantics: jis the next iterator in a sequence
Postcondition: jis dereferenceable or past-the-end
typedef i::category c;
Semantics: cis identical to the iterator’scategory tag
Invariants
For any forward iterators iandjthe following invariants always hold:
—iandjare equivalent if and only if theyare pointing to the same element.
—Ifiis dereferenceable, and jis equivalent to i, then jis dereferenceable as well.
—Ifiandjare equivalent and dereferenceable, then deref<i>::type andderef<j>::type are identical.
—Ifiis incrementable, and jis equivalent to i, then jis incrementable as well.
—Ifiandjare equivalent and incrementable, then next<i>::type andnext<j>::type are equivalent.
See also
Iterators,Bidirectional Iterator ,Forward Sequence ,deref,next
2.1.2 Bidirectional Iterator
Description
ABidirectional Iterator is aForward Iterator that provides a way to obtain an iterator to the previous element in a
sequence.
Reﬁnement of
Forward Iterator
Revision Date: 15th November 200471 Iterators 2.1 Concepts
Deﬁnitions
—abidirectionaliterator iisdecrementable ifthereisa“previous”iterator,thatis,if prior<i>::type expression
is well-deﬁned; iteratorspointing to the ﬁrst element of the sequence are not decrementable.
Expression requirements
In addition to the requirements deﬁned in Forward Iterator , the following requirementsmust be met.
Expression Type Complexity
next<i>::type Bidirectional Iterator Amortized constant time
prior<i>::type Bidirectional Iterator Amortized constant time
i::category Integral Constant , convertible to bidirec-
tional_iterator_tagConstant time
Expression semantics
typedef prior<i>::type j;
Precondition: iis decrementable
Semantics: jis an iterator pointing to theprevious element of the sequence
Postcondition: jis dereferenceable and incrementable
Invariants
For any bidirectional iterators iandjthe following invariants always hold:
—Ifiis incrementable, then prior< next<i>::type >::type is a null operation; similarly, if iis decre-
mentable, next< prior<i>::type >::type is a null operation.
See also
Iterators,Forward Iterator ,Random Access Iterator ,Bidirectional Sequence ,prior
2.1.3 Random Access Iterator
Description
ARandom Access Iterator is aBidirectional Iterator that provides constant-time guarantees on moving the iterator
an arbitrary number of positions forward or backward and for measuring the distance to another iterator in the same
sequence.
Reﬁnement of
Bidirectional Iterator
Expression requirements
In addition to the requirements deﬁned in Bidirectional Iterator , the following requirementsmust be met.
Revision Date: 15th November 20042.2 Iterator Metafunctions Iterators 72
Expression Type Complexity
next<i>::type Random Access Iterator Amortized constant time
prior<i>::type Random Access Iterator Amortized constant time
i::category Integral Constant , convertible to random_ac-
cess_iterator_tagConstant time
advance<i,n>::type Random Access Iterator Amortized constant time
distance<i,j>::type Integral Constant Amortized constant time
Expression semantics
typedef advance<i,n>::type j;
Semantics: Seeadvance speciﬁcation
typedef distance<i,j>::type n;
Semantics: Seedistance speciﬁcation
Invariants
For any random access iterators iandjthe following invariants always hold:
—Ifadvance<i,n>::type is well-deﬁned, then advance< advance<i,n>::type, negate<n>::type
>::type is a null operation.
See also
Iterators,Bidirectional Iterator ,Random Access Sequence ,advance,distance
2.2 Iterator Metafunctions
2.2.1 advance
Synopsis
template<
typename Iterator
, typename N
>
struct advance
{
typedef unspecified type;
};
Description
Moves Iterator by the distance N. Forbidirectional andrandom access iterators, the distance may be negative.
Header
#include <boost/mpl/advance.hpp>
Revision Date: 15th November 200473 Iterators 2.2 Iterator Metafunctions
Parameters
Parameter Requirement Description
Iterator Forward Iterator An iterator to advance.
N Integral Constant A distance.
Model Of
Tag Dispatched Metafunction
Expression semantics
For aForward Iterator iterand arbitrary Integral Constant n:
typedef advance<iter,n>::type j;
Return type: Forward Iterator .
Precondition: IfIterator is aForward Iterator ,n::value must be nonnegative.
Semantics: Equivalent to:
typedef iter i0;
typedef next<i0>::type i1;
...
typedef next<i n-1>::type j;
ifn::value > 0 , and
typedef iter i0;
typedef prior<i0>::type i1;
...
typedef prior<i n-1>::type j;
otherwise.
Postcondition: jis dereferenceable or past-the-end; distance<iter,j>::value == n::value if
n::value > 0 , and distance<j,iter>::value == n::value otherwise.
Complexity
Amortized constant time if iteris a model of Random Access Iterator , otherwise linear time.
Example
typedef range_c<int,0,10> numbers;
typedef begin<numbers>::type first;
typedef end<numbers>::type last;
typedef advance<first,int_<10> >::type i1;
typedef advance<last,int_<-10> >::type i2;
BOOST_MPL_ASSERT(( boost::is_same<i1,last> ));
BOOST_MPL_ASSERT(( boost::is_same<i2,first> ));
Revision Date: 15th November 20042.2 Iterator Metafunctions Iterators 74
See also
Iterators,Tag Dispatched Metafunction ,distance ,next
2.2.2 distance
Synopsis
template<
typename First
, typename Last
>
struct distance
{
typedef unspecified type;
};
Description
Returns the distance between Firstand Lastiterators, that is, an Integral Constant nsuch that ad-
vance<First,n>::type is identical to Last.
Header
#include <boost/mpl/distance.hpp>
Parameters
Parameter Requirement Description
First,Last Forward Iterator Iterators to compute a distance between.
Model Of
Tag Dispatched Metafunction
Expression semantics
For anyForward Iterator sfirstandlast:
typedef distance<first,last>::type n;
Return type: Integral Constant .
Precondition: [first,last) is a valid range.
Semantics: Equivalent to
typedef iter_fold<
iterator_range<first,last>
, long_<0>
, next<_1>
>::type n;
Postcondition: is_same< advance<first,n>::type, last >::value == true .
Revision Date: 15th November 200475 Iterators 2.2 Iterator Metafunctions
Complexity
Amortized constant time if firstandlastareRandom Access Iterator s, otherwise linear time.
Example
typedef range_c<int,0,10>::type range;
typedef begin<range>::type first;
typedef end<range>::type last;
BOOST_MPL_ASSERT_RELATION( (distance<first,last>::value), ==, 10);
See also
Iterators,Tag Dispatched Metafunction ,advance,next,prior
2.2.3 next
Synopsis
template<
typename Iterator
>
struct next
{
typedef unspecified type;
};
Description
Returns the next iterator in the sequence. [ Note: nexthas a number of overloaded meanings, depending on the type of
its argument. For instance, if Xis anIntegral Constant ,next<X> returns an incremented Integral Constant of the same
type. The following speciﬁcation is iterator-speciﬁc. Please refer to the corresponding concept’s documentation for the
details of the alternative semantics — end note].
Header
#include <boost/mpl/next_prior.hpp>
Parameters
Parameter Requirement Description
Iterator Forward Iterator . An iterator to increment.
Expression semantics
For anyForward Iterator siter:
typedef next<iter>::type j;
Return type: Forward Iterator .
Revision Date: 15th November 20042.2 Iterator Metafunctions Iterators 76
Precondition: iteris incrementable.
Semantics: jis an iterator pointing to the next element in the sequence, or is past-the-end. If iteris a
user-deﬁned iterator, the library-provided default implementation is equivalent to
typedef iter::next j;
Complexity
Amortized constant time.
Example
typedef vector_c<int,1> v;
typedef begin<v>::type first;
typedef end<v>::type last;
BOOST_MPL_ASSERT(( is_same< next<first>::type, last > ));
See also
Iterators,begin/end,prior,deref
2.2.4 prior
Synopsis
template<
typename Iterator
>
struct prior
{
typedef unspecified type;
};
Description
Returns the previous iterator in the sequence. [ Note: priorhas a number of overloaded meanings, depending on the
typeofitsargument. Forinstance,if XisanIntegralConstant ,prior<X> returnsandecremented IntegralConstant ofthe
same type. The following speciﬁcation is iterator-speciﬁc. Please refer to the corresponding concept’s documentation
for the details of the alternative semantics — end note].
Header
#include <boost/mpl/next_prior.hpp>
Parameters
Parameter Requirement Description
Iterator Forward Iterator . An iterator to decrement.
Revision Date: 15th November 200477 Iterators 2.2 Iterator Metafunctions
Expression semantics
For anyForward Iterator siter:
typedef prior<iter>::type j;
Return type: Forward Iterator .
Precondition: iteris decrementable.
Semantics: jis an iterator pointing to the previous element in the sequence. If iteris a user-deﬁned
iterator, the library-provided default implementation is equivalent to
typedef iter::prior j;
Complexity
Amortized constant time.
Example
typedef vector_c<int,1> v;
typedef begin<v>::type first;
typedef end<v>::type last;
BOOST_MPL_ASSERT(( is_same< prior<last>::type, first > ));
See also
Iterators,begin/end,next,deref
2.2.5 deref
Synopsis
template<
typename Iterator
>
struct deref
{
typedef unspecified type;
};
Description
Dereferences an iterator.
Header
#include <boost/mpl/deref.hpp>
Parameters
Revision Date: 15th November 20042.2 Iterator Metafunctions Iterators 78
Parameter Requirement Description
Iterator Forward Iterator The iterator to dereference.
Expression semantics
For anyForward Iterator siter:
typedef deref<iter>::type t;
Return type: A type.
Precondition: iteris dereferenceable.
Semantics: tisidentical totheelement referencedby iter. Ifiterisa user-deﬁnediterator,the library-
provided default implementation is equivalent to
typedef iter::type t;
Complexity
Amortized constant time.
Example
typedef vector<char,short,int,long> types;
typedef begin<types>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter>::type, char > ));
See also
Iterators,begin/end,next
2.2.6 iterator_category
Synopsis
template<
typename Iterator
>
struct iterator_category
{
typedef typename Iterator::category type;
};
Description
Returns one of the following iterator category tags:
—forward_iterator_tag
—bidirectional_iterator_tag
—random_access_iterator_tag
Revision Date: 15th November 200479 Iterators 2.2 Iterator Metafunctions
Header
#include <boost/mpl/iterator_category.hpp>
#include <boost/mpl/iterator_tags.hpp>
Parameters
Parameter Requirement Description
Iterator Forward Iterator The iterator to obtain a category for.
Expression semantics
For anyForward Iterator siter:
typedef iterator_category<iter>::type tag;
Return type: Integral Constant .
Semantics: tagisforward_iterator_tag ifiteris a model of Forward Iterator ,bidirectional_-
iterator_tag ifiteris a model of Bidirectional Iterator , orrandom_access_iterator_tag if
iteris a model of Random Access Iterator ;
Postcondition: forward_iterator_tag::value < bidirectional_iterator_tag::value ,
bidirectional_iterator_tag::value < random_access_iterator_tag::value .
Complexity
Amortized constant time.
Example
template< typename Tag, typename Iterator >
struct algorithm_impl
{
//O(n) implementation
};
template< typename Iterator >
struct algorithm_impl<random_access_iterator_tag,Iterator>
{
//O(1) implementation
};
template< typename Iterator >
struct algorithm
: algorithm_impl<
iterator_category<Iterator>::type
, Iterator
>
{
};
Revision Date: 15th November 20042.2 Iterator Metafunctions Iterators 80
See also
Iterators,begin/end,advance,distance ,next
Revision Date: 15th November 2004Chapter 3 Algorithms
The MPL provides a broad range of fundamental algorithms aimed to satisfy the majority of sequential compile-time
data processing needs. The algorithms include compile-time counterparts of many of the STL algorithms, iteration
algorithms borrowed from functional programming languages, and more.
UnlikethealgorithmsintheC++StandardLibrary,whichoperateonimplict iteratorranges ,themajorityofMPLcoun-
terpartstakeandreturn sequences . ThisderivationisnotdictatedbythefunctionalnatureofC++compile-timecompu-
tationsperse,butratherbyadesiretoimprovegeneralusabilityofthelibrary,makingprogrammingwithcompile-time
data structures as enjoyableas possible.
In the spirit of the STL, MPL algorithms are generic, meaning that they are not tied to particular sequence class imple-
mentations, and can operate on a wide range of arguments as long as they satisfy the documented requirements. The
requirements are formulated in terms of concepts. Under the hood, algorithms are decoupled from concrete sequence
implementations by operating on Iterators.
All MPL algorithms can be sorted into three major categories: iteration algorithms, querying algorithms, and transfor-
mation algorithms. The transformation algorithms introduce an associated Inserterconcept, a rough equivalent for the
notionof OutputIterator intheStandardLibrary. Moreover,everytransformationalgorithmprovidesa reverse_ coun-
terpart,allowingforawiderrangeofefﬁcienttransformations—acommonfunctionalitydocumentedbythe Reversible
Algorithm concept.
3.1 Concepts
3.1.1 Inserter
Description
AnInserterisacompile-timesubstituteforSTL OutputIterator . Underthehood,it’ssimplyatypeholdingtwoentities:
astateandanoperation . Whenpassedtoa transformationalgorithm ,theinserter’sbinaryoperationisinvokedforevery
elementthatwouldnormallybewrittenintotheoutputiterator,withtheelementitself(asthesecondargument)andthe
result of the previous operation’s invocation — or, for the very ﬁrst element, the inserter’s initial state.
Technically, instead of taking a single inserter parameter, transformation algorithms could accept the state and the
“output” operation separately. Grouping these in a single parameter entity, however, brings the algorithms semantically
and syntactically closer to their STL counterparts, signiﬁcantly simplifying many ofthe common use cases.
Valid expressions
In the following table and subsequent speciﬁcations, inis a model of Inserter.
Expression Type
in::state Any type
in::operation BinaryLambda Expression3.1 Concepts Algorithms 82
Expression semantics
Expression Semantics
in::state The inserter’s initial state.
in::operation The inserter’s “output” operation.
Example
typedef transform<
range_c<int,0,10>
, plus<_1,_1>
, back_inserter< vector0<> >
>::type result;
Models
—inserter
—front_inserter
—back_inserter
See also
Algorithms ,Transformation Algorithms ,inserter ,front_inserter ,back_inserter
3.1.2 Reversible Algorithm
Description
AReversible Algorithm is a member of a pair of transformation algorithms that iterate over their input sequence(s) in
opposite directions. For each reversible algorithm xthere exists a counterpart algorithm reverse_x , that exhibits the
exact semantics of xexcept that the elements of its input sequence argument(s) are processed in the reverseorder.
Expression requirements
Inthefollowingtableandsubsequentspeciﬁcations, xisaplaceholdertokenfortheactual ReversibleAlgorithm ’sname,
s1,s2,...snareForward Sequence s, and inis anInserter.
Expression Type Complexity
x<s1,s2,...sn, ...>::type Forward Sequence Unspeciﬁed.
x<s1,s2,...sn, ...in>::type Any type Unspeciﬁed.
reverse_x< s1,s2,...sn, ...>::type Forward Sequence Unspeciﬁed.
reverse_x< s1,s2,...sn, ...in>::type Any type Unspeciﬁed.
Expression semantics
typedef x< s1,s2,... sn,...>::type t;
Precondition: s1is anExtensible Sequence .
Revision Date: 15th November 200483 Algorithms 3.1 Concepts
Semantics: tis equivalent to
x<
s1,s2,... sn,...
, back_inserter< clear< s1>::type >
>::type
ifhas_push_back< s1>::value == true and
reverse_x<
s1,s2,... sn,...
, front_inserter< clear< s1>::type >
>::type
otherwise.
typedef x< s1,s2,... sn,...in>::type t;
Semantics: tis the result of an xinvocation with arguments s1,s2,...sn,...in.
typedef reverse_x< s1,s2,... sn,... >::type t;
Precondition: s1is anExtensible Sequence .
Semantics: tis equivalent to
x<
s1,s2,... sn,...
, front_inserter< clear< s1>::type >
>::type
ifhas_push_front< s1>::value == true and
reverse_x<
s1,s2,... sn,...
, back_inserter< clear< s1>::type >
>::type
otherwise.
typedef reverse_x< s1,s2,... sn,... in>::type t;
Semantics: tis the result of a reverse_x invocation with arguments s1,s2,...sn,...in.
Example
typedef transform<
range_c<int,0,10>
, plus<_1,int_<7> >
, back_inserter< vector0<> >
>::type r1;
typedef transform< r1, minus<_1,int_<2> > >::type r2;
typedef reverse_transform<
r2
, minus<_1,5>
, front_inserter< vector0<> >
>::type r3;
BOOST_MPL_ASSERT(( equal<r1, range_c<int,7,17> > ));
Revision Date: 15th November 20043.2 Inserters Algorithms 84
BOOST_MPL_ASSERT(( equal<r2, range_c<int,5,15> > ));
BOOST_MPL_ASSERT(( equal<r3, range_c<int,0,10> > ));
Models
—transform
—remove
—replace
See also
Transformation Algorithms ,Inserter
3.2 Inserters
3.2.1 back_inserter
Synopsis
template<
typename Seq
>
struct back_inserter
{
//unspecified
//...
};
Description
Inserts elements at the endof the sequence.
Header
#include <boost/mpl/back_inserter.hpp>
Model of
Inserter
Parameters
Parameter Requirement Description
Seq Back Extensible Sequence A sequence to bind the inserter to.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Inserter.
For anyBack Extensible Sequence s:
Revision Date: 15th November 200485 Algorithms 3.2 Inserters
Expression Semantics
back_inserter
 AnInserter in, equivalent to
struct in : inserter<s,push_back<_1,_2> > {};
Complexity
Amortized constant time.
Example
typedef copy<
range_c<int,5,10>
, back_inserter< vector_c<int,0,1,2,3,4> >
>::type range;
BOOST_MPL_ASSERT(( equal< range, range_c<int,0,10> > ));
See also
Algorithms ,Inserter,Reversible Algorithm ,inserter ,front_inserter ,push_back
3.2.2 front_inserter
Synopsis
template<
typename Seq
>
struct front_inserter
{
//unspecified
//...
};
Description
Inserts elements at the beginning of the sequence.
Header
#include <boost/mpl/front_inserter.hpp>
Model of
Inserter
Parameters
Revision Date: 15th November 20043.2 Inserters Algorithms 86
Parameter Requirement Description
Seq Front Extensible Sequence A sequence to bind the inserter to.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Inserter.
For anyFront Extensible Sequence s:
Expression Semantics
front_inserter
 AnInserter in, equivalent to
struct in : inserter<s,push_front<_1,_2> > {};
Complexity
Amortized constant time.
Example
typedef reverse_copy<
range_c<int,0,5>
, front_inserter< vector_c<int,5,6,7,8,9> >
>::type range;
BOOST_MPL_ASSERT(( equal< range, range_c<int,0,10> > ));
See also
Algorithms ,Inserter,Reversible Algorithm ,inserter ,back_inserter ,push_front
3.2.3 inserter
Synopsis
template<
typename State
, typename Operation
>
struct inserter
{
typedef State state;
typedef Operation operation;
};
Description
A general-purpose model of the Inserterconcept.
Revision Date: 15th November 200487 Algorithms 3.3 Iteration Algorithms
Header
#include <boost/mpl/inserter.hpp>
Model of
Inserter
Parameters
Parameter Requirement Description
State Any type A initial state.
Operation BinaryLambda Expression An output operation.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Inserter.
For any binary Lambda Expression opand arbitrary type state:
Expression Semantics
inserter<op,state> AnInserter.
Complexity
Amortized constant time.
Example
template< typename N > struct is_odd : bool_< ( N::value % 2 ) > {};
typedef copy<
range_c<int,0,10>
, inserter< // a filtering ’push_back’ inserter
vector<>
, if_< is_odd<_2>, push_back<_1,_2>, _1 >
>
>::type odds;
BOOST_MPL_ASSERT(( equal< odds, vector_c<int,1,3,5,7,9>, equal_to<_,_> > ));
See also
Algorithms ,Inserter,Reversible Algorithm ,front_inserter ,back_inserter
3.3 Iteration Algorithms
Iteration algorithms are the basic building blocks behind many of the MPL’s algorithms, and are usually the ﬁrst place
to look at when starting to build a new one. Abstracting away the details of sequence iteration and employing various
optimizations such as recursion unrolling, they provide signiﬁcant advantages over a hand-coded approach.
Revision Date: 15th November 20043.3 Iteration Algorithms Algorithms 88
3.3.1 fold
Synopsis
template<
typename Sequence
, typename State
, typename ForwardOp
>
struct fold
{
typedef unspecified type;
};
Description
Returns the result of the successive application of binary ForwardOp to the result of the previous ForwardOp in-
vocation ( Stateif it’s the ﬁrst call) and every element of the sequence in the range [ begin<Sequence>::type ,
end<Sequence>::type ) in order.
Header
#include <boost/mpl/fold.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to iterate.
State Any type The initial state for the ﬁrst ForwardOp application.
ForwardOp BinaryLambda Expression The operation to be executed onforward traversal.
Expression semantics
For anyForward Sequence s, binaryLambda Expression op, and arbitrary type state:
typedef fold<s,state,op>::type t;
Return type: A type.
Semantics: Equivalent to
typedef iter_fold< s,state,apply<op,_1,deref<_2> > >::type t;
Complexity
Linear. Exactly size
::value applications of op.
Example
typedef vector<long,float,short,double,float,long,long double> types;
typedef fold<
types
Revision Date: 15th November 200489 Algorithms 3.3 Iteration Algorithms
, int_<0>
, if_< is_float<_2>,next<_1>,_1 >
>::type number_of_floats;
BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 );
See also
Algorithms ,accumulate ,reverse_fold ,iter_fold ,reverse_iter_fold ,copy,copy_if
3.3.2 iter_fold
Synopsis
template<
typename Sequence
, typename State
, typename ForwardOp
>
struct iter_fold
{
typedef unspecified type;
};
Description
Returnstheresultofthesuccessiveapplicationofbinary ForwardOp totheresultoftheprevious ForwardOp invocation
(Stateifit’stheﬁrstcall)andeachiteratorintherange[ begin<Sequence>::type ,end<Sequence>::type )inorder.
Header
#include <boost/mpl/iter_fold.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to iterate.
State Any type The initial state for the ﬁrst ForwardOp application.
ForwardOp BinaryLambda Expression The operation to be executed onforward traversal.
Expression semantics
For anyForward Sequence s, binaryLambda Expression op, and an arbitrary type state:
typedef iter_fold<s,state,op>::type t;
Return type: A type.
Semantics: Equivalent to
typedef begin<Sequence>::type i 1;
typedef apply<op,state,i 1>::type state 1;
Revision Date: 15th November 20043.3 Iteration Algorithms Algorithms 90
typedef next<i 1>::type i 2;
typedef apply<op,state 1,i2>::type state 2;
...
typedef apply<op,state n−1,in>::type state n;
typedef next<i n>::type last;
typedef state nt;
where n == size
::value andlastis identical to end
::type ; equivalent to typedef
state t; ifempty
::value == true .
Complexity
Linear. Exactly size
::value applications of op.
Example
typedef vector_c<int,5,-1,0,7,2,0,-5,4> numbers;
typedef iter_fold<
numbers
, begin<numbers>::type
, if_< less< deref<_1>, deref<_2> >,_2,_1 >
>::type max_element_iter;
BOOST_MPL_ASSERT_RELATION( deref<max_element_iter>::type::value, ==, 7 );
See also
Algorithms ,reverse_iter_fold ,fold,reverse_fold ,copy
3.3.3 reverse_fold
Synopsis
template<
typename Sequence
, typename State
, typename BackwardOp
, typename ForwardOp = _1
>
struct reverse_fold
{
typedef unspecified type;
};
Description
Returnstheresultofthesuccessiveapplicationofbinary BackwardOp totheresultoftheprevious BackwardOp invoca-
tion ( Stateif it’s the ﬁrst call) and every element in the range [ begin<Sequence>::type ,end<Sequence>::type )
inreverseorder. If ForwardOp isprovided,thenitisappliedonforwardtraversaltoformtheresultthatispassedtothe
ﬁrstBackwardOp call.
Revision Date: 15th November 200491 Algorithms 3.3 Iteration Algorithms
Header
#include <boost/mpl/reverse_fold.hpp>
Parameters
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to iterate.
State Any type The initial state for the ﬁrst BackwardOp /ForwardOp
application.
BackwardOp BinaryLambda Expression The operation to be executed on backward traversal.
ForwardOp BinaryLambda Expression The operation to be executed on forward traversal.
Expression semantics
For anyForward Sequence s, binaryLambda Expression backward_op andforward_op , and arbitrary type state:
typedef reverse_fold< s,state,backward_op >::type t;
Return type: A type
Semantics: Equivalent to
typedef reverse_iter_fold<
s
, state
, apply<backward_op,_1,deref<_2> >
>::type t;
typedef reverse_fold< s,state,backward_op,forward_op >::type t;
Return type: A type.
Semantics: Equivalent to
typedef reverse_fold<
Sequence
, fold<s,state,forward_op>::type
, backward_op
>::type t;
Complexity
Linear. Exactly size
::value applications of backward_op andforward_op .
Example
Remove negative elements froma sequence2).
typedef list_c<int,5,-1,0,-7,-2,0,-5,4> numbers;
typedef list_c<int,-1,-7,-2,-5> negatives;
typedef reverse_fold<
numbers
Revision Date: 15th November 20043.3 Iteration Algorithms Algorithms 92
, list_c<int>
, if_< less< _2,int_<0> >, push_front<_1,_2,>, _1 >
>::type result;
BOOST_MPL_ASSERT(( equal< negatives,result > ));
See also
Algorithms ,fold,reverse_iter_fold ,iter_fold
3.3.4 reverse_iter_fold
Synopsis
template<
typename Sequence
, typename State
, typename BackwardOp
, typename ForwardOp = _1
>
struct reverse_iter_fold
{
typedef unspecified type;
};
Description
Returns the result of the successive application of binary BackwardOp to the result of the previous BackwardOp invo-
cation ( Stateif it’s the ﬁrst call) and each iterator in the range [ begin<Sequence>::type ,end<Sequence>::type )
in reverse order. If ForwardOp is provided, then it’s applied on forward traversal to form the result which is passed to
the ﬁrst BackwardOp call.
Header
#include <boost/mpl/reverse_iter_fold.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to iterate.
State Any type The initial state for the ﬁrst BackwardOp /ForwardOp
application.
BackwardOp BinaryLambda Expression The operation to be executed on backward traversal.
ForwardOp BinaryLambda Expression The operation to be executed on forward traversal.
Expression semantics
For anyForward Sequence s, binaryLambda Expression backward_op andforward_op , and arbitrary type state:
2)Seeremove_if for a more compact way to do this.
Revision Date: 15th November 200493 Algorithms 3.3 Iteration Algorithms
typedef reverse_iter_fold< s,state,backward_op >::type t;
Return type: A type.
Semantics: Equivalent to
typedef begin
::type i 1;
typedef next<i 1>::type i 2;
...
typedef next<i n>::type last;
typedef apply<backward_op,state,i n>::type state n;
typedef apply<backward_op,state n,in−1>::type state n−1;
...
typedef apply<backward_op,state 2,i1>::type state 1;
typedef state 1t;
where n == size
::value andlastis identical to end
::type ; equivalent to typedef
state t; ifempty
::value == true .
typedef reverse_iter_fold< s,state,backward_op,forward_op >::type t;
Return type: A type.
Semantics: Equivalent to
typedef reverse_iter_fold<
Sequence
, iter_fold<s,state,forward_op>::type
, backward_op
>::type t;
Complexity
Linear. Exactly size
::value applications of backward_op andforward_op .
Example
Build a list of iterators to the negative elements in a sequence.
typedef vector_c<int,5,-1,0,-7,-2,0,-5,4> numbers;
typedef list_c<int,-1,-7,-2,-5> negatives;
typedef reverse_iter_fold<
numbers
, list<>
, if_< less< deref<_2>,int_<0> >, push_front<_1,_2>, _1 >
>::type iters;
BOOST_MPL_ASSERT(( equal<
negatives
, transform_view< iters,deref<_1> >
> ));
See also
Algorithms ,iter_fold ,reverse_fold ,fold
Revision Date: 15th November 20043.3 Iteration Algorithms Algorithms 94
3.3.5 accumulate
Synopsis
template<
typename Sequence
, typename State
, typename ForwardOp
>
struct accumulate
{
typedef unspecified type;
};
Description
Returns the result of the successive application of binary ForwardOp to the result of the previous ForwardOp in-
vocation ( Stateif it’s the ﬁrst call) and every element of the sequence in the range [ begin<Sequence>::type ,
end<Sequence>::type ) in order. [ Note: accumulate is a synonym for fold—end note]
Header
#include <boost/mpl/accumulate.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to iterate.
State Any type The initial state for the ﬁrst ForwardOp application.
ForwardOp BinaryLambda Expression The operation to be executed onforward traversal.
Expression semantics
For anyForward Sequence s, binaryLambda Expression op, and arbitrary type state:
typedef accumulate<s,state,op>::type t;
Return type: A type.
Semantics: Equivalent to
typedef fold<s,state,op>::type t;
Complexity
Linear. Exactly size
::value applications of op.
Example
typedef vector<long,float,short,double,float,long,long double> types;
typedef accumulate<
types
Revision Date: 15th November 200495 Algorithms 3.4 Querying Algorithms
, int_<0>
, if_< is_float<_2>,next<_1>,_1 >
>::type number_of_floats;
BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 );
See also
Algorithms ,fold,reverse_fold ,iter_fold ,reverse_iter_fold ,copy,copy_if
3.4 Querying Algorithms
3.4.1 ﬁnd
Synopsis
template<
typename Sequence
, typename T
>
struct find
{
typedef unspecified type;
};
Description
Returns an iterator to the ﬁrst occurrence of type Tin aSequence .
Header
#include <boost/mpl/find.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to search in.
T Any type A type to search for.
Expression semantics
For anyForward Sequence sand arbitrary type t:
typedef find<s,t>::type i;
Return type: Forward Iterator .
Semantics: Equivalent to
typedef find_if<s, is_same<_,t> >::type i;
Revision Date: 15th November 20043.4 Querying Algorithms Algorithms 96
Complexity
Linear. At most size
::value comparisons for identity.
Example
typedef vector<char,int,unsigned,long,unsigned long> types;
typedef find<types,unsigned>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned > ));
BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
See also
Querying Algorithms ,contains ,find_if,count,lower_bound
3.4.2 ﬁnd_if
Synopsis
template<
typename Sequence
, typename Pred
>
struct find_if
{
typedef unspecified type;
};
Description
Returns an iterator to the ﬁrst element in Sequence that satisﬁes the predicate Pred.
Header
#include <boost/mpl/find_if.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to search in.
Pred UnaryLambda Expression A search condition.
Expression semantics
For anyForward Sequence sand unary Lambda Expression pred:
typedef find_if<s,pred>::type i;
Return type: Forward Iterator .
Semantics: iis the ﬁrst iterator in the range [ begin
::type ,end
::type ) such that
Revision Date: 15th November 200497 Algorithms 3.4 Querying Algorithms
apply< pred,deref<i>::type >::type::value == true
If no such iterator exists, iis identical to end
::type .
Complexity
Linear. At most size
::value applications of pred.
Example
typedef vector<char,int,unsigned,long,unsigned long> types;
typedef find_if<types, is_same<_1,unsigned> >::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned > ));
BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
See also
Querying Algorithms ,find,count_if ,lower_bound
3.4.3 contains
Synopsis
template<
typename Sequence
, typename T
>
struct contains
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant if one or more elements in Sequence are identical to T.
Header
#include <boost/mpl/contains.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
T Any type A type to search for.
Expression semantics
For anyForward Sequence sand arbitrary type t:
Revision Date: 15th November 20043.4 Querying Algorithms Algorithms 98
typedef contains<s,t>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef not_< is_same<
find<s,t>::type
, end
::type
> >::type r;
Complexity
Linear. At most size
::value comparisons for identity.
Example
typedef vector<char,int,unsigned,long,unsigned long> types;
BOOST_MPL_ASSERT_NOT(( contains<types,bool> ));
See also
Querying Algorithms ,find,find_if,count,lower_bound
3.4.4 count
Synopsis
template<
typename Sequence
, typename T
>
struct count
{
typedef unspecified type;
};
Description
Returns the number of elements in a Sequence that are identical to T.
Header
#include <boost/mpl/count.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
T Any type A type to search for.
Revision Date: 15th November 200499 Algorithms 3.4 Querying Algorithms
Expression semantics
For anyForward Sequence sand arbitrary type t:
typedef count<s,t>::type n;
Return type: Integral Constant .
Semantics: Equivalent to
typedef count_if< s,is_same<_,T> >::type n;
Complexity
Linear. Exactly size
::value comparisons for identity.
Example
typedef vector<int,char,long,short,char,short,double,long> types;
typedef count<types, short>::type n;
BOOST_MPL_ASSERT_RELATION( n::value, ==, 2 );
See also
Querying Algorithms ,count_if ,find,find_if,contains ,lower_bound
3.4.5 count_if
Synopsis
template<
typename Sequence
, typename Pred
>
struct count_if
{
typedef unspecified type;
};
Description
Returns the number of elements in Sequence that satisfy the predicate Pred.
Header
#include <boost/mpl/count_if.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
Pred UnaryLambda Expression A count condition.
Revision Date: 15th November 20043.4 Querying Algorithms Algorithms 100
Expression semantics
For anyForward Sequence sand unary Lambda Expression pred:
typedef count_if<s,pred>::type n;
Return type: Integral Constant .
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef fold<
s
, long_<0>
, if_< apply_wrap1<p,_2>, next<_1>, _1 >
>::type n;
Complexity
Linear. Exactly size
::value applications of pred.
Example
typedef vector<int,char,long,short,char,long,double,long> types;
BOOST_MPL_ASSERT_RELATION( (count_if< types, is_float<_> >::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (count_if< types, is_same<_,char> >::value), ==, 2 );
BOOST_MPL_ASSERT_RELATION( (count_if< types, is_same<_,void> >::value), ==, 0 );
See also
Querying Algorithms ,count,find,find_if,contains
3.4.6 lower_bound
Synopsis
template<
typename Sequence
, typename T
, typename Pred = less<_1,_2>
>
struct lower_bound
{
typedef unspecified type;
};
Description
Returns the ﬁrst position inthe sorted Sequence where Tcould be inserted without violating the ordering.
Revision Date: 15th November 2004101 Algorithms 3.4 Querying Algorithms
Header
#include <boost/mpl/lower_bound.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sorted sequence to search in.
T Any type A type to search a position for.
Pred BinaryLambda Expression A search criteria.
Expression semantics
For any sorted Forward Sequence s, binaryLambda Expression pred, and arbitrary type x:
typedef lower_bound< s,x,pred >::type i;
Return type: Forward Iterator .
Semantics: iisthefurthermostiteratorin[ begin
::type ,end
::type )suchthat,foreveryiterator
jin [begin
::type ,i),
apply< pred, deref<j>::type, x >::type::value == true
Complexity
The number of comparisons is logarithmic: at most log 2(size
::value ) + 1. If sis aRandom Access Se-
quencethenthenumberofstepsthroughtherangeisalsologarithmic;otherwise,thenumberofstepsisproportionalto
size
::value .
Example
typedef vector_c<int,1,2,3,3,3,5,8> numbers;
typedef lower_bound< numbers, int_<3> >::type iter;
BOOST_MPL_ASSERT_RELATION(
(distance< begin<numbers>::type,iter >::value), ==, 2
);
BOOST_MPL_ASSERT_RELATION( deref<iter>::type::value, ==, 3 );
See also
Querying Algorithms ,upper_bound ,find,find_if,min_element
3.4.7 upper_bound
Synopsis
template<
typename Sequence
, typename T
Revision Date: 15th November 20043.4 Querying Algorithms Algorithms 102
, typename Pred = less<_1,_2>
>
struct upper_bound
{
typedef unspecified type;
};
Description
Returns the last position inthe sorted Sequence where Tcould be inserted without violating the ordering.
Header
#include <boost/mpl/upper_bound.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sorted sequence to search in.
T Any type A type to search a position for.
Pred BinaryLambda Expression A search criteria.
Expression semantics
For any sorted Forward Sequence s, binaryLambda Expression pred, and arbitrary type x:
typedef upper_bound< s,x,pred >::type i;
Return type: Forward Iterator
Semantics: iisthefurthermostiteratorin[ begin
::type ,end
::type )suchthat,foreveryiterator
jin[begin
::type, i) ,
apply< pred, x, deref<j>::type >::type::value == false
Complexity
The number of comparisons is logarithmic: at most log 2(size
::value ) + 1. If sis aRandom Access Se-
quencethenthenumberofstepsthroughtherangeisalsologarithmic;otherwise,thenumberofstepsisproportionalto
size
::value .
Example
typedef vector_c<int,1,2,3,3,3,5,8> numbers;
typedef upper_bound< numbers, int_<3> >::type iter;
BOOST_MPL_ASSERT_RELATION(
(distance< begin<numbers>::type,iter >::value), ==, 5
);
BOOST_MPL_ASSERT_RELATION( deref<iter>::type::value, ==, 5 );
Revision Date: 15th November 2004103 Algorithms 3.4 Querying Algorithms
See also
Querying Algorithms ,lower_bound ,find,find_if,min_element
3.4.8 min_element
Synopsis
template<
typename Sequence
, typename Pred = less<_1,_2>
>
struct min_element
{
typedef unspecified type;
};
Description
Returns an iterator to the smallest element in Sequence .
Header
#include <boost/mpl/min_element.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be searched.
Pred BinaryLambda Expression A comparison criteria.
Expression semantics
For anyForward Sequence sand binary Lambda Expression pred:
typedef min_element<s,pred>::type i;
Return type: Forward Iterator .
Semantics: iis the ﬁrst iterator in [ begin
::type ,end
::type ) such that for every iterator jin
[begin
::type ,end
::type ),
apply< pred, deref<j>::type, deref<i>::type >::type::value == false
Complexity
Linear. Zero comparisons if sis empty, otherwise exactly size
::value - 1 comparisons.
Example
typedef vector<bool,char[50],long,double> types;
typedef min_element<
Revision Date: 15th November 20043.4 Querying Algorithms Algorithms 104
transform_view< types,sizeof_<_1> >
>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter::base>::type, bool> ));
See also
Querying Algorithms ,max_element ,find_if,upper_bound ,find
3.4.9 max_element
Synopsis
template<
typename Sequence
, typename Pred = less<_1,_2>
>
struct max_element
{
typedef unspecified type;
};
Description
Returns an iterator to the largest element in Sequence .
Header
#include <boost/mpl/max_element.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to be searched.
Pred BinaryLambda Expression A comparison criteria.
Expression semantics
For anyForward Sequence sand binary Lambda Expression pred:
typedef max_element<s,pred>::type i;
Return type: Forward Iterator .
Semantics: iis the ﬁrst iterator in [ begin
::type ,end
::type ) such that for every iterator jin
[begin
::type ,end
::type ),
apply< pred, deref<i>::type, deref<j>::type >::type::value == false
Complexity
Linear. Zero comparisons if sis empty, otherwise exactly size
::value - 1 comparisons.
Revision Date: 15th November 2004105 Algorithms 3.4 Querying Algorithms
Example
typedef vector<bool,char[50],long,double> types;
typedef max_element<
transform_view< types,sizeof_<_1> >
>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter::base>::type, char[50]> ));
See also
Querying Algorithms ,min_element ,find_if,upper_bound ,find
3.4.10 equal
Synopsis
template<
typename Seq1
, typename Seq2
, typename Pred = is_same<_1,_2>
>
struct equal
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant if the two sequences Seq1andSeq2are identical when compared element-by-
element.
Header
#include <boost/mpl/equal.hpp>
Parameters
Parameter Requirement Description
Seq1,Seq2 Forward Sequence Sequences to compare.
Pred BinaryLambda Expression A comparison criterion.
Expression semantics
For anyForward Sequence ss1ands2and a binary Lambda Expression pred:
typedef equal<s1,s2,pred>::type c;
Return type: Integral Constant
Semantics: c::value == true is and only if size<s1>::value == size<s2>::value and for every
iterator iin [begin<s1>::type ,end<s1>::type )deref<i>::type is identical to
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 106
advance< begin<s2>::type, distance< begin<s1>::type,i >::type >::type
Complexity
Linear. At most size<s1>::value comparisons.
Example
typedef vector<char,int,unsigned,long,unsigned long> s1;
typedef list<char,int,unsigned,long,unsigned long> s2;
BOOST_MPL_ASSERT(( equal<s1,s2> ));
See also
Querying Algorithms ,find,find_if
3.5 Transformation Algorithms
According to their name, MPL’s transformation , orsequence-building algorithms provide the tools for building new
sequences from the existing ones by performing some kind of transformation. A typical transformation alogrithm takes
oneormoreinputsequencesandatransformationmetafunction/predicate,andreturnsanewsequencebuiltaccordingto
the algorithm’s semantics through the means of its Inserterargument, which plays a role similar to the role of run-time
Output Iterator .
Every transformation algorithm is a Reversible Algorithm , providing an accordingly named reverse_ counterpart
carrying the transformation in the reverse order. Thus, all sequence-building algorithms come in pairs, for instance
replace /reverse_replace . In presence of variability of the output sequence’s properties such as front or backward
extensibility, the existence of the bidirectional algorithms allows for the most efﬁcient way to perform the required
transformation.
3.5.1 copy
Synopsis
template<
typename Sequence
, typename In = unspecified
>
struct copy
{
typedef unspecified type;
};
Description
Returns a copy of the originalsequence.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Revision Date: 15th November 2004107 Algorithms 3.5 Transformation Algorithms
Header
#include <boost/mpl/copy.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to copy.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, and anInserter in:
typedef copy<s,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef fold< s,in::state,in::operation >::type r;
Complexity
Linear. Exactly size
::value applications of in::operation .
Example
typedef vector_c<int,0,1,2,3,4,5,6,7,8,9> numbers;
typedef copy<
range_c<int,10,20>
, back_inserter< numbers >
>::type result;
BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 20 );
BOOST_MPL_ASSERT(( equal< result,range_c<int,0,20> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_copy ,copy_if,transform
3.5.2 copy_if
Synopsis
template<
typename Sequence
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 108
, typename Pred
, typename In = unspecified
>
struct copy_if
{
typedef unspecified type;
};
Description
Returns a ﬁltered copy of theoriginal sequence containing the elements that satisfythe predicate Pred.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/copy_if.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to copy.
Pred UnaryLambda Expression A copying condition.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, and anInserter in:
typedef copy_if<s,pred,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef lambda<in::operation>::type op;
typedef fold<
s
, in::state
, eval_if<
apply_wrap1<p,_2>
, apply_wrap2<op,_1,_2>
, identity<_1>
>
Revision Date: 15th November 2004109 Algorithms 3.5 Transformation Algorithms
>::type r;
Complexity
Linear. Exactly size
::value applications of pred, and at most size
::value applications of
in::operation .
Example
typedef copy_if<
range_c<int,0,10>
, less< _1, int_<5> >
, back_inserter< vector<> >
>::type result;
BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 5 );
BOOST_MPL_ASSERT(( equal<result,range_c<int,0,5> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_copy_if ,copy,remove_if ,replace_if
3.5.3 transform
Synopsis
template<
typename Seq
, typename Op
, typename In = unspecified
>
struct transform
{
typedef unspecified type;
};
template<
typename Seq1
, typename Seq2
, typename BinaryOp
, typename In = unspecified
>
struct transform
{
typedef unspecified type;
};
Description
transform is anoverloaded name :
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 110
—transform<Seq,Op> returns a transformed copy of the original sequence produced by applying an unary trans-
formation Opto every element in the [ begin<Sequence>::type ,end<Sequence>::type ) range.
—transform<Seq1,Seq2,Op> returns a new sequence produced by applying a binary transformation Bina-
ryOpto a pair of elements (e 1, e21) from the corresponding [ begin<Seq1>::type ,end<Seq1>::type ) and
[begin<Seq2>::type ,end<Seq2>::type ) ranges.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/transform.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence ,Seq1,Seq2 Forward Sequence Sequences to transform.
Op,BinaryOp Lambda Expression A transformation.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence ss,s1ands2,Lambda Expression sopandop2, and anInserter in:
typedef transform<s,op,in>::type r;
Return type: A type.
Postcondition: Equivalent to
typedef lambda<op>::type f;
typedef lambda<in::operation>::type in_op;
typedef fold<
s
, in::state
, bind< in_op, _1, bind<f, _2> >
>::type r;
typedef transform<s1,s2,op,in>::type r;
Return type: A type.
Postcondition: Equivalent to
typedef lambda<op2>::type f;
typedef lambda<in::operation>::type in_op;
typedef fold<
Revision Date: 15th November 2004111 Algorithms 3.5 Transformation Algorithms
pair_view<s1,s2>
, in::state
, bind<
in_op
, _1
, bind<f, bind<first<>,_2>, bind<second<>,_2> >
>
>::type r;
Complexity
Linear. Exactly size
::value /size<s1>::value applications of op/op2andin::operation .
Example
typedef vector<char,short,int,long,float,double> types;
typedef vector<char*,short*,int*,long*,float*,double*> pointers;
typedef transform< types,boost::add_pointer<_1> >::type result;
BOOST_MPL_ASSERT(( equal<result,pointers> ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_transform ,copy,replace_if
3.5.4 replace
Synopsis
template<
typename Sequence
, typename OldType
, typename NewType
, typename In = unspecified
>
struct replace
{
typedef unspecified type;
};
Description
Returns a copy of the originalsequence where every type identical to OldType has been replaced with NewType.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/replace.hpp>
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 112
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence A original sequence.
OldType Any type A type to be replaced.
NewType Any type A type to replace with.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, anInserter in, and arbitrary types xandy:
typedef replace<s,x,y,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef replace_if< s,y,is_same<_,x>,in >::type r;
Complexity
Linear. Performs exactly size
::value comparisons for identity / insertions.
Example
typedef vector<int,float,char,float,float,double> types;
typedef vector<int,double,char,double,double,double> expected;
typedef replace< types,float,double >::type result;
BOOST_MPL_ASSERT(( equal< result,expected > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_replace ,replace_if ,remove,transform
3.5.5 replace_if
Synopsis
template<
typename Sequence
, typename Pred
, typename In = unspecified
>
struct replace_if
{
Revision Date: 15th November 2004113 Algorithms 3.5 Transformation Algorithms
typedef unspecified type;
};
Description
Returns a copy of the original sequence where every type that satisﬁes the predicate Predhas been replaced with
NewType.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/replace_if.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
Pred UnaryLambda Expression A replacement condition.
NewType Any type A type to replace with.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, anInserter in, and arbitrary type x:
typedef replace_if<s,pred,x,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef transform< s, if_< apply_wrap1<p,_1>,x,_1>, in >::type r;
Complexity
Linear. Performs exactly size
::value applications of pred, and at most size
::value insertions.
Example
typedef vector_c<int,1,4,5,2,7,5,3,5> numbers;
typedef vector_c<int,1,4,0,2,0,0,3,0> expected;
typedef replace_if< numbers, greater<_,int_<4> >, int_<0> >::type result;
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 114
BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_replace_if ,replace,remove_if ,transform
3.5.6 remove
Synopsis
template<
typename Sequence
, typename T
, typename In = unspecified
>
struct remove
{
typedef unspecified type;
};
Description
Returns a new sequence that contains all elements from [ begin<Sequence>::type ,end<Sequence>::type ) range
except those that are identical to T.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/remove.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
T Any type A type to be removed.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, anInserter in, and arbitrary type x:
typedef remove<s,x,in>::type r;
Return type: A type.
Revision Date: 15th November 2004115 Algorithms 3.5 Transformation Algorithms
Semantics: Equivalent to
typedef remove_if< s,is_same<_,x>,in >::type r;
Complexity
Linear. Performs exactly size
::value comparisons for equality, and at most size
::value insertions.
Example
typedef vector<int,float,char,float,float,double>::type types;
typedef remove< types,float >::type result;
BOOST_MPL_ASSERT(( equal< result, vector<int,char,double> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_remove ,remove_if ,copy,replace
3.5.7 remove_if
Synopsis
template<
typename Sequence
, typename Pred
, typename In = unspecified
>
struct remove_if
{
typedef unspecified type;
};
Description
Returns a new sequence that contains all the elements from [ begin<Sequence>::type ,end<Sequence>::type )
range except those that satisfy the predicate Pred.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/remove_if.hpp>
Model of
Reversible Algorithm
Parameters
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 116
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
Pred UnaryLambda Expression A removal condition.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, and anInserter in, and an unary Lambda Expression pred:
typedef remove_if<s,pred,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef lambda<in::operation>::type op;
typedef fold<
s
, in::state
, eval_if<
apply_wrap1<p,_2>
, identity<_1>
, apply_wrap2<op,_1,_2>
>
>::type r;
Complexity
Linear. Performs exactly size
::value applications of pred, and at most size
::value insertions.
Example
typedef vector_c<int,1,4,5,2,7,5,3,5>::type numbers;
typedef remove_if< numbers, greater<_,int_<4> > >::type result;
BOOST_MPL_ASSERT(( equal< result,vector_c<int,1,4,2,3>,equal_to<_,_> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_remove_if ,remove,copy_if,replace_if
3.5.8 unique
Synopsis
template<
typename Seq
, typename Pred
, typename In = unspecified
Revision Date: 15th November 2004117 Algorithms 3.5 Transformation Algorithms
>
struct unique
{
typedef unspecified type;
};
Description
Returns a sequence of the initial elements of every subrange of the original sequence Seqwhose elements are all the
same.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/unique.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
Pred BinaryLambda Expression An equivalence relation.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, a binary Lambda Expression pred, and anInserter in:
typedef unique<s,pred,in>::type r;
Return type: A type.
Semantics: Ifsize
::value <= 1 , then equivalent to
typedef copy<s,in>::type r;
otherwise equivalent to
typedef lambda<pred>::type p;
typedef lambda<in::operation>::type in_op;
typedef apply_wrap2<
in_op
, in::state
, front<types>::type
>::type in_state;
typedef fold<
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 118
s
, pair< in_state, front
::type >
, eval_if<
apply_wrap2<p, second<_1>, _2>
, identity< first<_1> >
, apply_wrap2<in_op, first<_1>, _2>
>
>::type::first r;
Complexity
Linear. Performs exactly size
::value - 1 applications of pred, and at most size
::value insertions.
Example
typedef vector<int,float,float,char,int,int,int,double> types;
typedef vector<int,float,char,int,double> expected;
typedef unique< types, is_same<_1,_2> >::type result;
BOOST_MPL_ASSERT(( equal< result,expected > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_unique ,remove,copy_if,replace_if
3.5.9 partition
Synopsis
template<
typename Seq
, typename Pred
, typename In1 = unspecified
, typename In2 = unspecified
>
struct partition
{
typedef unspecified type;
};
Description
Returnsapairofsequencestogethercontainingallelementsintherange[ begin<Seq>::type ,end<Seq>::type )split
into two groups based on the predicate Pred.partition is a synonym for stable_partition .
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/partition.hpp>
Revision Date: 15th November 2004119 Algorithms 3.5 Transformation Algorithms
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Seq Forward Sequence An original sequence.
Pred UnaryLambda Expression A partitioning predicate.
In1,In2 Inserter Output inserters.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, andInsertersin1andin2:
typedef partition<s,pred,in1,in2>::type r;
Return type: Apair.
Semantics: Equivalent to
typedef stable_partition<s,pred,in1,in2>::type r;
Complexity
Linear. Exactly size
::value applications of pred, and size
::value of summarized in1::operation /
in2::operation applications.
Example
template< typename N > struct is_odd : bool_<(N::value % 2)> {};
typedef partition<
range_c<int,0,10>
, is_odd<_1>
, back_inserter< vector<> >
, back_inserter< vector<> >
>::type r;
BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,1,3,5,7,9> > ));
BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,0,2,4,6,8> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_partition ,stable_partition ,sort
3.5.10 stable_partition
Synopsis
template<
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 120
typename Seq
, typename Pred
, typename In1 = unspecified
, typename In2 = unspecified
>
struct stable_partition
{
typedef unspecified type;
};
Description
Returnsapairofsequencestogethercontainingallelementsintherange[ begin<Seq>::type ,end<Seq>::type )split
into two groups based on the predicate Pred.stable_partition is guaranteed to preserve the relative order of the
elements in the resulting sequences.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/stable_partition.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Seq Forward Sequence An original sequence.
Pred UnaryLambda Expression A partitioning predicate.
In1,In2 Inserter Output inserters.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, andInsertersin1andin2:
typedef stable_partition<s,pred,in1,in2>::type r;
Return type: Apair.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef lambda<in1::operation>::type in1_op;
typedef lambda<in2::operation>::type in2_op;
typedef fold<
s
, pair< in1::state, in2::state >
Revision Date: 15th November 2004121 Algorithms 3.5 Transformation Algorithms
, if_<
apply_wrap1<p,_2>
, pair< apply_wrap2<in1_op,first<_1>,_2>, second<_1> >
, pair< first<_1>, apply_wrap2<in2_op,second<_1>,_2> >
>
>::type r;
Complexity
Linear. Exactly size
::value applications of pred, and size
::value of summarized in1::operation /
in2::operation applications.
Example
template< typename N > struct is_odd : bool_<(N::value % 2)> {};
typedef stable_partition<
range_c<int,0,10>
, is_odd<_1>
, back_inserter< vector<> >
, back_inserter< vector<> >
>::type r;
BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,1,3,5,7,9> > ));
BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,0,2,4,6,8> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_stable_partition ,partition ,sort,transform
3.5.11 sort
Synopsis
template<
typename Seq
, typename Pred = less<_1,_2>
, typename In = unspecified
>
struct sort
{
typedef unspecified type;
};
Description
Returns a new sequence of all elements in the range [ begin<Seq>::type ,end<Seq>::type ) sorted according to the
ordering relation Pred.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 122
Header
#include <boost/mpl/sort.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Seq Forward Sequence An original sequence.
Pred BinaryLambda Expression An ordering relation.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, a binary Lambda Expression pred, and anInserter in:
typedef sort<s,pred,in>::type r;
Return type: A type.
Semantics: Ifsize
::value <= 1 , equivalent to
typedef copy<s,in>::type r;
otherwise equivalent to
typedef back_inserter< vector<> > aux_in;
typedef lambda<pred>::type p;
typedef begin
::type pivot;
typedef partition<
iterator_range< next<pivot>::type, end
::type >
, apply_wrap2<p,_1,deref<pivot>::type>
, aux_in
, aux_in
>::type partitioned;
typedef sort<partitioned::first,p,aux_in >::type part1;
typedef sort<partitioned::second,p,aux_in >::type part2;
typedef copy<
joint_view<
joint_view<part1,single_view< deref<pivot>::type > >
, part2
>
, in
>::type r;
Revision Date: 15th November 2004123 Algorithms 3.5 Transformation Algorithms
Complexity
AverageO(n log(n)) wheren==size
::value , quadratic at worst.
Example
typedef vector_c<int,3,4,0,-5,8,-1,7> numbers;
typedef vector_c<int,-5,-1,0,3,4,7,8> expected;
typedef sort<numbers>::type result;
BOOST_MPL_ASSERT(( equal< result, expected, equal_to<_,_> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,partition
3.5.12 reverse
Synopsis
template<
typename Sequence
, typename In = unspecified
>
struct reverse
{
typedef unspecified type;
};
Description
Returns a reversed copy of theoriginal sequence. reverse is a synonym for reverse_copy .
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/reverse.hpp>
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to reverse.
In Inserter An inserter.
Expression semantics
For anyForward Sequence s, and anInserter in:
typedef reverse<s,in>::type r;
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 124
Return type: A type.
Semantics: Equivalent to
typedef reverse_copy<s,in>::type r;
Complexity
Linear.
Example
typedef vector_c<int,9,8,7,6,5,4,3,2,1,0> numbers;
typedef reverse< numbers >::type result;
BOOST_MPL_ASSERT(( equal< result, range_c<int,0,10> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,reverse_copy ,copy,copy_if
3.5.13 reverse_copy
Synopsis
template<
typename Sequence
, typename In = unspecified
>
struct reverse_copy
{
typedef unspecified type;
};
Description
Returns a reversed copy of theoriginal sequence.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/copy.hpp>
Model of
Reversible Algorithm
Parameters
Revision Date: 15th November 2004125 Algorithms 3.5 Transformation Algorithms
Parameter Requirement Description
Sequence Forward Sequence A sequence to copy.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, and anInserter in:
typedef reverse_copy<s,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef reverse_fold< s,in::state,in::operation >::type r;
Complexity
Linear. Exactly size
::value applications of in::operation .
Example
typedef list_c<int,10,11,12,13,14,15,16,17,18,19>::type numbers;
typedef reverse_copy<
range_c<int,0,10>
, front_inserter< numbers >
>::type result;
BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 20 );
BOOST_MPL_ASSERT(( equal< result,range_c<int,0,20> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,copy,reverse_copy_if ,reverse_transform
3.5.14 reverse_copy_if
Synopsis
template<
typename Sequence
, typename Pred
, typename In = unspecified
>
struct reverse_copy_if
{
typedef unspecified type;
};
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 126
Description
Returns a reversed, ﬁltered copy of the original sequence containing the elements thatsatisfy the predicate Pred.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/copy_if.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence A sequence to copy.
Pred UnaryLambda Expression A copying condition.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, and anInserter in:
typedef reverse_copy_if<s,pred,in>::type r;
Return type: A type
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef lambda<in::operation>::type op;
typedef reverse_fold<
s
, in::state
, eval_if<
apply_wrap1<p,_2>
, apply_wrap2<op,_1,_2>
, identity<_1>
>
>::type r;
Complexity
Linear. Exactly size
::value applications of pred, and at most size
::value applications of
in::operation .
Revision Date: 15th November 2004127 Algorithms 3.5 Transformation Algorithms
Example
typedef reverse_copy_if<
range_c<int,0,10>
, less< _1, int_<5> >
, front_inserter< vector<> >
>::type result;
BOOST_MPL_ASSERT_RELATION( size<result>::value, ==, 5 );
BOOST_MPL_ASSERT(( equal<result,range_c<int,0,5> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,copy_if,reverse_copy ,remove_if ,replace_if
3.5.15 reverse_transform
Synopsis
template<
typename Seq
, typename Op
, typename In = unspecified
>
struct reverse_transform
{
typedef unspecified type;
};
template<
typename Seq1
, typename Seq2
, typename BinaryOp
, typename In = unspecified
>
struct reverse_transform
{
typedef unspecified type;
};
Description
reverse_transform is anoverloaded name :
—reverse_transform<Seq,Op> returns a reversed, transformed copy of the original sequence produced by ap-
plyinganunarytransformation Optoeveryelementinthe[ begin<Sequence>::type ,end<Sequence>::type )
range.
—reverse_transform<Seq1,Seq2,Op> returns a new sequence produced by applying a binary transformation
BinaryOp to a pair of elements (e 1, e21) from the corresponding [ begin<Seq1>::type ,end<Seq1>::type )
and [ begin<Seq2>::type ,end<Seq2>::type ) ranges in reverse order.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 128
Header
#include <boost/mpl/transform.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence ,Seq1,Seq2 Forward Sequence Sequences to transform.
Op,BinaryOp Lambda Expression A transformation.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence ss,s1ands2,Lambda Expression sopandop2, and anInserter in:
typedef reverse_transform<s,op,in>::type r;
Return type: A type.
Postcondition: Equivalent to
typedef lambda<op>::type f;
typedef lambda<in::operation>::type in_op;
typedef reverse_fold<
s
, in::state
, bind< in_op, _1, bind<f, _2> >
>::type r;
typedef transform<s1,s2,op,in>::type r;
Return type: A type.
Postcondition: Equivalent to
typedef lambda<op2>::type f;
typedef lambda<in::operation>::type in_op;
typedef reverse_fold<
pair_view<s1,s2>
, in::state
, bind<
in_op
, _1
, bind<f, bind<first<>,_2>, bind<second<>,_2> >
>
>::type r;
Revision Date: 15th November 2004129 Algorithms 3.5 Transformation Algorithms
Complexity
Linear. Exactly size
::value /size<s1>::value applications of op/op2andin::operation .
Example
typedef vector<char,short,int,long,float,double> types;
typedef vector<double*,float*,long*,int*,short*,char*> pointers;
typedef reverse_transform< types,boost::add_pointer<_1> >::type result;
BOOST_MPL_ASSERT(( equal<result,pointers> ));
See also
Transformation Algorithms ,Reversible Algorithm ,transform ,reverse_copy ,replace_if
3.5.16 reverse_replace
Synopsis
template<
typename Sequence
, typename OldType
, typename NewType
, typename In = unspecified
>
struct reverse_replace
{
typedef unspecified type;
};
Description
Returnsareversedcopyoftheoriginalsequencewhereeverytypeidenticalto OldType hasbeenreplacedwith NewType.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/replace.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence A original sequence.
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 130
Parameter Requirement Description
OldType Any type A type to be replaced.
NewType Any type A type to replace with.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, anInserter in, and arbitrary types xandy:
typedef reverse_replace<s,x,y,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef reverse_replace_if< s,y,is_same<_,x>,in >::type r;
Complexity
Linear. Performs exactly size
::value comparisons for identity / insertions.
Example
typedef vector<int,float,char,float,float,double> types;
typedef vector<double,double,double,char,double,int> expected;
typedef reverse_replace< types,float,double >::type result;
BOOST_MPL_ASSERT(( equal< result,expected > ));
See also
Transformation Algorithms ,Reversible Algorithm ,replace,reverse_replace_if ,remove,reverse_transform
3.5.17 reverse_replace_if
Synopsis
template<
typename Sequence
, typename Pred
, typename In = unspecified
>
struct reverse_replace_if
{
typedef unspecified type;
};
Revision Date: 15th November 2004131 Algorithms 3.5 Transformation Algorithms
Description
Returns a reversed copy of the original sequence where every type that satisﬁes the predicate Predhas been replaced
with NewType.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/replace_if.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
Pred UnaryLambda Expression A replacement condition.
NewType Any type A type to replace with.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, anInserter in, and arbitrary type x:
typedef reverse_replace_if<s,pred,x,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef reverse_transform< s, if_< apply_wrap1<p,_1>,x,_-
1>, in >::type r;
Complexity
Linear. Performs exactly size
::value applications of pred, and at most size
::value insertions.
Example
typedef vector_c<int,1,4,5,2,7,5,3,5> numbers;
typedef vector_c<int,1,4,0,2,0,0,3,0> expected;
typedef reverse_replace_if<
numbers
, greater< _, int_<4> >
, int_<0>
, front_inserter< vector<> >
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 132
>::type result;
BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,replace_if ,reverse_replace ,remove_if ,transform
3.5.18 reverse_remove
Synopsis
template<
typename Sequence
, typename T
, typename In = unspecified
>
struct reverse_remove
{
typedef unspecified type;
};
Description
Returns a new sequence that contains all elements from [ begin<Sequence>::type ,end<Sequence>::type ) range
in reverse order except those that are identical to T.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/remove.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
T Any type A type to be removed.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, anInserter in, and arbitrary type x:
Revision Date: 15th November 2004133 Algorithms 3.5 Transformation Algorithms
typedef reverse_remove<s,x,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef reverse_remove_if< s,is_same<_,x>,in >::type r;
Complexity
Linear. Performs exactly size
::value comparisons for equality, and at most size
::value insertions.
Example
typedef vector<int,float,char,float,float,double>::type types;
typedef reverse_remove< types,float >::type result;
BOOST_MPL_ASSERT(( equal< result, vector<double,char,int> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,remove,reverse_remove_if ,reverse_copy ,transform ,re-
place
3.5.19 reverse_remove_if
Synopsis
template<
typename Sequence
, typename Pred
, typename In = unspecified
>
struct reverse_remove_if
{
typedef unspecified type;
};
Description
Returns a new sequence that contains all the elements from [ begin<Sequence>::type ,end<Sequence>::type )
range in reverse order except those that satisfy the predicate Pred.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/remove_if.hpp>
Model of
Reversible Algorithm
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 134
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
Pred UnaryLambda Expression A removal condition.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, and anInserter in, and an unary Lambda Expression pred:
typedef reverse_remove_if<s,pred,in>::type r;
Return type: A type.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef lambda<in::operation>::type op;
typedef reverse_fold<
s
, in::state
, eval_if<
apply_wrap1<p,_2>
, identity<_1>
, apply_wrap2<op,_1,_2>
>
>::type r;
Complexity
Linear. Performs exactly size
::value applications of pred, and at most size
::value insertions.
Example
typedef vector_c<int,1,4,5,2,7,5,3,5>::type numbers;
typedef reverse_remove_if< numbers, greater<_,int_<4> > >::type result;
BOOST_MPL_ASSERT(( equal< result,vector_c<int,3,2,4,1>,equal_to<_,_> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,remove_if ,reverse_remove ,reverse_copy_if ,replace_if
3.5.20 reverse_unique
Synopsis
template<
typename Seq
Revision Date: 15th November 2004135 Algorithms 3.5 Transformation Algorithms
, typename Pred
, typename In = unspecified
>
struct reverse_unique
{
typedef unspecified type;
};
Description
Returns a sequence of the initial elements of every subrange of the reversed original sequence Seqwhose elements are
all the same.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/unique.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Sequence Forward Sequence An original sequence.
Pred BinaryLambda Expression An equivalence relation.
In Inserter An inserter.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, a binary Lambda Expression pred, and anInserter in:
typedef reverse_unique<s,pred,in>::type r;
Return type: A type.
Semantics: Ifsize
::value <= 1 , then equivalent to
typedef reverse_copy<s,in>::type r;
otherwise equivalent to
typedef lambda<pred>::type p;
typedef lambda<in::operation>::type in_op;
typedef apply_wrap2<
in_op
, in::state
, front<types>::type
>::type in_state;
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 136
typedef reverse_fold<
s
, pair< in_state, front
::type >
, eval_if<
apply_wrap2<p, second<_1>, _2>
, identity< first<_1> >
, apply_wrap2<in_op, first<_1>, _2>
>
>::type::first r;
Complexity
Linear. Performs exactly size
::value - 1 applications of pred, and at most size
::value insertions.
Example
typedef vector<int,float,float,char,int,int,int,double> types;
typedef vector<double,int,char,float,int> expected;
typedef reverse_unique< types, is_same<_1,_2> >::type result;
BOOST_MPL_ASSERT(( equal< result,expected > ));
See also
Transformation Algorithms ,Reversible Algorithm ,unique,reverse_remove ,reverse_copy_if ,replace_if
3.5.21 reverse_partition
Synopsis
template<
typename Seq
, typename Pred
, typename In1 = unspecified
, typename In2 = unspecified
>
struct reverse_partition
{
typedef unspecified type;
};
Description
Returnsapairofsequencestogethercontainingallelementsintherange[ begin<Seq>::type ,end<Seq>::type )split
into two groups based on the predicate Pred.reverse_partition is a synonym for reverse_stable_partition .
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Revision Date: 15th November 2004137 Algorithms 3.5 Transformation Algorithms
Header
#include <boost/mpl/partition.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Seq Forward Sequence An original sequence.
Pred UnaryLambda Expression A partitioning predicate.
In1,In2 Inserter Output inserters.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, andInsertersin1andin2:
typedef reverse_partition<s,pred,in1,in2>::type r;
Return type: Apair.
Semantics: Equivalent to
typedef reverse_stable_partition<s,pred,in1,in2>::type r;
Complexity
Linear. Exactly size
::value applications of pred, and size
::value of summarized in1::operation /
in2::operation applications.
Example
template< typename N > struct is_odd : bool_<(N::value % 2)> {};
typedef partition<
range_c<int,0,10>
, is_odd<_1>
, back_inserter< vector<> >
, back_inserter< vector<> >
>::type r;
BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,9,7,5,3,1> > ));
BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,8,6,4,2,0> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,partition ,reverse_stable_partition ,sort
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 138
3.5.22 reverse_stable_partition
Synopsis
template<
typename Seq
, typename Pred
, typename In1 = unspecified
, typename In2 = unspecified
>
struct reverse_stable_partition
{
typedef unspecified type;
};
Description
Returnsapairofsequencestogethercontainingallelementsintherange[ begin<Seq>::type ,end<Seq>::type )split
into two groups based on the predicate Pred.reverse_stable_partition is guaranteed to preserve the reversed
relative order of the elements in the resulting sequences.
[Note:This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a
precise speciﬁcation of thealgorithm’s details in all cases — end note]
Header
#include <boost/mpl/stable_partition.hpp>
Model of
Reversible Algorithm
Parameters
Parameter Requirement Description
Seq Forward Sequence An original sequence.
Pred UnaryLambda Expression A partitioning predicate.
In1,In2 Inserter Output inserters.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Reversible Algorithm .
For anyForward Sequence s, an unary Lambda Expression pred, andInsertersin1andin2:
typedef reverse_stable_partition<s,pred,in1,in2>::type r;
Return type: Apair.
Semantics: Equivalent to
typedef lambda<pred>::type p;
typedef lambda<in1::operation>::type in1_op;
typedef lambda<in2::operation>::type in2_op;
Revision Date: 15th November 2004139 Algorithms 3.5 Transformation Algorithms
typedef reverse_fold<
s
, pair< in1::state, in2::state >
, if_<
apply_wrap1<p,_2>
, pair< apply_wrap2<in1_op,first<_1>,_2>, second<_1> >
, pair< first<_1>, apply_wrap2<in2_op,second<_1>,_2> >
>
>::type r;
Complexity
Linear. Exactly size
::value applications of pred, and size
::value of summarized in1::operation /
in2::operation applications.
Example
template< typename N > struct is_odd : bool_<(N::value % 2)> {};
typedef reverse_stable_partition<
range_c<int,0,10>
, is_odd<_1>
, back_inserter< vector<> >
, back_inserter< vector<> >
>::type r;
BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,9,7,5,3,1> > ));
BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,8,6,4,2,0> > ));
See also
Transformation Algorithms ,Reversible Algorithm ,stable_partition ,reverse_partition ,sort,transform
Revision Date: 15th November 20043.5 Transformation Algorithms Algorithms 140
Revision Date: 15th November 2004Chapter 4 Metafunctions
The MPL includes a number of predeﬁned metafunctions that can be roughly classiﬁed in two categories: general pur-
pose metafunctions ,dealingwithconditional typeselection andhigher-ordermetafunction invocation ,composition ,and
argument binding , and numeric metafunctions , incapsulating built-in and user-deﬁned arithmetic ,comparison ,logical,
andbitwiseoperations.
Given that it is possible to perform integer numeric computations at compile time using the conventional operators
notation,theneedforthesecondcategorymightbenotobvious,butitinfactplaysacentalroleinmakingprogramming
with MPL seemingly effortless. In particular, there are at least two contexts where built-in language facilities fall
short3):
1)Passing a computation to an algorithm.
2)Performing a computationon non-integer data.
The second use case deserves special attention. In contrast to the built-in, strictly integer compile-time arithmetics, the
MPLnumericmetafunctionsare polymorphic ,withsupportfor mixed-typearithmetics . Thismeansthattheycanoperate
on a variety of numeric types — for instance, rational, ﬁxed-point or complex numbers, — and that, in general, you are
allowed to freely intermix these types within a single expression. See Numeric Metafunction concept for more details
on the MPL numeric infrastructure.
To reduce a negative syntactical impact of the metafunctions notation over the inﬁx operator notation, all numeric
metafunctions allow to pass up to N arguments, where N is deﬁned by the value of BOOST_MPL_LIMIT_METAFUNC-
TION_ARITY conﬁguration macro.
4.1 Concepts
4.1.1 Metafunction
Description
Ametafunction isaclassoraclasstemplatethatrepresentsafunctioninvocableatcompile-time. Annon-nullarymeta-
functionisinvokedbyinstantiatingtheclasstemplatewithparticulartemplateparameters(metafunctionarguments);the
result of the metafunction application is accessible through the instantiation’s nested typetypedef. All metafunction’s
arguments must be types (i.e. only type template parameters are allowed). A metafunction can have a variable number
of parameters. A nullary metafunction is represented as a (template) class with a nested typetypename member.
Expression requirements
In the following table and subsequent speciﬁcations, fis aMetafunction .
3)All other considerations aside, as of the time of this writing (early 2004), using built-in operators on integral constants still often present a
portability problem — many compilers cannot handle particular forms of expressions, forcing us to use conditional compilation. Because MPL
numeric metafunctions work on types and encapsulate these kind of workarounds internally, they elude these problems, so if you aim for portability,
it is generally adviced to use them in the place of the conventional operators, even at the price of slightly decreased readability.4.1 Concepts Metafunctions 142
Expression Type Complexity
Expression Type Complexity
f::type Any type Unspeciﬁed.
f<>::type Any type Unspeciﬁed.
f<a1,..,an>::type Any type Unspeciﬁed.
Expression semantics
typedef f::type x;
Precondition: fis a nullary Metafunction ;f::type is atype-name .
Semantics: xis the result of the metafunction invocation.
typedef f<>::type x;
Precondition: fis a nullary Metafunction ;f<>::type is atype-name .
Semantics: xis the result of the metafunction invocation.
typedef f<a1, ... an>::type x;
Precondition: fis ann-aryMetafunction ;a1,...anare types; f<a1,...an>::type is atype-name .
Semantics: xis the result of the metafunction invocation with the actual arguments a1,...an.
Models
—identity
—plus
—begin
—insert
—fold
See also
Metafunctions ,Metafunction Class ,Lambda Expression ,invocation ,apply,lambda,bind
4.1.2 Metafunction Class
Summary
Ametafunctionclass isacertainformofmetafunctionrepresentationthatenableshigher-ordermetaprogramming. More
precisely, it’s a class with a publicly-accessible nested Metafunction called apply. Correspondingly, a metafunction
class invocation is deﬁned asinvocation of its nested applymetafunction.
Expression requirements
In the following table and subsequent speciﬁcations, fis aMetafunction Class .
Revision Date: 15th November 2004143 Metafunctions 4.1 Concepts
Expression Type Complexity
f::apply::type Any type Unspeciﬁed.
f::apply<>::type Any type Unspeciﬁed.
f::apply<a1,...an>::type Any type Unspeciﬁed.
Expression semantics
typedef f::apply::type x;
Precondition: fis a nullary Metafunction Class ;f::apply::type is atype-name .
Semantics: xis the result of the metafunction class invocation.
typedef f::apply<>::type x;
Precondition: fis a nullary Metafunction Class ;f::apply<>::type is atype-name .
Semantics: xis the result of the metafunction class invocation.
typedef f::apply<a1, ...an>::type x;
Precondition: fis ann-ary metafunction class; applyis aMetafunction .
Semantics: xis the result of the metafunction class invocation with the actual arguments a1,...an.
Models
—always
—arg
—quote
—numeric_cast
—unpack_args
See also
Metafunctions ,Metafunction ,Lambda Expression ,invocation ,apply_wrap ,bind,quote
4.1.3 Lambda Expression
Description
ALambda Expression is a compile-time invocable entity in either of the following two forms:
—Metafunction Class
—Placeholder Expression
Most of the MPL components accept either of those, and the concept gives us a consice way to describe these require-
ments.
Expression requirements
See corresponding Metafunction Class andPlaceholder Expression speciﬁcations.
Revision Date: 15th November 20044.1 Concepts Metafunctions 144
Models
—always
—unpack_args
—plus<_, int_<2> >
—if_< less<_1, int_<7> >, plus<_1,_2>, _1 >
See also
Metafunctions ,Placeholders ,apply,lambda
4.1.4 Placeholder Expression
Description
APlaceholder Expression is a type that is either a placeholder or a class template specialization with at least one
argument that itself is a Placeholder Expression .
Expression requirements
IfXis a class template, and a1,...anare arbitrary types, then X<a1,...,an> is aPlaceholder Expression if and only if
all of the following conditions hold:
—At least one of the template arguments a1,...anis aplaceholder or aPlaceholder Expression .
—All of X’s template parameters, including the default ones, are types.
—The number of X’s template parameters, including the default ones, is less or equal to the value of BOOST_MPL_-
LIMIT_METAFUNCTION_ARITY conﬁguration macro .
Models
—_1
—plus<_, int_<2> >
—if_< less<_1, int_<7> >, plus<_1,_2>, _1 >
See also
Lambda Expression ,Placeholders ,Metafunctions ,apply,lambda
4.1.5 Tag Dispatched Metafunction
Summary
ATag Dispatched Metafunction is aMetafunction that employs a tag dispatching technique in its implementation to
build an infrastructure for easy overriding/extenstion of the metafunction’s behavior.
Notation
Revision Date: 15th November 2004145 Metafunctions 4.1 Concepts
Symbol Legend
name A placeholder token for the speciﬁc metafunction’s name.
tag-metafunction A placeholder token for the tag metafunction’s name.
tag A placeholder token for one of possible tag types returned by the tag meta-
function.
Synopsis
template< typename Tag > struct name _impl;
template<
typename X
[, ...]
>
struct name
:name _impl< typename tag-metafunction <X>::type >
::template apply<X [, ...] >
{
};
template< typename Tag > struct name _impl
{
template< typename X [, ...] > struct apply
{
//default implementation
};
};
template<> struct name _impl< tag>
{
template< typename X [, ...] > struct apply
{
//tag-specific implementation
};
};
Description
Theusualmechanismforoverridingametafunction’sbehaviorisclasstemplatespecialization—givenalibrary-deﬁned
metafunction f, it’s possible to write a specialization of ffor a speciﬁc type user_type that would have the required
semantics4).
While this mechanism is always available, it’s not always the most convenient one, especially if it is desirable to spe-
cialize a metafunction’s behavior for a familyof related types. A typical example of it is numbered forms of sequence
classes in MPL itself ( list0, ...,list50, et al.), and sequence classes in general.
ATag Dispatched Metafunction is a concept name for an instance of the metafunction implementation infrastructure
being employed by the library to make it easier for users and implementors to override the behavior of library’s meta-
functions operating on families of speciﬁc types.
Theinfrastructureisbuiltonavariationofthetechniquecommonlyknownas tagdispatching (hencetheconceptname),
and involves three entities: a metafunction itself, an associated tag-producing tag metafunction , and the metafunction’s
implementation,intheformofa MetafunctionClass templateparametrizedbya Tagtypeparameter. Themetafunction
Revision Date: 15th November 20044.1 Concepts Metafunctions 146
redirectstoitsimplementationclasstemplatebyinvokingitsspecializationonatagtypeproducedbythetagmetafunc-
tion with the original metafunction’s parameters.
Example
#include <boost/mpl/size.hpp>
namespace user {
struct bitset_tag;
struct bitset0
{
typedef bitset_tag tag;
// ...
};
template< typename B0 > struct bitset1
{
typedef bitset_tag tag;
// ...
};
template< typename B0, ..., typename B n> struct bitset n
{
typedef bitset_tag tag;
// ...
};
} // namespace user
namespace boost { namespace mpl {
template<> struct size_impl<user::bitset_tag>
{
template< typename Bitset > struct apply
{
typedef typename Bitset::size type;
};
};
}}
Models
—sequence_tag
See also
Metafunction ,Metafunction Class ,Numeric Metafunction
4)Usually such user-deﬁned specialization is still required to preserve the f’s original invariants and complexity requirements.
Revision Date: 15th November 2004147 Metafunctions 4.1 Concepts
4.1.6 Numeric Metafunction
Description
ANumeric Metafunction is aTag Dispatched Metafunction that provides a built-in infrastructure for easy implementa-
tion of mixed-type operations.
Expression requirements
In the following table and subsequent speciﬁcations, opis a placeholder token for the actual Numeric Metafunction ’s
name, and x,yandx1,x2,...xnare arbitrary numeric types.
Expression Type Complexity
op_tag<x>::type Integral Constant Amortized constant time.
op_impl<
op_tag<x>::type
, op_tag<y>::type
>::apply<x,y>::typeAny type Unspeciﬁed.
op<x1,x2,...xn>::type Any type Unspeciﬁed.
Expression semantics
typedef op_tag<x>::type tag;
Semantics: tagis a tag type for xforop.tag::value isx’sconversion rank .
typedef op_impl<
op_tag<x>::type
, op_tag<y>::type
>::apply<x,y>::type r;
Semantics: ris the result of opapplication on arguments xandy.
typedef op< x1,x2,... xn>::type r;
Semantics: ris the result of opapplication on arguments x1,x2,...xn.
Example
struct complex_tag : int_<10> {};
template< typename Re, typename Im > struct complex
{
typedef complex_tag tag;
typedef complex type;
typedef Re real;
typedef Im imag;
};
template< typename C > struct real : C::real {};
template< typename C > struct imag : C::imag {};
namespace boost { namespace mpl {
Revision Date: 15th November 20044.1 Concepts Metafunctions 148
template<>
struct plus_impl< complex_tag,complex_tag >
{
template< typename N1, typename N2 > struct apply
: complex<
plus< typename N1::real, typename N2::real >
, plus< typename N1::imag, typename N2::imag >
>
{
};
};
}}
typedef complex< int_<5>, int_<-1> > c1;
typedef complex< int_<-5>, int_<1> > c2;
typedef plus<c1,c2> r1;
BOOST_MPL_ASSERT_RELATION( real<r1>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( imag<r1>::value, ==, 0 );
typedef plus<c1,c1> r2;
BOOST_MPL_ASSERT_RELATION( real<r2>::value, ==, 10 );
BOOST_MPL_ASSERT_RELATION( imag<r2>::value, ==, -2 );
typedef plus<c2,c2> r3;
BOOST_MPL_ASSERT_RELATION( real<r3>::value, ==, -10 );
BOOST_MPL_ASSERT_RELATION( imag<r3>::value, ==, 2 );
Models
—plus
—minus
—times
—divides
See also
Tag Dispatched Metafunction ,Metafunctions ,numeric_cast
4.1.7 Trivial Metafunction
Description
ATrivial Metafunction accepts a single argument of a class type xand returns the x’s nested type member x::name,
where nameis a placeholder token for the actual member’s name accessed by a speciﬁc metafunction’s instance. By
convention,all trivialmetafunctions inMPLarenamedafterthememberstheyprovideassessto. Forinstance,a Trivial
Metafunction named firstreaches for the x’s nested member ::first.
Revision Date: 15th November 2004149 Metafunctions 4.2 Type Selection
Expression requirements
Inthefollowingtableandsubsequentspeciﬁcations, nameisplaceholdertokenforthenamesofthe TrivialMetafunction
itself and the accessed member, and xis a class type such that x::name is a valid type-name .
Expression Type Complexity
name<x>::type Any type Constant time.
Expression semantics
typedef name<x>::type r;
Precondition: x::name is a valid type-name .
Semantics: is_same<r,x::name>::value == true .
Models
—first
—second
—base
See also
Metafunctions ,Trivial Metafunctions ,identity
4.2 Type Selection
4.2.1 if_
Synopsis
template<
typename C
, typename T1
, typename T2
>
struct if_
{
typedef unspecified type;
};
Description
Returns one of its two arguments, T1orT2, depending on the value C.
Header
#include <boost/mpl/if.hpp>
Revision Date: 15th November 20044.2 Type Selection Metafunctions 150
Parameters
Revision Date: 15th November 2004151 Metafunctions 4.2 Type Selection
Parameter Requirement Description
C Integral Constant A selection condition.
T1,T2 Any type Types to select from.
Expression semantics
For anyIntegral Constant cand arbitrary types t1,t2:
typedef if_<c,t1,t2>::type t;
Return type: Any type.
Semantics: Ifc::value == true ,tis identical to t1; otherwise tis identical to t2.
Example
typedef if_<true_,char,long>::type t1;
typedef if_<false_,char,long>::type t2;
BOOST_MPL_ASSERT(( is_same<t1, char> ));
BOOST_MPL_ASSERT(( is_same<t2, long> ));
See also
Metafunctions ,Integral Constant ,if_c,eval_if
4.2.2 if_c
Synopsis
template<
bool c
, typename T1
, typename T2
>
struct if_c
{
typedef unspecified type;
};
Description
Returnsoneofitstwoarguments, T1orT2,dependingonthevalueofintegralconstant c.if_c<c,t1,t2>::type isa
shorcut notation for if_< bool_<c>,t1,t2 >::type .
Header
#include <boost/mpl/if.hpp>
Parameters
Revision Date: 15th November 20044.2 Type Selection Metafunctions 152
Parameter Requirement Description
c An integral constant A selection condition.
T1,T2 Any type Types to select from.
Expression semantics
For any integral constant cand arbitrary types t1,t2:
typedef if_c<c,t1,t2>::type t;
Return type: Any type.
Semantics: Equivalent to typedef if_< bool_<c>,t1,t2 >::type t;
Example
typedef if_c<true,char,long>::type t1;
typedef if_c<false,char,long>::type t2;
BOOST_MPL_ASSERT(( is_same<t1, char> ));
BOOST_MPL_ASSERT(( is_same<t2, long> ));
See also
Metafunctions ,Integral Constant ,if_,eval_if,bool_
4.2.3 eval_if
Synopsis
template<
typename C
, typename F1
, typename F2
>
struct eval_if
{
typedef unspecified type;
};
Description
Evaluates one of its two nullary-metafunction arguments, F1orF2, depending on the value C.
Header
#include <boost/mpl/eval_if.hpp>
Parameters
Revision Date: 15th November 2004153 Metafunctions 4.2 Type Selection
Parameter Requirement Description
C Integral Constant An evaluation condition.
F1,F2 NullaryMetafunction Metafunctions to select forevaluation from.
Expression semantics
For anyIntegral Constant cand nullary Metafunction sf1,f2:
typedef eval_if<c,f1,f2>::type t;
Return type: Any type.
Semantics: Ifc::value == true ,tis identical to f1::type ; otherwise tis identical to f2::type .
Example
typedef eval_if< true_, identity<char>, identity<long> >::type t1;
typedef eval_if< false_, identity<char>, identity<long> >::type t2;
BOOST_MPL_ASSERT(( is_same<t1,char> ));
BOOST_MPL_ASSERT(( is_same<t2,long> ));
See also
Metafunctions ,Integral Constant ,eval_if_c ,if_
4.2.4 eval_if_c
Synopsis
template<
bool c
, typename F1
, typename F2
>
struct eval_if_c
{
typedef unspecified type;
};
Description
Evaluates one of its two nullary-metafunction arguments, F1orF2, depending on the value of integral constant c.
eval_if_c<c,f1,f2>::type is a shorcut notation for eval_if< bool_<c>,f1,f2 >::type .
Header
#include <boost/mpl/eval_if.hpp>
Parameters
Revision Date: 15th November 20044.3 Invocation Metafunctions 154
Parameter Requirement Description
c An integral constant An evaluation condition.
F1,F2 NullaryMetafunction Metafunctions to select forevaluation from.
Expression semantics
For any integral constant cand nullary Metafunction sf1,f2:
typedef eval_if_c<c,f1,f2>::type t;
Return type: Any type.
Semantics: Equivalent to typedef eval_if< bool_<c>,f1,f2 >::type t;
Example
typedef eval_if_c< true, identity<char>, identity<long> >::type t1;
typedef eval_if_c< false, identity<char>, identity<long> >::type t2;
BOOST_MPL_ASSERT(( is_same<t1,char> ));
BOOST_MPL_ASSERT(( is_same<t2,long> ));
See also
Metafunctions ,Integral Constant ,eval_if,if_,bool_
4.3 Invocation
4.3.1 apply
Synopsis
template<
typename F
>
struct apply0
{
typedef unspecified type;
};
template<
typename F, typename A1
>
struct apply1
{
typedef unspecified type;
};
...
template<
typename F, typename A1, ... typename An
>
Revision Date: 15th November 2004155 Metafunctions 4.3 Invocation
struct apply n
{
typedef unspecified type;
};
template<
typename F
, typename A1 = unspecified
...
, typename An = unspecified
>
struct apply
{
typedef unspecified type;
};
Description
Invokes a Metafunction Class or aLambda Expression Fwith arguments A1,...An.
Header
#include <boost/mpl/apply.hpp>
Parameters
Parameter Requirement Description
F Lambda Expression An expression to invoke.
A1,...An Any type Invocation arguments.
Expression semantics
For anyLambda Expression fand arbitrary types a1,...an:
typedef apply n<f,a1, ...an>::type t;
typedef apply<f,a1, ...an>::type t;
Return type: Any type.
Semantics: Equivalent to typedef apply_wrap n< lambda<f>::type,a1,... an>::type t; .
Example
template< typename N1, typename N2 > struct int_plus
: int_<( N1::value + N2::value )>
{
};
typedef apply< int_plus<_1,_2>, int_<2>, int_<3> >::type r1;
typedef apply< quote2<int_plus>, int_<2>, int_<3> >::type r2;
BOOST_MPL_ASSERT_RELATION( r1::value, ==, 5 );
Revision Date: 15th November 20044.3 Invocation Metafunctions 156
BOOST_MPL_ASSERT_RELATION( r2::value, ==, 5 );
See also
Metafunctions ,apply_wrap ,lambda,quote,bind
4.3.2 apply_wrap
Synopsis
template<
typename F
>
struct apply_wrap0
{
typedef unspecified type;
};
template<
typename F, typename A1
>
struct apply_wrap1
{
typedef unspecified type;
};
...
template<
typename F, typename A1, ... typename An
>
struct apply_wrap n
{
typedef unspecified type;
};
Description
Invokes a Metafunction Class Fwith arguments A1,...An.
In essence, apply_wrap forms are nothing more than syntactic wrappers around F::apply<A1,... An>::type /
F::apply::type expressions(hencethename). Theyprovideamoreconcisenotationandhigherportabilitythantheir
underlaying constructs at thecost of an extra template instantiation.
Header
#include <boost/mpl/apply_wrap.hpp>
Parameters
Revision Date: 15th November 2004157 Metafunctions 4.3 Invocation
Parameter Requirement Description
F Metafunction Class A metafunction class to invoke.
A1,...An Any type Invocation arguments.
Expression semantics
For anyMetafunction Class fand arbitrary types a1,...an:
typedef apply_wrap n<f,a1, ...an>::type t;
Return type: Any type.
Semantics: Ifn > 0, equivalent to typedef f::apply<a1,... an>::type t; , otherwise equiva-
lent to either typedef f::apply::type t; ortypedef f::apply<>::type t; depending on
whether f::apply is a class or a class template.
Example
struct f0
{
template< typename T = int > struct apply
{
typedef char type;
};
};
struct g0
{
struct apply { typedef char type; };
};
struct f2
{
template< typename T1, typename T2 > struct apply
{
typedef T2 type;
};
};
typedef apply_wrap0< f0 >::type r1;
typedef apply_wrap0< g0 >::type r2;
typedef apply_wrap2< f2,int,char >::type r3;
BOOST_MPL_ASSERT(( is_same<r1,char> ));
BOOST_MPL_ASSERT(( is_same<r2,char> ));
BOOST_MPL_ASSERT(( is_same<r3,char> ));
See also
Metafunctions ,invocation ,apply,lambda,quote,bind,protect
Revision Date: 15th November 20044.3 Invocation Metafunctions 158
4.3.3 unpack_args
Synopsis
template<
typename F
>
struct unpack_args
{
//unspecified
//...
};
Description
A higher-order primitive transforming an n-aryLambda Expression Finto an unary Metafunction Class gaccepting a
single sequence of narguments.
Header
#include <boost/mpl/unpack_args.hpp>
Model of
Metafunction Class
Parameters
Parameter Requirement Description
F Lambda Expression A lambda expression to adopt.
Expression semantics
For an arbitrary Lambda Expression f, and arbitrary types a1,...an:
typedef unpack_args<f> g;
Return type: Metafunction Class .
Semantics: gis a unary Metafunction Class such that
apply_wrap n< g, vector<a1, ...an> >::type
is identical to
apply<F,a1, ...an>::type
Example
BOOST_MPL_ASSERT(( apply<
unpack_args< is_same<_1,_2> >
, vector<int,int>
> ));
Revision Date: 15th November 2004159 Metafunctions 4.4 Composition and Argument Binding
See also
Metafunctions ,Lambda Expression ,Metafunction Class ,apply,apply_wrap ,bind
4.4 Composition and Argument Binding
4.4.1 Placeholders
Synopsis
namespace placeholders {
typedef unspecified _;
typedef arg<1> _1;
typedef arg<2> _2;
...
typedef arg< n> _ n;
}
using placeholders::_;
using placeholders::_1;
using placeholders::_2;
...
using placeholders::_ n;
Description
Aplaceholderinaform _nissimplyasynonymforthecorresponding arg<n>specialization. Theunnamedplaceholder
_(underscore) carries special meaning in bind and lambda expressions, and does not have deﬁned semantics outside of
these contexts.
Placeholder names can be made available in the user namespace through using namespace mpl::placeholders;
directive.
Header
#include <boost/mpl/placeholders.hpp>
[Note:Theincludemightbeomittedwhenusingplaceholderstoconstructa LambdaExpression forpassingittoMPL’s
own algorithm or metafunction: any library component that is documented to accept a lambda expression makes the
placeholders implicitly available for the user code — end note]
Parameters
None.
Expression semantics
For any integral constant nin the range [1, BOOST_MPL_LIMIT_METAFUNCTION_ARITY ] and arbitrary types a1,...an:
typedef apply_wrap n<_n,a1, ...an>::type x;
Return type: A type.
Semantics: Equivalent to
Revision Date: 15th November 20044.4 Composition and Argument Binding Metafunctions 160
typedef apply_wrap n< arg< n>,a1, ...an>::type x;
Example
typedef apply_wrap5< _1,bool,char,short,int,long >::type t1;
typedef apply_wrap5< _3,bool,char,short,int,long >::type t3;
BOOST_MPL_ASSERT(( is_same< t1, bool > ));
BOOST_MPL_ASSERT(( is_same< t3, short > ));
See also
Composition and Argument Binding ,arg,lambda,bind,apply,apply_wrap
4.4.2 lambda
Synopsis
template<
typename X
, typename Tag = unspecified
>
struct lambda
{
typedef unspecified type;
};
Description
IfXis aPlaceholder Expression , transforms Xinto a corresponding Metafunction Class , otherwise Xis returned un-
changed.
Header
#include <boost/mpl/lambda.hpp>
Parameters
Parameter Requirement Description
X Any type An expression to transform.
Tag Any type A tag determining transformsemantics.
Expression semantics
For arbitrary types xandtag:
typedef lambda<x>::type f;
Return type: Metafunction Class .
Semantics: Ifxis aPlaceholder Expression in a general form X<a1,...an> , where Xis a class template
Revision Date: 15th November 2004161 Metafunctions 4.4 Composition and Argument Binding
anda1,...anare arbitrary types, equivalentto
typedef protect< bind<
quote n<X>
, lambda<a1>::type, ... lambda<a n>::type
> > f;
otherwise, fis identical to x.
typedef lambda<x,tag>::type f;
Return type: Metafunction Class .
Semantics: Ifxis aPlaceholder Expression in a general form X<a1,...an> , where Xis a class template
anda1,...anare arbitrary types, equivalentto
typedef protect< bind<
quote n<X,tag>
, lambda<a1,tag>::type, ... lambda<a n,tag>::type
> > f;
otherwise, fis identical to x.
Example
template< typename N1, typename N2 > struct int_plus
: int_<( N1::value + N2::value )>
{
};
typedef lambda< int_plus<_1, int_<42> > >::type f1;
typedef bind< quote2<int_plus>, _1, int_<42> > f2;
typedef f1::apply<42>::type r1;
typedef f2::apply<42>::type r2;
BOOST_MPL_ASSERT_RELATION( r1::value, ==, 84 );
BOOST_MPL_ASSERT_RELATION( r2::value, ==, 84 );
See also
Composition and Argument Binding ,invocation ,Placeholders ,bind,quote,protect,apply
4.4.3 bind
Synopsis
template<
typename F
>
struct bind0
{
//unspecified
//...
};
Revision Date: 15th November 20044.4 Composition and Argument Binding Metafunctions 162
template<
typename F, typename A1
>
struct bind1
{
//unspecified
//...
};
...
template<
typename F, typename A1, ... typename An
>
struct bind n
{
//unspecified
//...
};
template<
typename F
, typename A1 = unspecified
...
, typename An = unspecified
>
struct bind
{
//unspecified
//...
};
Description
bindis a higher-order primitive for Metafunction Class composition and argument binding. In essence, it’s a compile-
time counterpart of the similar run-time functionality provided by Boost.Bind andBoost.Lambda libraries.
Header
#include <boost/mpl/bind.hpp>
Model of
Metafunction Class
Parameters
Parameter Requirement Description
F Metafunction Class An metafunction class to perform binding on.
A1,...An Any type Arguments to bind.
Revision Date: 15th November 2004163 Metafunctions 4.4 Composition and Argument Binding
Expression semantics
For anyMetafunction Class fand arbitrary types a1,...an:
typedef bind<f,a1,...a n> g;
typedef bind n<f,a1,...a n> g;
Return type: Metafunction Class
Semantics: Equivalent to
struct g
{
template<
typename U1 = unspecified
...
, typename U n=unspecified
>
struct apply
: apply_wrap n<
typename h0<f,U1, ...Un>::type
, typename h1<a1,U1, ...Un>::type
...
, typename h n<an,U1, ...Un>::type
>
{
};
};
where hkis equivalent to
template< typename X, typename U1, ... typename U n> struct h k
: apply_wrap n<X,U1, ...Un>
{
};
ifforakis abind expression or aplaceholder , and
template< typename X, typename U1, ... typename U n> struct h k
{
typedef X type;
};
otherwise. [ Note:Every nth appearance of the unnamed placeholder in the bind<f,a1,...an>
specialization is replaced with the corresponding numbered placeholder _n—end note]
Example
struct f1
{
template< typename T1 > struct apply
{
typedef T1 type;
};
};
struct f5
Revision Date: 15th November 20044.4 Composition and Argument Binding Metafunctions 164
{
template< typename T1, typename T2, typename T3, typename T4, typename T5 >
struct apply
{
typedef T5 type;
};
};
typedef apply_wrap1<
bind1<f1,_1>
, int
>::type r11;
typedef apply_wrap5<
bind1<f1,_5>
, void,void,void,void,int
>::type r12;
BOOST_MPL_ASSERT(( is_same<r11,int> ));
BOOST_MPL_ASSERT(( is_same<r12,int> ));
typedef apply_wrap5<
bind5<f5,_1,_2,_3,_4,_5>
, void,void,void,void,int
>::type r51;
typedef apply_wrap5<
bind5<f5,_5,_4,_3,_2,_1>
, int,void,void,void,void
>::type r52;
BOOST_MPL_ASSERT(( is_same<r51,int> ));
BOOST_MPL_ASSERT(( is_same<r52,int> ));
See also
Composition and Argument Binding ,invocation ,Placeholders ,lambda,quote,protect,apply,apply_wrap
4.4.4 quote
Synopsis
template<
template< typename P1 > class F
, typename Tag = unspecified
>
struct quote1
{
//unspecified
//...
};
Revision Date: 15th November 2004165 Metafunctions 4.4 Composition and Argument Binding
...
template<
template< typename P1, ... typename P n> class F
, typename Tag = unspecified
>
struct quote n
{
//unspecified
//...
};
Description
quotenis a higher-order primitive that wraps an n-aryMetafunction to create a corresponding Metafunction Class .
Header
#include <boost/mpl/quote.hpp>
Model of
Metafunction Class
Parameters
Parameter Requirement Description
F Metafunction A metafunction to wrap.
Tag Any type A tag determining wrap semantics.
Expression semantics
For anyn-aryMetafunction fand arbitrary type tag:
typedef quote n<f> g;
typedef quote n<f,tag> g;
Return type: Metafunction Class
Semantics: Equivalent to
struct g
{
template< typename A1, ... typename A n> struct apply
: f<A1, ...An>
{
};
};
iff<A1,...An> has a nested type member ::type, and to
struct g
{
Revision Date: 15th November 20044.4 Composition and Argument Binding Metafunctions 166
template< typename A1, ... typename A n> struct apply
{
typedef f<A1, ...An> type;
};
};
otherwise.
Example
template< typename T > struct f1
{
typedef T type;
};
template<
typename T1, typename T2, typename T3, typename T4, typename T5
>
struct f5
{
// no ’type’ member!
};
typedef quote1<f1>::apply<int>::type t1;
typedef quote5<f5>::apply<char,short,int,long,float>::type t5;
BOOST_MPL_ASSERT(( is_same< t1, int > ));
BOOST_MPL_ASSERT(( is_same< t5, f5<char,short,int,long,float> > ));
See also
Composition and Argument Binding ,invocation ,bind,lambda,protect,apply
4.4.5 arg
Synopsis
template< int n > struct arg;
template<> struct arg<1>
{
template< typename A1, ... typename A n=unspecified >
struct apply
{
typedef A1 type;
};
};
...
template<> struct arg< n>
{
Revision Date: 15th November 2004167 Metafunctions 4.4 Composition and Argument Binding
template< typename A1, ... typename A n>
struct apply
{
typedef A ntype;
};
};
Description
arg<n>specialization is a Metafunction Class that return the nth of its arguments.
Header
#include <boost/mpl/arg.hpp>
Parameters
Parameter Requirement Description
n An integral constant A number of argument to return.
Expression semantics
For any integral constant nin the range [1, BOOST_MPL_LIMIT_METAFUNCTION_ARITY ] and arbitrary types a1,...an:
typedef apply_wrap n< arg< n>,a1, ...an>::type x;
Return type: A type.
Semantics: xis identical to an.
Example
typedef apply_wrap5< arg<1>,bool,char,short,int,long >::type t1;
typedef apply_wrap5< arg<3>,bool,char,short,int,long >::type t3;
BOOST_MPL_ASSERT(( is_same< t1, bool > ));
BOOST_MPL_ASSERT(( is_same< t3, short > ));
See also
Composition and Argument Binding ,Placeholders ,lambda,bind,apply,apply_wrap
4.4.6 protect
Synopsis
template<
typename F
>
struct protect
{
Revision Date: 15th November 20044.4 Composition and Argument Binding Metafunctions 168
//unspecified
//...
};
Description
protect is an identity wrapper for a Metafunction Class that prevents its argument from being recognized as a bind
expression .
Header
#include <boost/mpl/protect.hpp>
Parameters
Parameter Requirement Description
F Metafunction Class A metafunction class to wrap.
Expression semantics
For anyMetafunction Class f:
typedef protect<f> g;
Return type: Metafunction Class .
Semantics: Iffis abind expression , equivalent to
struct g
{
template<
typename U1 = unspecified ,... typename U n=unspecified
>
struct apply
: apply_wrap n<f,U1, ...Un>
{
};
};
otherwise equivalent to typedef f g; .
Example
FIXME
struct f
{
template< typename T1, typename T2 > struct apply
{
//...
};
};
Revision Date: 15th November 2004169 Metafunctions 4.5 Arithmetic Operations
typedef bind<_1, protect< bind<f,_1,_2> > >
typedef apply_wrap0< f0 >::type r1;
typedef apply_wrap0< g0 >::type r2;
typedef apply_wrap2< f2,int,char >::type r3;
BOOST_MPL_ASSERT(( is_same<r1,char> ));
BOOST_MPL_ASSERT(( is_same<r2,char> ));
BOOST_MPL_ASSERT(( is_same<r3,char> ));
See also
Composition and Argument Binding ,invocation ,bind,quote,apply_wrap
4.5 Arithmetic Operations
4.5.1 plus
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct plus
{
typedef unspecified type;
};
Description
Returns the sum of its arguments.
Header
#include <boost/mpl/plus.hpp>
#include <boost/mpl/arithmetic.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
Revision Date: 15th November 20044.5 Arithmetic Operations Metafunctions 170
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef plus<c1, ...cn>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value + c2::value)
, ( c1::value + c2::value )
> c;
typedef plus<c,c3, ...cn>::type r;
typedef plus<c1, ...cn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : plus<c1, ...cn>::type {};
Complexity
Amortized constant time.
Example
typedef plus< int_<-10>, int_<3>, long_<1> >::type r;
BOOST_MPL_ASSERT_RELATION( r::value, ==, -6 );
BOOST_MPL_ASSERT(( is_same< r::value_type, long > ));
See also
Arithmetic Operations ,Numeric Metafunction ,numeric_cast ,minus,negate,times
4.5.2 minus
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct minus
Revision Date: 15th November 2004171 Metafunctions 4.5 Arithmetic Operations
{
typedef unspecified type;
};
Description
Returns the difference of itsarguments.
Header
#include <boost/mpl/minus.hpp>
#include <boost/mpl/arithmetic.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef minus<c1, ...cn>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value - c2::value)
, ( c1::value - c2::value )
> c;
typedef minus<c,c3, ...cn>::type r;
typedef minus<c1, ...cn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : minus<c1, ...cn>::type {};
Complexity
Amortized constant time.
Revision Date: 15th November 20044.5 Arithmetic Operations Metafunctions 172
Example
typedef minus< int_<-10>, int_<3>, long_<1> >::type r;
BOOST_MPL_ASSERT_RELATION( r::value, ==, -14 );
BOOST_MPL_ASSERT(( is_same< r::value_type, long > ));
See also
Arithmetic Operations ,Numeric Metafunction ,numeric_cast ,plus,negate,times
4.5.3 times
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct times
{
typedef unspecified type;
};
Description
Returns the product of its arguments.
Header
#include <boost/mpl/times.hpp>
#include <boost/mpl/arithmetic.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Revision Date: 15th November 2004173 Metafunctions 4.5 Arithmetic Operations
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef times<c1, ...cn>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value * c2::value)
, ( c1::value * c2::value )
> c;
typedef times<c,c3, ...cn>::type r;
typedef times<c1, ...cn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : times<c1, ...cn>::type {};
Complexity
Amortized constant time.
Example
typedef times< int_<-10>, int_<3>, long_<1> >::type r;
BOOST_MPL_ASSERT_RELATION( r::value, ==, -30 );
BOOST_MPL_ASSERT(( is_same< r::value_type, long > ));
See also
Metafunctions ,Numeric Metafunction ,numeric_cast ,divides,modulus,plus
4.5.4 divides
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct divides
{
typedef unspecified type;
};
Revision Date: 15th November 20044.5 Arithmetic Operations Metafunctions 174
Description
Returns the quotient of its arguments.
Header
#include <boost/mpl/divides.hpp>
#include <boost/mpl/arithmetic.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef divides<c1, ...cn>::type r;
Return type: Integral Constant .
Precondition: c2::value != 0 ,...cn::value != 0 .
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value / c2::value)
, ( c1::value / c2::value )
> c;
typedef divides<c,c3, ...cn>::type r;
typedef divides<c1, ...cn> r;
Return type: Integral Constant .
Precondition: c2::value != 0 ,...cn::value != 0 .
Semantics: Equivalent to
struct r : divides<c1, ...cn>::type {};
Complexity
Amortized constant time.
Revision Date: 15th November 2004175 Metafunctions 4.5 Arithmetic Operations
Example
typedef divides< int_<-10>, int_<3>, long_<1> >::type r;
BOOST_MPL_ASSERT_RELATION( r::value, ==, -3 );
BOOST_MPL_ASSERT(( is_same< r::value_type, long > ));
See also
Arithmetic Operations ,Numeric Metafunction ,numeric_cast ,times,modulus,plus
4.5.5 modulus
Synopsis
template<
typename T1
, typename T2
>
struct modulus
{
typedef unspecified type;
};
Description
Returns the modulus of its arguments.
Header
#include <boost/mpl/modulus.hpp>
#include <boost/mpl/arithmetic.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef modulus<c1,c2>::type r;
Revision Date: 15th November 20044.5 Arithmetic Operations Metafunctions 176
Return type: Integral Constant .
Precondition: c2::value != 0
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value % c2::value)
, ( c1::value % c2::value )
> r;
typedef modulus<c1,c2> r;
Return type: Integral Constant .
Precondition: c2::value != 0
Semantics: Equivalent to
struct r : modulus<c1,c2>::type {};
Complexity
Amortized constant time.
Example
typedef modulus< int_<10>, long_<3> >::type r;
BOOST_MPL_ASSERT_RELATION( r::value, ==, 1 );
BOOST_MPL_ASSERT(( is_same< r::value_type, long > ));
See also
Metafunctions ,Numeric Metafunction ,numeric_cast ,divides,times,plus
4.5.6 negate
Synopsis
template<
typename T
>
struct negate
{
typedef unspecified type;
};
Description
Returns the negative (additiveinverse) of its argument.
Header
#include <boost/mpl/negate.hpp>
#include <boost/mpl/arithmetic.hpp>
Revision Date: 15th November 2004177 Metafunctions 4.6 Comparisons
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T Integral Constant Operation’s argument.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant c:
typedef negate<c>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c< c::value_type, ( -c::value ) > r;
typedef negate<c> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : negate<c>::type {};
Complexity
Amortized constant time.
Example
typedef negate< int_<-10> >::type r;
BOOST_MPL_ASSERT_RELATION( r::value, ==, 10 );
BOOST_MPL_ASSERT(( is_same< r::value_type, int > ));
See also
Arithmetic Operations ,Numeric Metafunction ,numeric_cast ,plus,minus,times
4.6 Comparisons
4.6.1 less
Synopsis
template<
typename T1
Revision Date: 15th November 20044.6 Comparisons Metafunctions 178
, typename T2
>
struct less
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant ifT1is less than T2.
Header
#include <boost/mpl/less.hpp>
#include <boost/mpl/comparison.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef less<c1,c2>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (c1::value < c2::value) > r;
typedef less<c1,c2> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : less<c1,c2>::type {};
Complexity
Amortized constant time.
Revision Date: 15th November 2004179 Metafunctions 4.6 Comparisons
Example
BOOST_MPL_ASSERT(( less< int_<0>, int_<10> > ));
BOOST_MPL_ASSERT_NOT(( less< long_<10>, int_<0> > ));
BOOST_MPL_ASSERT_NOT(( less< long_<10>, int_<10> > ));
See also
Comparisons ,Numeric Metafunction ,numeric_cast ,less_equal ,greater,equal
4.6.2 less_equal
Synopsis
template<
typename T1
, typename T2
>
struct less_equal
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant ifT1is less than or equal to T2.
Header
#include <boost/mpl/less_equal.hpp>
#include <boost/mpl/comparison.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef less_equal<c1,c2>::type r;
Revision Date: 15th November 20044.6 Comparisons Metafunctions 180
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (c1::value <= c2::value) > r;
typedef less_equal<c1,c2> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : less_equal<c1,c2>::type {};
Complexity
Amortized constant time.
Example
BOOST_MPL_ASSERT(( less_equal< int_<0>, int_<10> > ));
BOOST_MPL_ASSERT_NOT(( less_equal< long_<10>, int_<0> > ));
BOOST_MPL_ASSERT(( less_equal< long_<10>, int_<10> > ));
See also
Comparisons ,Numeric Metafunction ,numeric_cast ,less,greater,equal
4.6.3 greater
Synopsis
template<
typename T1
, typename T2
>
struct greater
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant ifT1is greater than T2.
Header
#include <boost/mpl/greater.hpp>
#include <boost/mpl/comparison.hpp>
Model of
Numeric Metafunction
Revision Date: 15th November 2004181 Metafunctions 4.6 Comparisons
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef greater<c1,c2>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (c1::value < c2::value) > r;
typedef greater<c1,c2> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : greater<c1,c2>::type {};
Complexity
Amortized constant time.
Example
BOOST_MPL_ASSERT(( greater< int_<10>, int_<0> > ));
BOOST_MPL_ASSERT_NOT(( greater< long_<0>, int_<10> > ));
BOOST_MPL_ASSERT_NOT(( greater< long_<10>, int_<10> > ));
See also
Comparisons ,Numeric Metafunction ,numeric_cast ,greater_equal ,less,equal_to
4.6.4 greater_equal
Synopsis
template<
typename T1
, typename T2
>
struct greater_equal
{
typedef unspecified type;
};
Revision Date: 15th November 20044.6 Comparisons Metafunctions 182
Description
Returns a true-valued Integral Constant ifT1is greater than or equal to T2.
Header
#include <boost/mpl/greater_equal.hpp>
#include <boost/mpl/comparison.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef greater_equal<c1,c2>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (c1::value < c2::value) > r;
typedef greater_equal<c1,c2> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : greater_equal<c1,c2>::type {};
Complexity
Amortized constant time.
Example
BOOST_MPL_ASSERT(( greater_equal< int_<10>, int_<0> > ));
BOOST_MPL_ASSERT_NOT(( greater_equal< long_<0>, int_<10> > ));
BOOST_MPL_ASSERT(( greater_equal< long_<10>, int_<10> > ));
Revision Date: 15th November 2004183 Metafunctions 4.6 Comparisons
See also
Comparisons ,Numeric Metafunction ,numeric_cast ,greater,less,equal_to
4.6.5 equal_to
Synopsis
template<
typename T1
, typename T2
>
struct equal_to
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant ifT1andT2are equal.
Header
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/comparison.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef equal_to<c1,c2>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (c1::value == c2::value) > r;
typedef equal_to<c1,c2> r;
Revision Date: 15th November 20044.6 Comparisons Metafunctions 184
Return type: Integral Constant .
Semantics: Equivalent to
struct r : equal_to<c1,c2>::type {};
Complexity
Amortized constant time.
Example
BOOST_MPL_ASSERT_NOT(( equal_to< int_<0>, int_<10> > ));
BOOST_MPL_ASSERT_NOT(( equal_to< long_<10>, int_<0> > ));
BOOST_MPL_ASSERT(( equal_to< long_<10>, int_<10> > ));
See also
Comparisons ,Numeric Metafunction ,numeric_cast ,not_equal_to ,less
4.6.6 not_equal_to
Synopsis
template<
typename T1
, typename T2
>
struct not_equal_to
{
typedef unspecified type;
};
Description
Returns a true-valued Integral Constant ifT1andT2are not equal.
Header
#include <boost/mpl/not_equal_to.hpp>
#include <boost/mpl/comparison.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2 Integral Constant Operation’s arguments.
Revision Date: 15th November 2004185 Metafunctions 4.7 Logical Operations
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1andc2:
typedef not_equal_to<c1,c2>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (c1::value != c2::value) > r;
typedef not_equal_to<c1,c2> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : not_equal_to<c1,c2>::type {};
Complexity
Amortized constant time.
Example
BOOST_MPL_ASSERT(( not_equal_to< int_<0>, int_<10> > ));
BOOST_MPL_ASSERT(( not_equal_to< long_<10>, int_<0> > ));
BOOST_MPL_ASSERT_NOT(( not_equal_to< long_<10>, int_<10> > ));
See also
Comparisons ,Numeric Metafunction ,numeric_cast ,equal_to ,less
4.7 Logical Operations
4.7.1 and_
Synopsis
template<
typename F1
, typename F2
...
, typename F n=unspecified
>
struct and_
{
typedef unspecified type;
};
Revision Date: 15th November 20044.7 Logical Operations Metafunctions 186
Description
Returns the result of short-circuit logical and (&&) operation on its arguments.
Header
#include <boost/mpl/and.hpp>
#include <boost/mpl/logical.hpp>
Parameters
Parameter Requirement Description
F1,F2,...Fn NullaryMetafunction Operation’s arguments.
Expression semantics
For arbitrary nullary Metafunction sf1,f2,...fn:
typedef and_<f1,f2, ...,fn>::type r;
Return type: Integral Constant .
Semantics: risfalse_if either of f1::type::value ,f2::type::value ,...fn::type::value ex-
pressions evaluates to false, and true_otherwise; guarantees left-to-right evaluation; the operands
subsequent to the ﬁrst fimetafunction that evaluates to falseare not evaluated.
typedef and_<f1,f2, ...,fn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : and_<f1,f2, ...,fn>::type {};
Example
struct unknown;
BOOST_MPL_ASSERT(( and_< true_,true_ > ));
BOOST_MPL_ASSERT_NOT(( and_< false_,true_ > ));
BOOST_MPL_ASSERT_NOT(( and_< true_,false_ > ));
BOOST_MPL_ASSERT_NOT(( and_< false_,false_ > ));
BOOST_MPL_ASSERT_NOT(( and_< false_,unknown > )); // OK
BOOST_MPL_ASSERT_NOT(( and_< false_,unknown,unknown > )); // OK too
See also
Metafunctions ,Logical Operations ,or_,not_
4.7.2 or_
Synopsis
template<
Revision Date: 15th November 2004187 Metafunctions 4.7 Logical Operations
typename F1
, typename F2
...
, typename F n=unspecified
>
struct or_
{
typedef unspecified type;
};
Description
Returns the result of short-circuit logical or (||) operation on its arguments.
Header
#include <boost/mpl/or.hpp>
#include <boost/mpl/logical.hpp>
Parameters
Parameter Requirement Description
F1,F2,...Fn NullaryMetafunction Operation’s arguments.
Expression semantics
For arbitrary nullary Metafunction sf1,f2,...fn:
typedef or_<f1,f2, ...,fn>::type r;
Return type: Integral Constant .
Semantics: ristrue_if either of f1::type::value ,f2::type::value ,...fn::type::value ex-
pressions evaluates to true, and false_otherwise; guarantees left-to-right evaluation; the operands
subsequent to the ﬁrst fimetafunction that evaluates to trueare not evaluated.
typedef or_<f1,f2, ...,fn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : or_<f1,f2, ...,fn>::type {};
Example
struct unknown;
BOOST_MPL_ASSERT(( or_< true_,true_ > ));
BOOST_MPL_ASSERT(( or_< false_,true_ > ));
BOOST_MPL_ASSERT(( or_< true_,false_ > ));
BOOST_MPL_ASSERT_NOT(( or_< false_,false_ > ));
BOOST_MPL_ASSERT(( or_< true_,unknown > )); // OK
BOOST_MPL_ASSERT(( or_< true_,unknown,unknown > )); // OK too
Revision Date: 15th November 20044.7 Logical Operations Metafunctions 188
See also
Metafunctions ,Logical Operations ,and_,not_
4.7.3 not_
Synopsis
template<
typename F
>
struct not_
{
typedef unspecified type;
};
Description
Returns the result of logical not (!) operation on its argument.
Header
#include <boost/mpl/not.hpp>
#include <boost/mpl/logical.hpp>
Parameters
Parameter Requirement Description
F NullaryMetafunction Operation’s argument.
Expression semantics
For arbitrary nullary Metafunction f:
typedef not_<f>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef bool_< (!f::type::value) > r;
typedef not_<f> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : not_<f>::type {};
Example
BOOST_MPL_ASSERT_NOT(( not_< true_ > ));
BOOST_MPL_ASSERT(( not_< false_ > ));
Revision Date: 15th November 2004189 Metafunctions 4.8 Bitwise Operations
See also
Metafunctions ,Logical Operations ,and_,or_
4.8 Bitwise Operations
4.8.1 bitand_
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct bitand_
{
typedef unspecified type;
};
Description
Returns the result of bitwise and (&) operation of its arguments.
Header
#include <boost/mpl/bitand.hpp>
#include <boost/mpl/bitwise.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef bitand_<c1, ...cn>::type r;
Return type: Integral Constant .
Revision Date: 15th November 20044.8 Bitwise Operations Metafunctions 190
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value & c2::value)
, ( c1::value & c2::value )
> c;
typedef bitand_<c,c3, ...cn>::type r;
typedef bitand_<c1, ...cn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : bitand_<c1, ...cn>::type {};
Complexity
Amortized constant time.
Example
typedef integral_c<unsigned,0> u0;
typedef integral_c<unsigned,1> u1;
typedef integral_c<unsigned,2> u2;
typedef integral_c<unsigned,8> u8;
typedef integral_c<unsigned,0xffffffff> uffffffff;
BOOST_MPL_ASSERT_RELATION( (bitand_<u0,u0>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (bitand_<u1,u0>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (bitand_<u0,u1>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (bitand_<u0,uffffffff>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (bitand_<u1,uffffffff>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (bitand_<u8,uffffffff>::value), ==, 8 );
See also
Bitwise Operations ,Numeric Metafunction ,numeric_cast ,bitor_,bitxor_,shift_left
4.8.2 bitor_
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct bitor_
{
typedef unspecified type;
Revision Date: 15th November 2004191 Metafunctions 4.8 Bitwise Operations
};
Description
Returns the result of bitwise or (|) operation of its arguments.
Header
#include <boost/mpl/bitor.hpp>
#include <boost/mpl/bitwise.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef bitor_<c1, ...cn>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value | c2::value)
, ( c1::value | c2::value )
> c;
typedef bitor_<c,c3, ...cn>::type r;
typedef bitor_<c1, ...cn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : bitor_<c1, ...cn>::type {};
Complexity
Amortized constant time.
Revision Date: 15th November 20044.8 Bitwise Operations Metafunctions 192
Example
typedef integral_c<unsigned,0> u0;
typedef integral_c<unsigned,1> u1;
typedef integral_c<unsigned,2> u2;
typedef integral_c<unsigned,8> u8;
typedef integral_c<unsigned,0xffffffff> uffffffff;
BOOST_MPL_ASSERT_RELATION( (bitor_<u0,u0>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (bitor_<u1,u0>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (bitor_<u0,u1>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (bitor_<u0,uffffffff>::value), ==, 0xffffffff );
BOOST_MPL_ASSERT_RELATION( (bitor_<u1,uffffffff>::value), ==, 0xffffffff );
BOOST_MPL_ASSERT_RELATION( (bitor_<u8,uffffffff>::value), ==, 0xffffffff );
See also
Bitwise Operations ,Numeric Metafunction ,numeric_cast ,bitand_,bitxor_,shift_left
4.8.3 bitxor_
Synopsis
template<
typename T1
, typename T2
, typename T3 = unspecified
...
, typename T n=unspecified
>
struct bitxor_
{
typedef unspecified type;
};
Description
Returns the result of bitwise xor (^) operation of its arguments.
Header
#include <boost/mpl/bitxor.hpp>
#include <boost/mpl/bitwise.hpp>
Model of
Numeric Metafunction
Parameters
Revision Date: 15th November 2004193 Metafunctions 4.8 Bitwise Operations
Parameter Requirement Description
T1,T2,...Tn Integral Constant Operation’s arguments.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For anyIntegral Constant sc1,c2,...cn:
typedef bitxor_<c1, ...cn>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
typeof(c1::value ^ c2::value)
, ( c1::value ^ c2::value )
> c;
typedef bitxor_<c,c3, ...cn>::type r;
typedef bitxor_<c1, ...cn> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : bitxor_<c1, ...cn>::type {};
Complexity
Amortized constant time.
Example
typedef integral_c<unsigned,0> u0;
typedef integral_c<unsigned,1> u1;
typedef integral_c<unsigned,2> u2;
typedef integral_c<unsigned,8> u8;
typedef integral_c<unsigned,0xffffffff> uffffffff;
BOOST_MPL_ASSERT_RELATION( (bitxor_<u0,u0>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (bitxor_<u1,u0>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (bitxor_<u0,u1>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (bitxor_<u0,uffffffff>::value), ==, 0xffffffff ^ 0 );
BOOST_MPL_ASSERT_RELATION( (bitxor_<u1,uffffffff>::value), ==, 0xffffffff ^ 1 );
BOOST_MPL_ASSERT_RELATION( (bitxor_<u8,uffffffff>::value), ==, 0xffffffff ^ 8 );
See also
Bitwise Operations ,Numeric Metafunction ,numeric_cast ,bitand_,bitor_,shift_left
Revision Date: 15th November 20044.8 Bitwise Operations Metafunctions 194
4.8.4 shift_left
Synopsis
template<
typename T
, typename Shift
>
struct shift_left
{
typedef unspecified type;
};
Description
Returns the result of bitwise shift left(<<) operation on T.
Header
#include <boost/mpl/shift_left.hpp>
#include <boost/mpl/bitwise.hpp>
Model of
Numeric Metafunction
Parameters
Parameter Requirement Description
T Integral Constant A value to shift.
Shift Unsigned Integral Constant A shift distance.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For arbitrary Integral Constant cand unsigned Integral Constant shift:
typedef shift_left<c,shift>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
c::value_type
, ( c::value << shift::value )
> r;
typedef shift_left<c,shift> r;
Revision Date: 15th November 2004195 Metafunctions 4.8 Bitwise Operations
Return type: Integral Constant .
Semantics: Equivalent to
struct r : shift_left<c,shift>::type {};
Complexity
Amortized constant time.
Example
typedef integral_c<unsigned,0> u0;
typedef integral_c<unsigned,1> u1;
typedef integral_c<unsigned,2> u2;
typedef integral_c<unsigned,8> u8;
BOOST_MPL_ASSERT_RELATION( (shift_left<u0,u0>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (shift_left<u1,u0>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (shift_left<u1,u1>::value), ==, 2 );
BOOST_MPL_ASSERT_RELATION( (shift_left<u2,u1>::value), ==, 4 );
BOOST_MPL_ASSERT_RELATION( (shift_left<u8,u1>::value), ==, 16 );
See also
Bitwise Operations ,Numeric Metafunction ,numeric_cast ,shift_right ,bitand_
4.8.5 shift_right
Synopsis
template<
typename T
, typename Shift
>
struct shift_right
{
typedef unspecified type;
};
Description
Returns the result of bitwise shift right (>>) operation on T.
Header
#include <boost/mpl/shift_right.hpp>
#include <boost/mpl/bitwise.hpp>
Model of
Numeric Metafunction
Revision Date: 15th November 20044.8 Bitwise Operations Metafunctions 196
Parameters
Parameter Requirement Description
T Integral Constant A value to shift.
Shift Unsigned Integral Constant A shift distance.
[Note:The requirements listed in this speciﬁcation are the ones imposed by the default implementation. See Numeric
Metafunction conceptforthedetailsonhowtoprovideanimplementationforauser-deﬁnednumerictypethatdoesnot
satisfy the Integral Constant requirements. — end note]
Expression semantics
For arbitrary Integral Constant cand unsigned Integral Constant shift:
typedef shift_right<c,shift>::type r;
Return type: Integral Constant .
Semantics: Equivalent to
typedef integral_c<
c::value_type
, ( c::value >> shift::value )
> r;
typedef shift_right<c,shift> r;
Return type: Integral Constant .
Semantics: Equivalent to
struct r : shift_right<c,shift>::type {};
Complexity
Amortized constant time.
Example
typedef integral_c<unsigned,0> u0;
typedef integral_c<unsigned,1> u1;
typedef integral_c<unsigned,2> u2;
typedef integral_c<unsigned,8> u8;
BOOST_MPL_ASSERT_RELATION( (shift_right<u0,u0>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (shift_right<u1,u0>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (shift_right<u1,u1>::value), ==, 0 );
BOOST_MPL_ASSERT_RELATION( (shift_right<u2,u1>::value), ==, 1 );
BOOST_MPL_ASSERT_RELATION( (shift_right<u8,u1>::value), ==, 4 );
See also
Bitwise Operations ,Numeric Metafunction ,numeric_cast ,shift_left ,bitand_
Revision Date: 15th November 2004197 Metafunctions 4.10 Miscellaneous
4.9 Trivial
The MPL provides a number of Trivial Metafunction s that a nothing more than thin wrappers for a differently-named
class nested type members. While important in the context of in-place metafunction composition , these metafunctions
havesolittletothemthatpresentingtheminthesameformatastherestofthecompomentsinthismanualwouldresult
in more boilerplate syntactic baggage than the actual content. To avoid this problem, we instead factor out the common
metafunctions’ requirements into the corresponding concept and gather all of them in a single place — this subsection
— in a compact table form that is presented below.
4.9.1 Trivial Metafunctions Summary
In the following table, xis an arbitrary class type.
Metafunction Header
first<x>::type #include <boost/mpl/pair.hpp>
second<x>::type #include <boost/mpl/pair.hpp>
base<x>::type #include <boost/mpl/base.hpp>
See Also
Metafunctions ,Trivial Metafunction
4.10 Miscellaneous
4.10.1 identity
Synopsis
template<
typename X
>
struct identity
{
typedef X type;
};
Description
Theidentitymetafunction. Returns Xunchanged.
Header
#include <boost/mpl/identity.hpp>
Model of
Metafunction
Parameters
Revision Date: 15th November 20044.10 Miscellaneous Metafunctions 198
Parameter Requirement Description
X Any type An argument to be returned.
Expression semantics
For an arbitrary type x:
typedef identity<x>::type r;
Return type: A type.
Semantics: Equivalent to
typedef x r;
Postcondition: is_same<r,x>::value == true .
Example
typedef apply< identity<_1>, char >::type t1;
typedef apply< identity<_2>, char,int >::type t2;
BOOST_MPL_ASSERT(( is_same< t1, char > ));
BOOST_MPL_ASSERT(( is_same< t2, int > ));
See also
Metafunctions ,Placeholders ,Trivial Metafunctions ,always,apply
4.10.2 always
Synopsis
template<
typename X
>
struct always
{
//unspecified
//...
};
Description
always<X> specialization is a variadic Metafunction Class always returning the same type, X, regardless of the number
and types of passed arguments.
Header
#include <boost/mpl/always.hpp>
Revision Date: 15th November 2004199 Metafunctions 4.10 Miscellaneous
Model of
Metafunction Class
Parameters
Parameter Requirement Description
X Any type A type to be returned.
Expression semantics
For an arbitrary type x:
typedef always<x> f;
Return type: Metafunction Class .
Semantics: Equivalent to
struct f : bind< identity<_1>, x > {};
Example
typedef always<true_> always_true;
BOOST_MPL_ASSERT(( apply< always_true,false_> ));
BOOST_MPL_ASSERT(( apply< always_true,false_,false_ > ));
BOOST_MPL_ASSERT(( apply< always_true,false_,false_,false_ > ));
See also
Metafunctions ,Metafunction Class ,identity ,bind,apply
4.10.3 inherit
Synopsis
template<
typename T1, typename T2
>
struct inherit2
{
typedef unspecified type;
};
...
template<
typename T1, typename T2, ... typename T n
>
struct inherit n
{
typedef unspecified type;
Revision Date: 15th November 20044.10 Miscellaneous Metafunctions 200
};
template<
typename T1
, typename T2
...
, typename T n=unspecified
>
struct inherit
{
typedef unspecified type;
};
Description
Returnsanunspeciﬁedclasstypepublicallyderivedfrom T1,T2,...Tn. Guaranteesthatderivationfrom empty_base is
always a no-op, regardless of the position and number of empty_base classes in T1,T2,...Tn.
Header
#include <boost/mpl/inherit.hpp>
Model of
Metafunction
Parameters
Parameter Requirement Description
T1,T2,...Tn A class type Classes to derived from.
Expression semantics
For artibrary class types t1,t2,...tn:
typedef inherit2<t1,t2>::type r;
Return type: A class type.
Precondition: t1andt2are complete types.
Semantics: If both t1andt2are identical to empty_base , equivalent to
typedef empty_base r;
otherwise, if t1is identical to empty_base , equivalent to
typedef t2 r;
otherwise, if t2is identical to empty_base , equivalent to
typedef t1 r;
otherwise equivalent to
struct r : t1, t2 {};
Revision Date: 15th November 2004201 Metafunctions 4.10 Miscellaneous
typedef inherit n<t1,t2, ...tn>::type r;
Return type: A class type.
Precondition: t1,t2,...tnare complete types.
Semantics: Equivalent to
struct r
: inherit2<
inherit n-1<t1,t2, ...tn-1>::type
, tn
>
{
};
typedef inherit<t1,t2, ...tn>::type r;
Precondition: t1,t2,...tnare complete types.
Return type: A class type.
Semantics: Equivalent to
typedef inherit n<t1,t2, ...tn>::type r;
Complexity
Amortized constant time.
Example
struct udt1 { int n; };
struct udt2 {};
typedef inherit<udt1,udt2>::type r1;
typedef inherit<empty_base,udt1>::type r2;
typedef inherit<empty_base,udt1,empty_base,empty_base>::type r3;
typedef inherit<udt1,empty_base,udt2>::type r4;
typedef inherit<empty_base,empty_base>::type r5;
BOOST_MPL_ASSERT(( is_base_and_derived< udt1, r1> ));
BOOST_MPL_ASSERT(( is_base_and_derived< udt2, r1> ));
BOOST_MPL_ASSERT(( is_same< r2, udt1> ));
BOOST_MPL_ASSERT(( is_same< r3, udt1 > ));
BOOST_MPL_ASSERT(( is_base_and_derived< udt1, r4 > ));
BOOST_MPL_ASSERT(( is_base_and_derived< udt2, r4 > ));
BOOST_MPL_ASSERT(( is_same< r5, empty_base > ));
See also
Metafunctions ,empty_base ,inherit_linearly ,identity
Revision Date: 15th November 20044.10 Miscellaneous Metafunctions 202
4.10.4 inherit_linearly
Synopsis
template<
typename Types
, typename Node
, typename Root = empty_base
>
struct inherit_linearly
: fold<Types,Root,Node>
{
};
Description
A convenience wrapper for foldto use in the context of sequence-driven class composition. Returns the result the
successive application of binary Nodeto the result of the previous Nodeinvocation ( Rootif it’s the ﬁrst call) and every
type in the Forward Sequence Typesin order.
Header
#include <boost/mpl/inherit_linearly.hpp>
Model of
Metafunction
Parameters
Parameter Requirement Description
Types Forward Sequence Types to inherit from.
Node BinaryLambda Expression A derivation metafunction.
Root A class type A type to be placed at the rootof the class hierarchy.
Expression semantics
For anyForward Sequence types, binaryLambda Expression node, and arbitrary class type root:
typedef inherit_linearly<types,node,root>::type r;
Return type: A class type.
Semantics: Equivalent to
typedef fold<types,root,node>::type r;
Complexity
Linear. Exactly size<types>::value applications of node.
Revision Date: 15th November 2004203 Metafunctions 4.10 Miscellaneous
Example
template< typename T > struct tuple_field
{
T field;
};
template< typename T >
inline
T& field(tuple_field<T>& t)
{
return t.field;
}
typedef inherit_linearly<
vector<int,char const*,bool>
, inherit< _1, tuple_field<_2> >
>::type tuple;
int main()
{
tuple t;
field<int>(t) = -1;
field<char const*>(t) = "text";
field<bool>(t) = false;
std::cout
<< field<int>(t) << ’n’
<< field<char const*>(t) << ’n’
<< field<bool>(t) << ’n’
;
}
See also
Metafunctions ,Algorithms ,inherit,empty_base ,fold,reverse_fold
4.10.5 numeric_cast
Synopsis
template<
typename SourceTag
, typename TargetTag
>
struct numeric_cast;
Description
Each numeric_cast specializationisauser-specializedunary MetafunctionClass providingaconversionbetweentwo
numeric types.
Revision Date: 15th November 20044.10 Miscellaneous Metafunctions 204
Header
#include <boost/mpl/numeric_cast.hpp>
Parameters
Parameter Requirement Description
SourceTag Integral Constant A tag for the conversion’s source type.
TargetTag Integral Constant A tag for the conversion’s destination type.
Expression semantics
Ifxandyare two numeric types, xis convertible to y, and x_tagandy_tagare the types’ corresponding Integral
Constant tags:
typedef apply_wrap2< numeric_cast<x_tag,y_tag>,x >::type r;
Return type: A type.
Semantics: ris a value of xconverted to the type of y.
Complexity
Unspeciﬁed.
Example
struct complex_tag : int_<10> {};
template< typename Re, typename Im > struct complex
{
typedef complex_tag tag;
typedef complex type;
typedef Re real;
typedef Im imag;
};
template< typename C > struct real : C::real {};
template< typename C > struct imag : C::imag {};
namespace boost { namespace mpl {
template<> struct numeric_cast< integral_c_tag,complex_tag >
{
template< typename N > struct apply
: complex< N, integral_c< typename N::value_type, 0 > >
{
};
};
template<>
struct plus_impl< complex_tag,complex_tag >
Revision Date: 15th November 2004205 Metafunctions 4.10 Miscellaneous
{
template< typename N1, typename N2 > struct apply
: complex<
plus< typename N1::real, typename N2::real >
, plus< typename N1::imag, typename N2::imag >
>
{
};
};
}}
typedef int_<2> i;
typedef complex< int_<5>, int_<-1> > c1;
typedef complex< int_<-5>, int_<1> > c2;
typedef plus<c1,i> r4;
BOOST_MPL_ASSERT_RELATION( real<r4>::value, ==, 7 );
BOOST_MPL_ASSERT_RELATION( imag<r4>::value, ==, -1 );
typedef plus<i,c2> r5;
BOOST_MPL_ASSERT_RELATION( real<r5>::value, ==, -3 );
BOOST_MPL_ASSERT_RELATION( imag<r5>::value, ==, 1 );
See also
Metafunctions ,Numeric Metafunction ,plus,minus,times
4.10.6 min
Synopsis
template<
typename N1
, typename N2
>
struct min
{
typedef unspecified type;
};
Description
Returns the smaller of its two arguments.
Header
#include <boost/mpl/min_max.hpp>
Model of
Metafunction
Revision Date: 15th November 20044.10 Miscellaneous Metafunctions 206
Parameters
Parameter Requirement Description
N1,N2 Any type Types to compare.
Expression semantics
For arbitrary types xandy:
typedef min<x,y>::type r;
Return type: A type.
Precondition: less<x,y>::value is a well-formed integral constant expression.
Semantics: Equivalent to
typedef if_< less<x,y>,x,y >::type r;
Complexity
Constant time.
Example
typedef fold<
vector_c<int,1,7,0,-2,5,-1>
, int_<-10>
, min<_1,_2>
>::type r;
BOOST_MPL_ASSERT(( is_same< r, int_<-10> > ));
See also
Metafunctions ,comparison ,max,less,min_element
4.10.7 max
Synopsis
template<
typename N1
, typename N2
>
struct max
{
typedef unspecified type;
};
Description
Returns the larger of its twoarguments.
Revision Date: 15th November 2004207 Metafunctions 4.10 Miscellaneous
Header
#include <boost/mpl/min_max.hpp>
Model of
Metafunction
Parameters
Parameter Requirement Description
N1,N2 Any type Types to compare.
Expression semantics
For arbitrary types xandy:
typedef max<x,y>::type r;
Return type: A type.
Precondition: less<x,y>::value is a well-formed integral constant expression.
Semantics: Equivalent to
typedef if_< less<x,y>,y,x >::type r;
Complexity
Constant time.
Example
typedef fold<
vector_c<int,1,7,0,-2,5,-1>
, int_<10>
, max<_1,_2>
>::type r;
BOOST_MPL_ASSERT(( is_same< r, int_<10> > ));
See also
Metafunctions ,comparison ,min,less,max_element
4.10.8 sizeof_
Synopsis
template<
typename X
>
struct sizeof_
Revision Date: 15th November 20044.10 Miscellaneous Metafunctions 208
{
typedef unspecified type;
};
Description
Returns the result of a sizeof(X) expression wrapped into an Integral Constant of the corresponding type,
std::size_t .
Header
#include <boost/mpl/sizeof.hpp>
Model of
Metafunction
Parameters
Parameter Requirement Description
X Any type A type to compute the sizeoffor.
Expression semantics
For an arbitrary type x:
typedef sizeof_<x>::type n;
Return type: Integral Constant .
Precondition: xis a complete type.
Semantics: Equivalent to
typedef size_t< sizeof(x) > n;
Complexity
Constant time.
Example
struct udt { char a[100]; };
BOOST_MPL_ASSERT_RELATION( sizeof_<char>::value, ==, sizeof(char) );
BOOST_MPL_ASSERT_RELATION( sizeof_<int>::value, ==, sizeof(int) );
BOOST_MPL_ASSERT_RELATION( sizeof_<double>::value, ==, sizeof(double) );
BOOST_MPL_ASSERT_RELATION( sizeof_<udt>::value, ==, sizeof(my) );
See also
Metafunctions ,Integral Constant ,size_t
Revision Date: 15th November 2004Chapter 5 Data Types
5.1 Concepts
5.1.1 Integral Constant
Description
AnIntegral Constant is a holder class for a compile-time value of an integral type. Every Integral Constant is also a
nullaryMetafunction ,returningitself. Anintegralconstant objectisimplicitlyconvertibletothecorrespondingrun-time
value of the wrapped integraltype.
Expression requirements
In the following table and subsequent speciﬁcations, nis a model of Integral Constant .
Expression Type Complexity
n::value_type An integral type Constant time.
n::value An integral constant expression Constant time.
n::type Integral Constant Constant time.
next<n>::type Integral Constant Constant time.
prior<n>::type Integral Constant Constant time.
n::value_type const c = n() Constant time.
Expression semantics
Expression Semantics
n::value_type A cv-unqualiﬁed type of n::value .
n::value The value of the wrapped integral constant.
n::type is_same<n::type,n>::value == true .
next<n>::type AnIntegral Constant cof type n::value_type such that
c::value == n::value + 1 .
prior<n>::type AnIntegral Constant cof type n::value_type such that
c::value == n::value - 1 .
n::value_type const c = n() c == n::value .
Models
—bool_
—int_5.2 Numeric Data Types 210
—long_
—integral_c
See also
Data Types ,Integral Sequence Wrapper ,integral_c
5.2 Numeric
5.2.1 bool_
Synopsis
template<
bool C
>
struct bool_
{
//unspecified
// ...
};
typedef bool_<true> true_;
typedef bool_<false> false_;
Description
A boolean Integral Constant wrapper.
Header
#include <boost/mpl/bool.hpp>
Model of
Integral Constant
Parameters
Parameter Requirement Description
C A boolean integral constant A value to wrap.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Integral Constant .
For arbitrary integral constant c:
Expression Semantics
bool_<c> AnIntegralConstant xsuchthat x::value == c andx::value_type isidentical
tobool.
Revision Date: 15th November 2004211 Data Types 5.2 Numeric
Example
BOOST_MPL_ASSERT(( is_same< bool_<true>::value_type, bool > ));
BOOST_MPL_ASSERT(( is_same< bool_<true>, true_ > )); }
BOOST_MPL_ASSERT(( is_same< bool_<true>::type, bool_<true> > ));
BOOST_MPL_ASSERT_RELATION( bool_<true>::value, ==, true );
assert( bool_<true>() == true );
See also
Data Types ,Integral Constant ,int_,long_,integral_c
5.2.2 int_
Synopsis
template<
int N
>
struct int_
{
//unspecified
// ...
};
Description
AnIntegral Constant wrapper for int.
Header
#include <boost/mpl/int.hpp>
Model of
Integral Constant
Parameters
Parameter Requirement Description
N An integral constant A value to wrap.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Integral Constant .
For arbitrary integral constant n:
Expression Semantics
int_<c> AnIntegralConstant xsuchthat x::value == c andx::value_type isidentical
toint.
Revision Date: 15th November 20045.2 Numeric Data Types 212
Example
typedef int_<8> eight;
BOOST_MPL_ASSERT(( is_same< eight::value_type, int > ));
BOOST_MPL_ASSERT(( is_same< eight::type, eight > ));
BOOST_MPL_ASSERT(( is_same< next< eight >::type, int_<9> > ));
BOOST_MPL_ASSERT(( is_same< prior< eight >::type, int_<7> > ));
BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 );
assert( eight() == 8 );
See also
Data Types ,Integral Constant ,long_,size_t,integral_c
5.2.3 long_
Synopsis
template<
long N
>
struct long_
{
//unspecified
// ...
};
Description
AnIntegral Constant wrapper for long.
Header
#include <boost/mpl/long.hpp>
Model of
Integral Constant
Parameters
Parameter Requirement Description
N An integral constant A value to wrap.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Integral Constant .
For arbitrary integral constant n:
Revision Date: 15th November 2004213 Data Types 5.2 Numeric
Expression Semantics
long_<c> AnIntegralConstant xsuchthat x::value == c andx::value_type isidentical
tolong.
Example
typedef long_<8> eight;
BOOST_MPL_ASSERT(( is_same< eight::value_type, long > ));
BOOST_MPL_ASSERT(( is_same< eight::type, eight > ));
BOOST_MPL_ASSERT(( is_same< next< eight >::type, long_<9> > ));
BOOST_MPL_ASSERT(( is_same< prior< eight >::type, long_<7> > ));
BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 );
assert( eight() == 8 );
See also
Data Types ,Integral Constant ,int_,size_t,integral_c
5.2.4 size_t
Synopsis
template<
std::size_t N
>
struct size_t
{
//unspecified
// ...
};
Description
AnIntegral Constant wrapper for std::size_t .
Header
#include <boost/mpl/size_t.hpp>
Model of
Integral Constant
Parameters
Parameter Requirement Description
N An integral constant A value to wrap.
Revision Date: 15th November 20045.2 Numeric Data Types 214
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Integral Constant .
For arbitrary integral constant n:
Expression Semantics
size_t<c> AnIntegralConstant xsuchthat x::value == c andx::value_type isidentical
tostd::size_t .
Example
typedef size_t<8> eight;
BOOST_MPL_ASSERT(( is_same< eight::value_type, std::size_t > ));
BOOST_MPL_ASSERT(( is_same< eight::type, eight > ));
BOOST_MPL_ASSERT(( is_same< next< eight >::type, size_t<9> > ));
BOOST_MPL_ASSERT(( is_same< prior< eight >::type, size_t<7> > ));
BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 );
assert( eight() == 8 );
See also
Data Types ,Integral Constant ,int_,long_,integral_c
5.2.5 integral_c
Synopsis
template<
typename T, T N
>
struct integral_c
{
//unspecified
// ...
};
Description
A generic Integral Constant wrapper.
Header
#include <boost/mpl/integral_c.hpp>
Model of
Integral Constant
Revision Date: 15th November 2004215 Data Types 5.2 Numeric
Parameters
Revision Date: 15th November 20045.3 Miscellaneous Data Types 216
Parameter Requirement Description
T An integral type Wrapper’s value type.
N An integral constant A value to wrap.
Expression semantics
The semantics of an expression are deﬁned only where they differ from, or are not deﬁnedin Integral Constant .
For arbitrary integral type tand integral constant n:
Expression Semantics
integral_c<t,c> AnIntegralConstant xsuchthat x::value == c andx::value_type isiden-
tical to t.
Example
typedef integral_c<short,8> eight;
BOOST_MPL_ASSERT(( is_same< eight::value_type, short > ));
BOOST_MPL_ASSERT(( is_same< eight::type, eight > ));
BOOST_MPL_ASSERT(( is_same< next< eight >::type, integral_c<short,9> > ));
BOOST_MPL_ASSERT(( is_same< prior< eight >::type, integral_c<short,7> > ));
BOOST_MPL_ASSERT_RELATION( (eight::value), ==, 8 );
assert( eight() == 8 );
See also
Data Types ,Integral Constant ,bool_,int_,long_,size_t
5.3 Miscellaneous
5.3.1 pair
Synopsis
template<
typename T1
, typename T2
>
struct pair
{
typedef pair type;
typedef T1 first;
typedef T2 second;
};
Description
A transparent holder for two arbitrary types.
Revision Date: 15th November 2004217 Data Types 5.3 Miscellaneous
Header
#include <boost/mpl/pair.hpp>
Example
Count a number of elements in the sequence together with a number of negative elements among these.
typedef fold<
vector_c<int,-1,0,5,-7,-2,4,5,7>
, pair< int_<0>, int_<0> >
, pair<
next< first<_1> >
, if_<
less< _2, int_<0> >
, next< second<_1> >
, second<_1>
>
>
>::type p;
BOOST_MPL_ASSERT_RELATION( p::first::value, ==, 8 );
BOOST_MPL_ASSERT_RELATION( p::second::value, ==, 3 );
See also
Data Types ,Sequences ,first,second
5.3.2 empty_base
Synopsis
struct empty_base {};
Description
An empty base class. Inheritance from empty_base through the inherit metafunction is a no-op.
Header
#include <boost/mpl/empty_base.hpp>
See also
Data Types ,inherit,inherit_linearly ,void_
Revision Date: 15th November 20045.3 Miscellaneous Data Types 218
5.3.3 void_
Synopsis
struct void_
{
typedef void_ type;
};
template< typename T > struct is_void;
Description
void_is a generic type placeholder representing “nothing”.
Header
#include <boost/mpl/void.hpp>
See also
Data Types ,pair,empty_base ,bool_,int_,integral_c
Revision Date: 15th November 2004Chapter 6 Macros
Being atemplatemetaprogramming framework, the MPL concentrates on getting one thing done well and leaves most
of the clearly preprocessor-related tasks to the corresponding specialized libraries [ PRE], [Ve03]. But whether we
like it or not, macros play an important role on today’s C++ metaprogramming, and some of the useful MPL-level
functionalitycannotbeimplementedwithoutleakingitspreprocessor-dependentimplementationnatureintothelibrary’s
public interface.
6.1 Asserts
The MPL supplies a suite of static assertion macros that are speciﬁcally designed to generate maximally useful and
informative error messageswithin the diagnostic capabilities of each compiler.
All assert macros can be used at class, function, or namespace scope.
6.1.1 BOOST_MPL_ASSERT
Synopsis
#define BOOST_MPL_ASSERT( pred ) \
unspecified token sequence \
/**/
Description
Generates a compilation error when the predicate predholds false.
Header
#include <boost/mpl/assert.hpp>
Parameters
Parameter Requirement Description
pred Boolean nullary Metafunction A predicate to be asserted.
Expression semantics
For any boolean nullary Metafunction pred:
BOOST_MPL_ASSERT(( pred ));
Return type: None.6.1 Asserts Macros 220
Semantics: Generates a compilation error if pred::type::value != true , otherwise has no effect.
Note that double parentheses are required even if no commas appear in the condition.
When possible within the compiler’s diagnostic capabilities, the error message will include the predi-
cate’s full type name, and have ageneral form of:
... ************ pred::************ ...
Example
template< typename T, typename U > struct my
{
// ...
BOOST_MPL_ASSERT(( is_same< T,U > ));
};
my<void*,char*> test;
// In instantiation of ‘my<void, char*>’:
// instantiated from here
// conversion from ‘
// mpl_::failed************boost::is_same<void, char*>::************’ to
// non-scalar type ‘mpl_::assert<false>’ requested
See also
Asserts,BOOST_MPL_ASSERT_NOT ,BOOST_MPL_ASSERT_MSG ,BOOST_MPL_ASSERT_RELATION
6.1.2 BOOST_MPL_ASSERT_MSG
Synopsis
#define BOOST_MPL_ASSERT_MSG( condition, message, types ) \
unspecified token sequence \
/**/
Description
Generates a compilation error with an embedded custom message when the conditiondoesn’t hold.
Header
#include <boost/mpl/assert.hpp>
Parameters
Parameter Requirement Description
condition An integral constant expression A condition to be asserted.
message A legal identiﬁer token A custom message in a form of a legal C++ identiﬁer
token.
Revision Date: 15th November 2004221 Macros 6.1 Asserts
Parameter Requirement Description
types A legal function parameter list Aparenthizedlistoftypestobedisplayedintheerror
message.
Expression semantics
For any integral constant expression expr, legal C++ identiﬁer message, and arbitrary types t1,t2,...tn:
BOOST_MPL_ASSERT_MSG( expr, message, (t1, t2,... tn) );
Return type: None.
Precondition: t1,t2,...tnare non- void.
Semantics: Generates a compilation error if expr::value != true , otherwise has no effect.
When possible within the compiler’s diagnostic capabilities, the error message will include the mes-
sageidentiﬁer and the parenthized list of t1,t2,...tntypes, and have a general formof:
... ************( ...::message )************)(t1, t2,... tn) ...
BOOST_MPL_ASSERT_MSG( expr, message, (types<t1, t2,... tn>) );
Return type: None.
Precondition: None.
Semantics: Generates a compilation error if expr::value != true , otherwise has no effect.
Whenpossiblewithinthecompiler’sdiagnosticscapabilities,theerrormessagewillincludethe mes-
sageidentiﬁer and the list of t1,t2,...tntypes, and have a general formof:
... ************( ...::message )************)(types<t1, t2,... tn>) ...
Example
template< typename T > struct my
{
// ...
BOOST_MPL_ASSERT_MSG(
is_integral<T>::value
, NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED
, (T)
);
};
my<void*> test;
// In instantiation of ‘my<void*>’:
// instantiated from here
// conversion from ‘
// mpl_::failed************(my<void*>::
// NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED::************)(void*)
// ’ to non-scalar type ‘mpl_::assert<false>’ requested
See also
Asserts,BOOST_MPL_ASSERT ,BOOST_MPL_ASSERT_NOT ,BOOST_MPL_ASSERT_RELATION
Revision Date: 15th November 20046.1 Asserts Macros 222
6.1.3 BOOST_MPL_ASSERT_NOT
Synopsis
#define BOOST_MPL_ASSERT_NOT( pred ) \
unspecified token sequence \
/**/
Description
Generates a compilation error when predicate holds true.
Header
#include <boost/mpl/assert.hpp>
Parameters
Parameter Requirement Description
pred Boolean nullary Metafunction A predicate to be asserted to be false.
Expression semantics
For any boolean nullary Metafunction pred:
BOOST_MPL_ASSERT_NOT(( pred ));
Return type: None.
Semantics: Generates a compilation error if pred::type::value != false , otherwise has no effect.
Note that double parentheses are required even if no commas appear in the condition.
When possible within the compiler’s diagnostic capabilities, the error message will include the predi-
cate’s full type name, and have ageneral form of:
... ************boost::mpl::not_< pred >::************ ...
Example
template< typename T, typename U > struct my
{
// ...
BOOST_MPL_ASSERT_NOT(( is_same< T,U > ));
};
my<void,void> test;
// In instantiation of ‘my<void, void>’:
// instantiated from here
// conversion from ‘
// mpl_::failed************boost::mpl::not_<boost::is_same<void, void>
// >::************’ to non-scalar type ‘mpl_::assert<false>’ requested
Revision Date: 15th November 2004223 Macros 6.1 Asserts
See also
Asserts,BOOST_MPL_ASSERT ,BOOST_MPL_ASSERT_MSG ,BOOST_MPL_ASSERT_RELATION
6.1.4 BOOST_MPL_ASSERT_RELATION
Synopsis
#define BOOST_MPL_ASSERT_RELATION( x, relation, y ) \
unspecified token sequence \
/**/
Description
A specialized assertion macro for checking numerical conditions. Generates a compilation error when the condition (
x relation y ) doesn’t hold.
Header
#include <boost/mpl/assert.hpp>
Parameters
Parameter Requirement Description
x An integral constant Left operand of the checked relation.
y An integral constant Right operand of the checked relation.
relation A C++ operator token An operator token for the relation being checked.
Expression semantics
For any integral constants x,yand a legal C++ operator token op:
BOOST_MPL_ASSERT_RELATION( x, op, y );
Return type: None.
Semantics: Generates a compilation error if ( x op y ) != true , otherwise has no effect.
Whenpossiblewithinthecompiler’sdiagnosticcapabilities,theerrormessagewillincludeanameof
the relation being checked, the actual values of both operands, and have a general form of:
... ************ ...assert_relation<op, x, y>::************) ...
Example
template< typename T, typename U > struct my
{
// ...
BOOST_MPL_ASSERT_RELATION( sizeof(T), <, sizeof(U) );
};
my<char[50],char[10]> test;
Revision Date: 15th November 20046.2 Introspection Macros 224
// In instantiation of ‘my<char[50], char[10]>’:
// instantiated from here
// conversion from ‘
// mpl_::failed************mpl_::assert_relation<less, 50, 10>::************’
// to non-scalar type ‘mpl_::assert<false>’ requested
See also
Asserts,BOOST_MPL_ASSERT ,BOOST_MPL_ASSERT_NOT ,BOOST_MPL_ASSERT_MSG
6.2 Introspection
6.2.1 BOOST_MPL_HAS_XXX_TRAIT_DEF
Synopsis
#define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \
unspecified token sequence \
/**/
Description
Expands into a deﬁnition of a boolean unary Metafunction has_name such that for any type x has_name<x>::value
== true if and only if xis a class type and has a nested type memeber x::name.
On the deﬁcient compilers not capabale of performing the detection, has_name<x>::value always returns false. A
boolean conﬁguraion macro, BOOST_MPL_CFG_NO_HAS_XXX , is provided to signal or override the “deﬁcient” status of
a particular compiler.
[Note: BOOST_MPL_HAS_XXX_TRAIT_DEF is a simpliﬁed front end to the BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
introspection macro — end note]
Header
#include <boost/mpl/has_xxx.hpp>
Parameters
Parameter Requirement Description
name A legal identiﬁer token A name of the member being detected.
Expression semantics
For any legal C++ identiﬁer name:
BOOST_MPL_HAS_XXX_TRAIT_DEF(name)
Precondition: Appears at namespace scope.
Return type: None.
Semantics: Equivalent to
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(
BOOST_PP_CAT(has_,name), name, false
Revision Date: 15th November 2004225 Macros 6.2 Introspection
)
Example
BOOST_MPL_HAS_XXX_TRAIT_DEF(has_xxx)
struct test1 {};
struct test2 { void xxx(); };
struct test3 { int xxx; };
struct test4 { static int xxx(); };
struct test5 { template< typename T > struct xxx {}; };
struct test6 { typedef int xxx; };
struct test7 { struct xxx; };
struct test8 { typedef void (*xxx)(); };
struct test9 { typedef void (xxx)(); };
BOOST_MPL_ASSERT_NOT(( has_xxx<test1> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test2> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test3> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test4> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test5> ));
#if !defined(BOOST_MPL_CFG_NO_HAS_XXX)
BOOST_MPL_ASSERT(( has_xxx<test6> ));
BOOST_MPL_ASSERT(( has_xxx<test7> ));
BOOST_MPL_ASSERT(( has_xxx<test8> ));
BOOST_MPL_ASSERT(( has_xxx<test9> ));
#endif
BOOST_MPL_ASSERT(( has_xxx<test6,true_> ));
BOOST_MPL_ASSERT(( has_xxx<test7,true_> ));
BOOST_MPL_ASSERT(( has_xxx<test8,true_> ));
BOOST_MPL_ASSERT(( has_xxx<test9,true_> ));
See also
Macros,BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF ,BOOST_MPL_CFG_NO_HAS_XXX
6.2.2 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
Synopsis
#define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \
unspecified token sequence \
/**/
Description
Expandsintoadeﬁnitionofabooleanunary Metafunction traitsuchthatforanytype x trait<x>::value == true
if and only if xis a class type and has a nested type memeber x::name.
Revision Date: 15th November 20046.2 Introspection Macros 226
On the deﬁcient compilers not capabale of performing the detection, trait<x>::value always returns a fallback
value default_ . A boolean conﬁguraion macro, BOOST_MPL_CFG_NO_HAS_XXX , is provided to signal or override the
“deﬁcient”statusofaparticularcompiler. [ Note:Thefallbackvaluecallalsobeprovidedatthepointofthemetafunction
invocation; see the Expression semantics section for details — end note]
Header
#include <boost/mpl/has_xxx.hpp>
Parameters
Parameter Requirement Description
trait A legal identiﬁer token A name of the metafunction to be generated.
name A legal identiﬁer token A name of the member being detected.
default_ An boolean constant A fallback value for the deﬁcient compilers.
Expression semantics
For any legal C++ identiﬁers traitandname, boolean constant expression c1, boolean Integral Constant c2, and
arbitrary type x:
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, c1)
Precondition: Appears at namespace scope.
Return type: None.
Semantics: Expands into an equivalent ofthe following class template deﬁnition
template< typename X, typename fallback = boost::mpl::bool_<c1> >
struct trait
{
//unspecified
// ...
};
where traitis a boolean Metafunction with the following semantics:
typedef trait<x>::type r;
Return type: Integral Constant .
Semantics: IfBOOST_MPL_CFG_NO_HAS_XXX is deﬁned, r::value == c1 ; otherwise,
r::value == true if and only if xis a class type that has a nested type memeber
x::name.
typedef trait< x,c2 >::type r;
Return type: Integral Constant .
Semantics: IfBOOST_MPL_CFG_NO_HAS_XXX is deﬁned, r::value == c2::value ; oth-
erwise, equivalent to
typedef trait<x>::type r;
Revision Date: 15th November 2004227 Macros 6.3 Conﬁguration
Example
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_xxx, xxx, false)
struct test1 {};
struct test2 { void xxx(); };
struct test3 { int xxx; };
struct test4 { static int xxx(); };
struct test5 { template< typename T > struct xxx {}; };
struct test6 { typedef int xxx; };
struct test7 { struct xxx; };
struct test8 { typedef void (*xxx)(); };
struct test9 { typedef void (xxx)(); };
BOOST_MPL_ASSERT_NOT(( has_xxx<test1> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test2> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test3> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test4> ));
BOOST_MPL_ASSERT_NOT(( has_xxx<test5> ));
#if !defined(BOOST_MPL_CFG_NO_HAS_XXX)
BOOST_MPL_ASSERT(( has_xxx<test6> ));
BOOST_MPL_ASSERT(( has_xxx<test7> ));
BOOST_MPL_ASSERT(( has_xxx<test8> ));
BOOST_MPL_ASSERT(( has_xxx<test9> ));
#endif
BOOST_MPL_ASSERT(( has_xxx<test6,true_> ));
BOOST_MPL_ASSERT(( has_xxx<test7,true_> ));
BOOST_MPL_ASSERT(( has_xxx<test8,true_> ));
BOOST_MPL_ASSERT(( has_xxx<test9,true_> ));
See also
Macros,BOOST_MPL_HAS_XXX_TRAIT_DEF ,BOOST_MPL_CFG_NO_HAS_XXX
6.3 Conﬁguration
6.3.1 BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
Synopsis
// #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
Description
BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS is an boolean conﬁguration macro regulating library’s internal use of
preprocessed headers. When deﬁned, it instructs the MPL to discard the pre-generated headers found in boost/m-
pl/aux_/preprocessed directory and use preprocessor metaprogramming techniques to generate the necessary ver-
sions of the library components on the ﬂy.
In this implementation of the library, the macro is not deﬁned by default. To change the default conﬁguration, deﬁne
BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS before including any library header.
Revision Date: 15th November 20046.3 Conﬁguration Macros 228
See also
Macros,Conﬁguration
6.3.2 BOOST_MPL_CFG_NO_HAS_XXX
Synopsis
// #define BOOST_MPL_CFG_NO_HAS_XXX
Description
BOOST_MPL_CFG_NO_HAS_XXX isanbooleanconﬁgurationmacrosignalingavailabilityofthe BOOST_MPL_HAS_XXX_-
TRAIT_DEF /BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF introspection macros’ functionality on a particular compiler.
See also
Macros,Conﬁguration ,BOOST_MPL_HAS_XXX_TRAIT_DEF ,BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
6.3.3 BOOST_MPL_LIMIT_METAFUNCTION_ARITY
Synopsis
#if !defined(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)
# define BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
implementation-defined integral constant \
/**/
#endif
Description
BOOST_MPL_LIMIT_METAFUNCTION_ARITY is an overridable conﬁguration macro regulating the maximum supported
arity ofmetafunctions andmetafunctionclasses . In this implementation ofthe library, BOOST_MPL_LIMIT_METAFUNC-
TION_ARITY has a default value of 5. To override the default limit, deﬁne BOOST_MPL_LIMIT_METAFUNCTION_ARITY
tothedesiredmaximumaritybeforeincludinganylibraryheader. [ Note:Overridingwilltakeeffect onlyifthelibraryis
conﬁgurednottouse preprocessedheaders . See BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS formoreinformation.
—end note]
Example
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_METAFUNCTION_ARITY 2
#include <boost/mpl/apply.hpp>
using namespace boost::mpl;
template< typename T1, typename T2 > struct second
{
typedef T2 type;
};
template< typename T1, typename T2, typename T3 > struct third
Revision Date: 15th November 2004229 Macros 6.3 Conﬁguration
{
typedef T3 type;
};
typedef apply< second<_1,_2_>,int,long >::type r1;
// typedef apply< third<_1,_2_,_3>,int,long,float >::type r2; // error!
See also
Macros,Conﬁguration ,BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
6.3.4 BOOST_MPL_LIMIT_VECTOR_SIZE
Synopsis
#if !defined(BOOST_MPL_LIMIT_VECTOR_SIZE)
# define BOOST_MPL_LIMIT_VECTOR_SIZE \
implementation-defined integral constant \
/**/
#endif
Description
BOOST_MPL_LIMIT_VECTOR_SIZE isanoverridableconﬁgurationmacroregulatingthemaximumarityofthe vector’s
andvector_c ’svariadic forms . In this implementation of the library, BOOST_MPL_LIMIT_VECTOR_SIZE has a default
value of 20. To override the default limit, deﬁne BOOST_MPL_LIMIT_VECTOR_SIZE to the desired maximum arity
rounded up to the nearest multiple of ten before including any library header. [ Note:Overriding will take effect onlyif
thelibraryisconﬁgurednottouse preprocessedheaders . See BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS formore
information. — end note]
Example
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_VECTOR_SIZE 10
#include <boost/mpl/vector.hpp>
using namespace boost::mpl;
typedef vector_c<int,1> v_1;
typedef vector_c<int,1,2,3,4,5,6,7,8,9,10> v_10;
// typedef vector_c<int,1,2,3,4,5,6,7,8,9,10,11> v_11; // error!
See also
Conﬁguration ,BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS ,BOOST_MPL_LIMIT_LIST_SIZE
6.3.5 BOOST_MPL_LIMIT_LIST_SIZE
Synopsis
#if !defined(BOOST_MPL_LIMIT_LIST_SIZE)
Revision Date: 15th November 20046.3 Conﬁguration Macros 230
# define BOOST_MPL_LIMIT_LIST_SIZE \
implementation-defined integral constant \
/**/
#endif
Description
BOOST_MPL_LIMIT_LIST_SIZE isanoverridableconﬁgurationmacroregulatingthemaximumarityofthe list’sand
list_c’svariadic forms . In this implementation of the library, BOOST_MPL_LIMIT_LIST_SIZE has a default value of
20. To override the default limit, deﬁne BOOST_MPL_LIMIT_LIST_SIZE to the desired maximum arity rounded up to
the nearest multiple of ten before including any library header. [ Note:Overriding will take effect onlyif the library is
conﬁgurednottouse preprocessedheaders . See BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS formoreinformation.
—end note]
Example
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_LIST_SIZE 10
#include <boost/mpl/list.hpp>
using namespace boost::mpl;
typedef list_c<int,1> l_1;
typedef list_c<int,1,2,3,4,5,6,7,8,9,10> l_10;
// typedef list_c<int,1,2,3,4,5,6,7,8,9,10,11> l_11; // error!
See also
Conﬁguration ,BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS ,BOOST_MPL_LIMIT_VECTOR_SIZE
6.3.6 BOOST_MPL_LIMIT_SET_SIZE
Synopsis
#if !defined(BOOST_MPL_LIMIT_SET_SIZE)
# define BOOST_MPL_LIMIT_SET_SIZE \
implementation-defined integral constant \
/**/
#endif
Description
BOOST_MPL_LIMIT_SET_SIZE is an overridable conﬁguration macro regulating the maximum arity of the set’s and
set_c’svariadic forms . In this implementation of the library, BOOST_MPL_LIMIT_SET_SIZE has a default value of
20. To override the default limit, deﬁne BOOST_MPL_LIMIT_SET_SIZE to the desired maximum arity rounded up to
the nearest multiple of ten before including any library header. [ Note:Overriding will take effect onlyif the library is
conﬁgurednottouse preprocessedheaders . See BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS formoreinformation.
—end note]
Revision Date: 15th November 2004231 Macros 6.3 Conﬁguration
Example
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_SET_SIZE 10
#include <boost/mpl/set.hpp>
using namespace boost::mpl;
typedef set_c<int,1> s_1;
typedef set_c<int,1,2,3,4,5,6,7,8,9,10> s_10;
// typedef set_c<int,1,2,3,4,5,6,7,8,9,10,11> s_11; // error!
See also
Conﬁguration ,BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS ,BOOST_MPL_LIMIT_MAP_SIZE
6.3.7 BOOST_MPL_LIMIT_MAP_SIZE
Synopsis
#if !defined(BOOST_MPL_LIMIT_MAP_SIZE)
# define BOOST_MPL_LIMIT_MAP_SIZE \
implementation-defined integral constant \
/**/
#endif
Description
BOOST_MPL_LIMIT_MAP_SIZE isanoverridableconﬁgurationmacroregulatingthemaximumarityofthe map’svariadic
form. In this implementation of the library, BOOST_MPL_LIMIT_MAP_SIZE has a default value of 20. To override the
defaultlimit,deﬁne BOOST_MPL_LIMIT_MAP_SIZE tothedesiredmaximumarityroundeduptothenearestmultipleof
ten before including any library header. [ Note:Overriding will take effect onlyif the library is conﬁgured not to use
preprocessed headers . See BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS for more information. — end note]
Example
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_MAP_SIZE 10
#include <boost/mpl/map.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/int.hpp>
using namespace boost::mpl;
template< int i > struct ints : pair< int_<i>,int_<i> > {};
typedef map< ints<1> > m_1;
typedef map< ints<1>, ints<2>, ints<3>, ints<4>, ints<5>
ints<6>, ints<7>, ints<8>, ints<9>, ints<10> > m_10;
// typedef map< ints<1>, ints<2>, ints<3>, ints<4>, ints<5>
// ints<6>, ints<7>, ints<8>, ints<9>, ints<10>, ints<11> > m_11; // error!
Revision Date: 15th November 20046.4 Broken Compiler Workarounds Macros 232
See also
Conﬁguration ,BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS ,BOOST_MPL_LIMIT_SET_SIZE
6.3.8 BOOST_MPL_LIMIT_UNROLLING
Synopsis
#if !defined(BOOST_MPL_LIMIT_UNROLLING)
# define BOOST_MPL_LIMIT_UNROLLING \
implementation-defined integral constant \
/**/
#endif
Description
BOOST_MPL_LIMIT_UNROLLING is an overridable conﬁguration macro regulating the unrolling depth of the library’s
iteration algorithms. In this implementation of the library, BOOST_MPL_LIMIT_UNROLLING has a default value of 4. To
override the default, deﬁne BOOST_MPL_LIMIT_UNROLLING to the desired value before including any library header.
[Note:Overriding will take effect onlyif the library is conﬁgured not to use preprocessed headers . See BOOST_MPL_-
CFG_NO_PREPROCESSED_HEADERS for more information. — end note]
Example
Except for overall library performace, overriding the BOOST_MPL_LIMIT_UNROLLING ’s default value has no user-
observable effects.
See also
Conﬁguration ,BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
6.4 Broken Compiler Workarounds
6.4.1 BOOST_MPL_AUX_LAMBDA_SUPPORT
Synopsis
#define BOOST_MPL_AUX_LAMBDA_SUPPORT(arity, fun, params) \
unspecified token sequence \
/**/
Description
Enables metafunction funfor the use in Lambda Expression s on compilers that don’t support partial template special-
ization or/and template template parameters. Expands to nothing on conforming compilers.
Header
#include <boost/mpl/aux_/lambda_support.hpp>
Parameters
Revision Date: 15th November 2004233 Macros 6.4 Broken Compiler Workarounds
Parameter Requirement Description
arity An integral constant The metafunction’s arity, i.e. the number of its template
parameters, including the defaults.
fun A legal identiﬁer token The metafunction’s name.
params APP-tuple A tuple of the metafunction’s parameter names, in their
original order, including the defaults.
Expression semantics
For any integral constant n, aMetafunction fun, and arbitrary types A1,...An:
template< typename A1, ... typename A n> struct fun
{
//...
BOOST_MPL_AUX_LAMBDA_SUPPORT(n, fun, (A1, ...An))
};
Precondition: Appears in fun’s scope, immediately followed by the scope-closing bracket ( }).
Return type: None.
Semantics: Expands to nothing and has no effect on conforming compilers. On compilers that don’t sup-
port partial template specialization or/and template template parameters expands to an unspeciﬁed
token sequence enabling funto participate in Lambda Expression s with the semantics described in
this manual.
Example
template< typename T, typename U = int > struct f
{
typedef T type[sizeof(U)];
BOOST_MPL_AUX_LAMBDA_SUPPORT(2, f, (T,U))
};
typedef apply1< f<char,_1>,long >::type r;
BOOST_MPL_ASSERT(( is_same< r, char[sizeof(long)] > ));
See also
Macros,Metafunctions ,Lambda Expression
Revision Date: 15th November 20046.4 Broken Compiler Workarounds Macros 234
Revision Date: 15th November 2004Chapter 7 Terminology
Overloaded name Overloaded name is a term used in this reference documentation to designate a metafunction pro-
viding more than one public interface. In reality, class template overloading is nonexistent and the referenced
functionality is implemented by other, unspeciﬁed, means.
Concept-identical A sequence s1is said to be concept-identical to a sequence s2ifs1ands2model the exact same
set of concepts.
Bind expression A bind expression is simply that — an instantiation of one of the bindclass templates. For instance,
these are all bind expressions:
bind< quote3<if_>, _1,int,long >
bind< _1, bind< plus<>, int_<5>, _2> >
bind< times<>, int_<2>, int_<2> >
and these are not:
if_< _1, bind< plus<>, int_<5>, _2>, _2 >
protect< bind< quote3<if_>, _1,int,long > >
_2Terminology 236
Revision Date: 15th November 2004Chapter 8 Categorized Index
8.1 Concepts
—Associative Sequence
—Back Extensible Sequence
—Bidirectional Iterator
—Bidirectional Sequence
—Extensible Associative Sequence
—Extensible Sequence
—Forward Iterator
—Forward Sequence
—Front Extensible Sequence
—Inserter
—Integral Constant
—Integral Sequence Wrapper
—Lambda Expression
—Metafunction
—Metafunction Class
—Numeric Metafunction
—Placeholder Expression
—Random Access Iterator
—Random Access Sequence
—Reversible Algorithm
—Tag Dispatched Metafunction
—Trivial Metafunction
—Variadic Sequence
8.2 Components
—BOOST_MPL_ASSERT
—BOOST_MPL_ASSERT_MSG
—BOOST_MPL_ASSERT_NOT8.2 Components Categorized Index 238
—BOOST_MPL_ASSERT_RELATION
—BOOST_MPL_AUX_LAMBDA_SUPPORT
—BOOST_MPL_CFG_NO_HAS_XXX
—BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
—BOOST_MPL_HAS_XXX_TRAIT_DEF
—BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF
—BOOST_MPL_LIMIT_LIST_SIZE
—BOOST_MPL_LIMIT_MAP_SIZE
—BOOST_MPL_LIMIT_METAFUNCTION_ARITY
—BOOST_MPL_LIMIT_SET_SIZE
—BOOST_MPL_LIMIT_UNROLLING
—BOOST_MPL_LIMIT_VECTOR_SIZE
—_1,_2,_3,...
—accumulate
—advance
—always
—and_
—apply
—apply_wrap
—arg
—at
—at_c
—back
—back_inserter
—begin
—bind
—bitand_
—bitor_
—bitxor_
—bool_
—clear
—contains
—copy
—copy_if
—count
Revision Date: 15th November 2004239 Categorized Index 8.2 Components
—count_if
—deque
—deref
—distance
—divides
—empty
—empty_base
—empty_sequence
—end
—equal
—equal_to
—erase
—erase_key
—eval_if
—eval_if_c
—filter_view
—find
—find_if
—fold
—front
—front_inserter
—greater
—greater_equal
—has_key
—identity
—if_
—if_c
—inherit
—inherit_linearly
—insert
—insert_range
—inserter
—int_
—integral_c
—is_sequence
Revision Date: 15th November 20048.2 Components Categorized Index 240
—iter_fold
—iterator_category
—iterator_range
—joint_view
—key_type
—lambda
—less
—less_equal
—list
—list_c
—long_
—lower_bound
—map
—max
—max_element
—min
—min_element
—minus
—modulus
—negate
—next
—not_
—not_equal_to
—numeric_cast
—or_
—order
—pair
—partition
—plus
—pop_back
—pop_front
—prior
—protect
—push_back
—push_front
Revision Date: 15th November 2004241 Categorized Index 8.2 Components
—quote
—range_c
—remove
—remove_if
—replace
—replace_if
—reverse
—reverse_copy
—reverse_copy_if
—reverse_fold
—reverse_iter_fold
—reverse_partition
—reverse_remove
—reverse_remove_if
—reverse_replace
—reverse_replace_if
—reverse_stable_partition
—reverse_transform
—reverse_unique
—sequence_tag
—set
—set_c
—shift_left
—shift_right
—single_view
—size
—size_t
—sizeof_
—sort
—stable_partition
—times
—transform
—transform_view
—unique
—unpack_args
Revision Date: 15th November 20048.2 Components Categorized Index 242
—upper_bound
—value_type
—vector
—vector_c
—void_
—zip_view
Revision Date: 15th November 2004Chapter 9 Acknowledgements
The format and language of this reference documentation has been greatly inﬂuenced by the SGI’s Standard Template
Library Programmer’s Guide .Acknowledgements 244
Revision Date: 15th November 2004Bibliography
[n1550]http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1550.htm
[PRE]Vesa Karvonen, Paul Mensonides, The Boost Preprocessor Metaprogramming library
[Ve03]Vesa Karvonen, The Order Programming Language , 2003.