]>
Commit | Line | Data |
---|---|---|
1 | .. Metafunctions/Bitwise Operations//shift_left | |
2 | ||
3 | shift_left | |
4 | ========== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename T | |
13 | , typename Shift | |
14 | > | |
15 | struct shift_left | |
16 | { | |
17 | typedef |unspecified| type; | |
18 | }; | |
19 | ||
20 | ||
21 | ||
22 | Description | |
23 | ----------- | |
24 | ||
25 | Returns the result of bitwise *shift left* (``<<``) operation on ``T``. | |
26 | ||
27 | ||
28 | Header | |
29 | ------ | |
30 | ||
31 | .. parsed-literal:: | |
32 | ||
33 | #include <boost/mpl/shift_left.hpp> | |
34 | #include <boost/mpl/bitwise.hpp> | |
35 | ||
36 | ||
37 | Model of | |
38 | -------- | |
39 | ||
40 | |Numeric Metafunction| | |
41 | ||
42 | ||
43 | Parameters | |
44 | ---------- | |
45 | ||
46 | +---------------+-------------------------------+---------------------------+ | |
47 | | Parameter | Requirement | Description | | |
48 | +===============+===============================+===========================+ | |
49 | | ``T`` | |Integral Constant| | A value to shift. | | |
50 | +---------------+-------------------------------+---------------------------+ | |
51 | | ``Shift`` | Unsigned |Integral Constant| | A shift distance. | | |
52 | +---------------+-------------------------------+---------------------------+ | |
53 | ||
54 | |Note:| |numeric metafunction note| |-- end note| | |
55 | ||
56 | ||
57 | Expression semantics | |
58 | -------------------- | |
59 | ||
60 | For arbitrary |Integral Constant| ``c`` and unsigned |Integral Constant| ``shift``: | |
61 | ||
62 | ||
63 | .. parsed-literal:: | |
64 | ||
65 | typedef shift_left<c,shift>::type r; | |
66 | ||
67 | :Return type: | |
68 | |Integral Constant|. | |
69 | ||
70 | :Semantics: | |
71 | Equivalent to | |
72 | ||
73 | .. parsed-literal:: | |
74 | ||
75 | typedef integral_c< | |
76 | c::value_type | |
77 | , ( c::value << shift::value ) | |
78 | > r; | |
79 | ||
80 | .. .......................................................................... | |
81 | ||
82 | .. parsed-literal:: | |
83 | ||
84 | typedef shift_left<c,shift> r; | |
85 | ||
86 | :Return type: | |
87 | |Integral Constant|. | |
88 | ||
89 | :Semantics: | |
90 | Equivalent to | |
91 | ||
92 | .. parsed-literal:: | |
93 | ||
94 | struct r : shift_left<c,shift>::type {}; | |
95 | ||
96 | ||
97 | Complexity | |
98 | ---------- | |
99 | ||
100 | Amortized constant time. | |
101 | ||
102 | ||
103 | Example | |
104 | ------- | |
105 | ||
106 | .. parsed-literal:: | |
107 | ||
108 | typedef integral_c<unsigned,0> u0; | |
109 | typedef integral_c<unsigned,1> u1; | |
110 | typedef integral_c<unsigned,2> u2; | |
111 | typedef integral_c<unsigned,8> u8; | |
112 | ||
113 | BOOST_MPL_ASSERT_RELATION( (shift_left<u0,u0>::value), ==, 0 ); | |
114 | BOOST_MPL_ASSERT_RELATION( (shift_left<u1,u0>::value), ==, 1 ); | |
115 | BOOST_MPL_ASSERT_RELATION( (shift_left<u1,u1>::value), ==, 2 ); | |
116 | BOOST_MPL_ASSERT_RELATION( (shift_left<u2,u1>::value), ==, 4 ); | |
117 | BOOST_MPL_ASSERT_RELATION( (shift_left<u8,u1>::value), ==, 16 ); | |
118 | ||
119 | ||
120 | See also | |
121 | -------- | |
122 | ||
123 | |Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |shift_right|, |bitand_| | |
124 | ||
125 | ||
126 |