??? boost庫中MPL部分提供了Data_Types。其中提供了對數字類型的一個wrapper
??? 有一下這么幾個,都在boost::mpl名字空間下
???
??? bool_ 是一個bool型的常量wrapper,頭文件 #include< boost/mpl/bool.hpp >
??? int_? 是一個int型的常量wrapper,頭文件 #include< boost/mpl/int.hpp >
??? long_ 是一個long型的常量wrapper,頭文件 #include< boost/mpl/long.hpp >
??? size_t 是一個std::size_t型的常量wrapper,頭文件 #include< boost/mpl/size_t.hpp >
??? integral_c 提供了對整形的一個通用wrapper,頭文件 #include< boost/mpl/integral_c.hpp >
???
??? 這些常量提供了如下的能力(假設一個常量類型 n )
??? 獲得常量類型包含的類型 n::value_type
??? 獲得常量類型的類型???? n::type
??? 獲得常量類型的值?????? n::value
??? 返回常量類型的值?????? n()
???
??? bool_部分
???
??? bool_的聲明如下
???
??? template< bool C >
??? struct bool_;
???
??? 庫中定義了兩個常用的bool型常量,true_和false_。定義分別如下
??? typedef bool_< true > true_;
??? typedef bool_< false > false_;
???
??? bool_特性如下
??? bool_< true >::value_type == bool
??? bool_< true >::type == bool< true >
??? bool_< true >::value == true
??? bool_< true >() == true
???
??? int_部分
???
??? int_的聲明如下
???
??? template< int N >
??? struct int_;
???
??? int_特性如下
??? int_< 10 >::value_type == int;
??? int_< 10 >::type == int_< 10 >;
??? int_< 10 >::value == 10;
??? int_< 10 >() == 10;
???
??? long_部分
???
??? long_的聲明如下
???
??? template< long N >
??? struct long_;
???
??? long_特性如下
??? long_< -500 >::value_type == long;
??? long_< -500 >::type == long_< -500 >;
??? long_< -500 >::value == -500;
??? long_< -500 >() == -500;
???
??? size_t部分
???
??? size_t的聲明如下
???
??? template< std::size_t N >
??? struct size_t;
???
??? size_t的特性如下
??? size_t< 20 >::value_type == std::size_t;
??? size_t< 20 >::type == size_t< 20 >;
??? size_t< 20 >::value == 20;
??? size_t< 20 >() == 20;
???
??? integral_c部分
???
??? integral_c的聲明如下
??? template< typename T, T N >
??? struct integral_c;
???
??? integral_c的特性如下
??? integral_c< short, 8 >::value_type == short;
??? integral_c< short, 8 >::type == integral_c< short, 8 >;
??? integral_c< short, 8 >::value == 8;
??? integral_c< short, 8 >() == 8;
posted on 2007-03-10 14:10
walkspeed 閱讀(1991)
評論(0) 編輯 收藏 引用 所屬分類:
STL、Boost、范型編程