This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: use of type_traits


Paolo Carlini <pcarlini@suse.de> writes:

[...]

|    // An arithmetic type is an integer type or a floating point type
|    //
| -  template<typename _Tp>
| +  template<typename _Tp, bool = (__is_integer<_Tp>::_M_type
| +				 || __is_floating<_Tp>::_M_type)>
|      struct __is_arithmetic
|      {
| -      enum
| -	{
| -	  _M_type = __is_integer<_Tp>::_M_type || __is_floating<_Tp>::_M_type
| -	};
| +      enum { _M_type = 0 };
| +      typedef __false_type __type;
|      };
|    
| +  template<typename _Tp>
| +    struct __is_arithmetic<_Tp, true>
| +    {
| +      enum { _M_type = 1 };
| +      typedef __true_type __type;
| +    };
| +
|    //
|    // A fundamental type is `void' or and arithmetic type
|    //
| -  template<typename _Tp>
| +  template<typename _Tp, bool = (__is_void<_Tp>::_M_type
| +				 || __is_arithmetic<_Tp>::_M_type)>
|      struct __is_fundamental
|      {
| -      enum
| -	{
| -	  _M_type = __is_void<_Tp>::_M_type || __is_arithmetic<_Tp>::_M_type
| -	};
| +      enum { _M_type = 0 };
| +      typedef __false_type __type;
| +    };
| +
| +  template<typename _Tp>
| +    struct __is_fundamental<_Tp, true>
| +    {
| +      enum { _M_type = 1 };
| +      typedef __true_type __type;
|      };
|  
|    //
|    // A scalar type is an arithmetic type or a pointer type
|    // 
| -  template<typename _Tp>
| +  template<typename _Tp, bool = (__is_arithmetic<_Tp>::_M_type
| +				 || __is_pointer<_Tp>::_M_type)>
|      struct __is_scalar
|      {
| -      enum
| -	{
| -	  _M_type = __is_arithmetic<_Tp>::_M_type || __is_pointer<_Tp>::_M_type
| -	};
| +      enum { _M_type = 0 };
| +      typedef __false_type __type;
| +    };
| +
| +  template<typename _Tp>
| +    struct __is_scalar<_Tp, true>
| +    {
| +      enum { _M_type = 1 };
| +      typedef __true_type __type;
|      };

I'm not sure I agree with the repetition of those ad-hoc rules.
What about

       template<bool>
       struct __truth_type {
           typedef __false_type __type;
       };

       template<>
       struct __truth_type<true> {
           typedef __true_type __type;
       };

       template<class _Sp, class _Tp>
        struct __traitor {
            enum { _M_value = _Sp::_M_value || _Tp::_M_value };
            typedef typename __truth_type<_M_value>::__type __type;
        };

       // not used in this patch but may be useful elsewhere.
       template<class _Sp, class _Tp>
        struct __traitand {
            enum { _M_value = _Sp::_M_value && _Tp::_M_value };
            typedef typename __truth_type<_M_value>::__type __type;
        };

* arithmetic

       template<typename _Tp>
       struct __is_arithmetic : __traitor<__is_integer<_Tp>,
                                          __is_floating<_Tp> >
       { };

* fundamental

      template<typename _Tp>
      struct __is_fundamental : __traitor<__is_void<_Tp>,
                                          __is_arithmetic<_Tp> >
      { };

* scalar
      
      template<typename _Tp>
      struct __is_scalar : __traitor<__is_arithmetic<_Tp>,
                                     __is_pointer<_Tp> >
      { };

?

-- Gaby
PS: The choice of _M_type  was unfortunate, but that is a topic 
of another time.  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]