Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

conversion_traits<> traits class  conversion_traits<> traits 類

Types 類型
Examples 例子

namespace boost { namespace numeric {

    enum int_float_mixture_enum
    {
       integral_to_integral
      ,integral_to_float
      ,float_to_integral
      ,float_to_float
    } ;

} } // namespace boost::numeric

namespace boost { namespace numeric {

enum sign_mixture_enum
{
   unsigned_to_unsigned
  ,signed_to_signed
  ,signed_to_unsigned
  ,unsigned_to_signed
} ;

} } // namespace boost::numeric

namespace boost { namespace numeric {

    enum udt_builtin_mixture_enum
    {
       builtin_to_builtin
      ,builtin_to_udt
      ,udt_to_builtin
      ,udt_to_udt
    } ;

} } // namespace boost::numeric

namespace boost { namespace numeric {

    template <class T, class S>
    struct int_float_mixture : mpl::integral_c<int_float_mixture_enum, impl-def-value> {} ;

} } // namespace boost::numeric

Classifying S and T as either integral or float, this MPL's Integral Constant indicates the combination of these attributes.
ST 分類為整型的或浮點的,這個 MPL 整型常量 表示了這些屬性的組合。

Its ::value is of enumeration type boost::numeric::int_float_mixture_enum
Its ::value 為枚舉類型 boost::numeric::int_float_mixture_enum

namespace boost { namespace numeric {

    template <class T, class S>
    struct sign_mixture : mpl::integral_c<sign_mixture_enum, impl-def-value> {} ;

} } // namespace boost::numeric

Classifying S and T as either signed or unsigned, this MPL's Integral Constant indicates the combination of these attributes.
ST 分類為有符號的或無符號的,這個 MPL 整型常量 表示了這些屬性的組合。

Its ::value is of enumeration type boost::numeric::sign_mixture_enum
Its ::value 為枚舉類型 boost::numeric::sign_mixture_enum

namespace boost { namespace numeric {

    template <class T, class S>
    struct udt_builtin_mixture : mpl::integral_c<udt_builtin__mixture_enum, impl-def-value> {} ;

} } // namespace boost::numeric

Classifying S and T as either user-defined or builtin, this MPL's Integral Constant indicates the combination of these attributes.
ST 分類為用戶自定義的或內建的,這個 MPL 整型常量 表示了這些屬性的組合。

Its ::value is of enumeration type boost::numeric::udt_builtin_mixture_enum
Its ::value 為枚舉類型 boost::numeric::udt_builtin_mixture_enum

namespace boost { namespace numeric {

    template <class T, class S>
    struct is_subranged : mpl::bool_<impl-def-value> {} ;

} } // namespace boost::numeric

Indicates if the range of the target type T is a subset of the range of the source type S. That is: if there are some source values which fall out of the Target type's range.
指明目標類型 T 的範圍是否為源類型 S 的範圍的子集。即:是否有一些源類型的值在目標類型範圍以外。

It is a boolean MPL's Integral Constant .
它是一個布爾 MPL 整型常量

It does not indicate if a particular conversion is effectively out of range; it indicates that some conversion might be out of range because not all the source values are representable as Target type.
它並不能指明某個特定的轉換是否超出範圍;它只是指明有些轉換可能會超出範圍,因為不是所有源類型的值都可以表示為目標類型。

namespace boost { namespace numeric {

    template <class T, class S>
    struct conversion_traits
    {
        mpl::integral_c<int_float_mixture_enum  , ...> int_float_mixture ;
        mpl::integral_c<sign_mixture_enum       , ...> sign_mixture;
        mpl::integral_c<udt_builtin_mixture_enum, ...> udt_builtin_mixture ;

        mpl::bool_<...> subranged ;
        mpl::bool_<...> trivial ;

        typedef T target_type   ;
        typedef S source_type   ;
        typedef ... argument_type ;
        typedef ... result_type   ;
        typedef ... supertype     ;
        typedef ... subtype       ;
    } ;

} } // namespace numeric, namespace boost

This traits class indicates some properties of a numeric conversion direction: from a source type S to a target type T. It does not indicate the properties of a specific conversion, but of the conversion direction. See Definitions for details.
這個 traits 類表示一個 數字轉換 方向:從源類型 S 到目標類型 T 的一些屬性。它不表示某個特定轉換的屬性,而是表示轉換方向的屬性。詳情請見 定義。 

The traits class provides the following MPL's Integral Constant \s of enumeration type. They express the combination of certain attributes of the Source and Target types (thus they are call mixture):
這個 traits 類提供以下枚舉類型的 MPL 整型常量。它們表示了源類型和目標類型的特定屬性的組合(因此稱為混合的):

int_float_mixture

Same as given by the traits class int_float_mixture
與 traits 類 int_float_mixture 所給出的相同

sign_mixture

Same as given by the traits class sign_mixture
與 traits 類 sign_mixture 所給出的相同

udt_builtin_mixture

Same as given by the traits class udt_builtin_mixture
與 traits 類 udt_builtin_mixture 所給出的相同

The traits class provides the following MPL's Integral Constant \s of boolean type which indicates indirectly the relation between the Source and Target ranges (see Definitions for details).
這個 traits 類提供以下布爾類型的 MPL 整型常量,間接地表示源類型範圍和目標類型範圍間的關係(詳見 定義)。

subranged

Same as given by is_subranged
is_subranged 所給出的相同

trivial

Indicates if both Source and Target, without cv-qualifications, are the same type.

表明源類型和目標類型 在不考慮cv-限定符下 是否為相同類型。

Its ::value is of boolean type.
Its ::value 為布爾類型。

The traits class provides the following types. They are the Source and Target types classified and qualified for different purposes.
這個 traits 類提供以下類型。它們根據不同目的對源類型和目標類型進行分類和限定。

target_type

The template parameter T without cv-qualifications

不帶cv-限定符的模板參數 T

source_type

The template parameter S without cv-qualifications

不帶cv-限定符的模板參數 S

argument_type

This type is either source_type or source_type const&.

該類型為 source_type 或 source_type const&

It represents the optimal argument type for the converter member functions.
它表示了用於 converter 成員函數的優化參數類型。

If S is a built-in type, this is source_type, otherwise, this is source_type const&.
如果 S 是內建類型,則它為 source_type,否則為 source_type const&

result_type

This type is either target_type or target_type const&

該類型為target_type 或 target_type const&

It represents the return type of the converter member functions.
它表示了用於 converter 成員函數的返回類型。

If T==S, it is target_type const&, otherwise, it is target_type.
如果 T==S,則它為 target_type const&,否則為 target_type

supertype

If the conversion is subranged, it is source_type, otherwise, it is target_type
如果轉換是子範圍的,它為 source_type,否則為 target_type

subtype

If the conversion is subranged, it is target_type, otherwise, it is source_type
如果轉換是子範圍的,它為 target_type,否則為 source_type

#include <cassert>
#include <typeinfo>
#include <boost/numeric/conversion/conversion_traits.hpp>

int main()
{

    // A trivial conversion. 簡單轉換
typedef boost::numeric::conversion_traits<short,short> Short2Short_Traits ; assert ( Short2Short_Traits::trivial::value ) ; // A subranged conversion. 子範圍轉換
typedef boost::numeric::conversion_traits<double,unsigned int> UInt2Double_Traits ; assert ( UInt2Double_Traits::int_float_mixture::value == boost::numeric::integral_to_float ) ; assert ( UInt2Double_Traits::sign_mixture::value == boost::numeric::unsigned_to_signed ) ; assert ( !UInt2Double_Traits::subranged::value ) ; assert ( typeid(UInt2Double_Traits::supertype) == typeid(double) ) ; assert ( typeid(UInt2Double_Traits::subtype) == typeid(unsigned int) ) ; // A doubly subranged conversion. 雙重子範圍轉換
assert ( (boost::numeric::conversion_traits<short, unsigned short>::subranged::value) ); assert ( (boost::numeric::conversion_traits<unsigned short, short>::subranged::value) ); return 0; }

PrevUpHomeNext