[v3] ext/type_traits.h

Paolo Carlini pcarlini@suse.de
Fri Sep 15 14:04:00 GMT 2006


Benjamin Kosnik wrote:
> +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
> +
> +  // XXX What about std::tr1::true_type?
> +  template<bool _Cond, typename _Iftrue, typename _Iffalse>
> +    struct conditional_type
> +    { typedef _Iftrue type; };
> +
> +  template<typename _Iftrue, typename _Iffalse>
> +    struct conditional_type<false, _Iftrue, _Iffalse>
> +    { typedef _Iffalse type; };
> +
> +  // Compile time constants for builtin integral types.
> +  // Sadly std::numeric_limits member functions cannot be used for this.
> +#define __glibcxx_signed(T) ((T)(-1) < 0)
> +#define __glibcxx_digits(T) (sizeof(T) * __CHAR_BIT__ - __glibcxx_signed(T))
> +
> +#define __glibcxx_min(T) \
> +  (__glibcxx_signed(T) ? (T)1 << __glibcxx_digits(T) : (T)0)
> +
> +#define __glibcxx_max(T) \
> +  (__glibcxx_signed(T) ? ((T)1 << __glibcxx_digits(T)) - 1 : ~(T)0)
> +
> +  template<typename _Value>
> +    struct numeric_traits
> +    {
> +      typedef _Value value_type;
> +      
> +      // Only integer types.
> +      static const value_type min = __glibcxx_min(value_type);
> +      static const value_type max = __glibcxx_max(value_type);
> +      
> +      // Only floating point types. See N1822. 
> +      static const std::streamsize max_digits10 =
> +	2 + std::numeric_limits<_Value>::digits * 3010/10000;
> +    };
> +
> +  template<typename _Value>
> +    const _Value numeric_traits<_Value>::min;
> +
> +  template<typename _Value>
> +    const _Value numeric_traits<_Value>::max;
> +
> +  template<typename _Value>
> +    const std::streamsize numeric_traits<_Value>::max_digits10;
>   
My only doubt is about uglification: are we sure we want to add the 
non-uglified names numeric_traits and conditional_type (maybe other)?  
It's also a matter of consistency because generally we do uglify 
everything else (e.g., _Value,  _Cond,  _To_unsigned_type...). 
Personally, to be on the safe side, I'm trying to consistently uglify 
all the new code as mush as possible, same policy of the library proper 
in /ext and /tr1, that is. I was even thinking adjusting unordered_* 
containers and be done with it...

Paolo.



More information about the Libstdc++ mailing list