Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/mpl/example/integer.cpp @ 45

Last change on this file since 45 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.9 KB
RevLine 
[29]1
2// Copyright Aleksey Gurtovoy 2001-2004
3//
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
8// See http://www.boost.org/libs/mpl for documentation.
9
10// $Source: /cvsroot/boost/boost/libs/mpl/example/integer.cpp,v $
11// $Date: 2004/09/02 15:41:29 $
12// $Revision: 1.4 $
13
14#include <boost/mpl/multiplies.hpp>
15#include <boost/mpl/list.hpp>
16#include <boost/mpl/lower_bound.hpp>
17#include <boost/mpl/transform_view.hpp>
18#include <boost/mpl/sizeof.hpp>
19#include <boost/mpl/int.hpp>
20#include <boost/mpl/identity.hpp>
21#include <boost/mpl/base.hpp>
22#include <boost/mpl/eval_if.hpp>
23#include <boost/mpl/deref.hpp>
24#include <boost/mpl/begin_end.hpp>
25#include <boost/mpl/assert.hpp>
26
27#include <boost/type_traits/is_same.hpp>
28
29namespace mpl = boost::mpl;
30using namespace mpl::placeholders;
31
32template< int bit_size >
33class big_int
34{
35    // ...
36};
37
38template< int bit_size >
39struct integer
40{
41    typedef mpl::list<char,short,int,long> builtins_;
42    typedef typename mpl::base< typename mpl::lower_bound<
43          mpl::transform_view< builtins_
44            , mpl::multiplies< mpl::sizeof_<_1>, mpl::int_<8> >
45            >
46        , mpl::int_<bit_size>
47        >::type >::type iter_;
48
49    typedef typename mpl::end<builtins_>::type last_;
50    typedef typename mpl::eval_if<
51          boost::is_same<iter_,last_>
52        , mpl::identity< big_int<bit_size> >
53        , mpl::deref<iter_>
54        >::type type;
55};
56
57typedef integer<1>::type int1;
58typedef integer<5>::type int5;
59typedef integer<15>::type int15;
60typedef integer<32>::type int32;
61typedef integer<100>::type int100;
62
63BOOST_MPL_ASSERT(( boost::is_same< int1, char > ));
64BOOST_MPL_ASSERT(( boost::is_same< int5, char > ));
65BOOST_MPL_ASSERT(( boost::is_same< int15, short > ));
66BOOST_MPL_ASSERT(( boost::is_same< int32, int > ));
67BOOST_MPL_ASSERT(( boost::is_same< int100, big_int<100> > ));
Note: See TracBrowser for help on using the repository browser.