]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Metafunctions/Arithmetic Operations//plus |10 |
2 | ||
3 | plus | |
4 | ==== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename T1 | |
13 | , typename T2 | |
14 | , typename T3 = |unspecified| | |
15 | |...| | |
16 | , typename T\ *n* = |unspecified| | |
17 | > | |
18 | struct plus | |
19 | { | |
20 | typedef |unspecified| type; | |
21 | }; | |
22 | ||
23 | ||
24 | ||
25 | Description | |
26 | ----------- | |
27 | ||
28 | Returns the sum of its arguments. | |
29 | ||
30 | ||
31 | Header | |
32 | ------ | |
33 | ||
34 | .. parsed-literal:: | |
35 | ||
36 | #include <boost/mpl/plus.hpp> | |
37 | #include <boost/mpl/arithmetic.hpp> | |
38 | ||
39 | ||
40 | Model of | |
41 | -------- | |
42 | ||
43 | |Numeric Metafunction| | |
44 | ||
45 | ||
46 | ||
47 | Parameters | |
48 | ---------- | |
49 | ||
50 | +---------------+---------------------------+-----------------------------------------------+ | |
51 | | Parameter | Requirement | Description | | |
52 | +===============+===========================+===============================================+ | |
53 | | |T1...Tn| | |Integral Constant| | Operation's arguments. | | |
54 | +---------------+---------------------------+-----------------------------------------------+ | |
55 | ||
56 | |Note:| |numeric metafunction note| |-- end note| | |
57 | ||
58 | ||
59 | Expression semantics | |
60 | -------------------- | |
61 | ||
62 | For any |Integral Constant|\ s |c1...cn|: | |
63 | ||
64 | ||
65 | .. parsed-literal:: | |
66 | ||
67 | typedef plus<c1,\ |...|\ c\ *n*\>::type r; | |
68 | ||
69 | :Return type: | |
70 | |Integral Constant|. | |
71 | ||
72 | :Semantics: | |
73 | Equivalent to | |
74 | ||
75 | .. parsed-literal:: | |
76 | ||
77 | typedef integral_c< | |
78 | typeof(c1::value + c2::value) | |
79 | , ( c1::value + c2::value ) | |
80 | > c; | |
81 | ||
82 | typedef plus<c,c3,\ |...|\c\ *n*\>::type r; | |
83 | ||
84 | .. .......................................................................... | |
85 | ||
86 | .. parsed-literal:: | |
87 | ||
88 | typedef plus<c1,\ |...|\ c\ *n*\> r; | |
89 | ||
90 | :Return type: | |
91 | |Integral Constant|. | |
92 | ||
93 | :Semantics: | |
94 | Equivalent to | |
95 | ||
96 | .. parsed-literal:: | |
97 | ||
98 | struct r : plus<c1,\ |...|\ c\ *n*\>::type {}; | |
99 | ||
100 | ||
101 | ||
102 | ||
103 | Complexity | |
104 | ---------- | |
105 | ||
106 | Amortized constant time. | |
107 | ||
108 | ||
109 | Example | |
110 | ------- | |
111 | ||
112 | .. parsed-literal:: | |
113 | ||
114 | typedef plus< int_<-10>, int_<3>, long_<1> >::type r; | |
115 | BOOST_MPL_ASSERT_RELATION( r::value, ==, -6 ); | |
116 | BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); | |
117 | ||
118 | ||
119 | See also | |
120 | -------- | |
121 | ||
122 | |Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |minus|, |negate|, |times| | |
123 | ||
124 | ||
125 |