• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Metafunctions/Bitwise Operations//shift_right
2
3shift_right
4===========
5
6Synopsis
7--------
8
9.. parsed-literal::
10
11    template<
12          typename T
13        , typename Shift
14        >
15    struct shift_right
16    {
17        typedef |unspecified| type;
18    };
19
20
21
22Description
23-----------
24
25Returns the result of bitwise *shift right* (``>>``) operation on ``T``.
26
27
28Header
29------
30
31.. parsed-literal::
32
33    #include <boost/mpl/shift_right.hpp>
34    #include <boost/mpl/bitwise.hpp>
35
36
37Model of
38--------
39
40|Numeric Metafunction|
41
42
43Parameters
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
57Expression semantics
58--------------------
59
60For arbitrary |Integral Constant| ``c`` and unsigned |Integral Constant| ``shift``:
61
62
63.. parsed-literal::
64
65    typedef shift_right<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_right<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_right<c,shift>::type {};
95
96
97Complexity
98----------
99
100Amortized constant time.
101
102
103Example
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_right<u0,u0>::value), ==, 0 );
114    BOOST_MPL_ASSERT_RELATION( (shift_right<u1,u0>::value), ==, 1 );
115    BOOST_MPL_ASSERT_RELATION( (shift_right<u1,u1>::value), ==, 0 );
116    BOOST_MPL_ASSERT_RELATION( (shift_right<u2,u1>::value), ==, 1 );
117    BOOST_MPL_ASSERT_RELATION( (shift_right<u8,u1>::value), ==, 4 );
118
119
120See also
121--------
122
123|Bitwise Operations|, |Numeric Metafunction|, |numeric_cast|, |shift_left|, |bitand_|
124
125
126.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
127   Distributed under the Boost Software License, Version 1.0. (See accompanying
128   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
129