diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e85e75a613103e4e70790ec20c3262038ee701a9..353b2b6f7ba6fa0330e9091ba377c154a68031ac 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2006-09-21 Benjamin Kosnik <bkoz@redhat.com> + + * include/ext/type_traits.h (__numeric_traits_integer): New. + (__numeric_traits_floating): New. + (__numeric_traits): Use them. + * testsuite/ext/type_traits.cc: New. + 2006-09-21 Paolo Carlini <pcarlini@suse.de> * include/ext/hash_map: Remove forward declaration of equality diff --git a/libstdc++-v3/include/ext/type_traits.h b/libstdc++-v3/include/ext/type_traits.h index 34e5ebd1cde7de8474bc6a370c9a6f57d9049611..da71e986f753067049ce20be0a268d9869f8c9a8 100644 --- a/libstdc++-v3/include/ext/type_traits.h +++ b/libstdc++-v3/include/ext/type_traits.h @@ -37,6 +37,7 @@ #include <utility> #include <limits> #include <iosfwd> // std::streamsize +#include <bits/cpp_type_traits.h> _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) @@ -126,27 +127,36 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) (__glibcxx_signed(T) ? ((T)1 << __glibcxx_digits(T)) - 1 : ~(T)0) template<typename _Value> - struct __numeric_traits + struct __numeric_traits_integer { - 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_type>::digits * 3010/10000; + // Only integers for initialization of member constant. + static const _Value __min = __glibcxx_min(_Value); + static const _Value __max = __glibcxx_max(_Value); }; template<typename _Value> - const _Value __numeric_traits<_Value>::__min; + const _Value __numeric_traits_integer<_Value>::__min; template<typename _Value> - const _Value __numeric_traits<_Value>::__max; + const _Value __numeric_traits_integer<_Value>::__max; template<typename _Value> - const std::streamsize __numeric_traits<_Value>::__max_digits10; + struct __numeric_traits_floating + { + // Only floating point types. See N1822. + static const std::streamsize __max_digits10 = + 2 + std::numeric_limits<_Value>::digits * 3010/10000; + }; + + template<typename _Value> + const std::streamsize __numeric_traits_floating<_Value>::__max_digits10; + + template<typename _Value> + struct __numeric_traits + : public __conditional_type<std::__is_integer<_Value>::__value, + __numeric_traits_integer<_Value>, + __numeric_traits_floating<_Value> >::__type + { }; _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/testsuite/ext/type_traits.cc b/libstdc++-v3/testsuite/ext/type_traits.cc new file mode 100644 index 0000000000000000000000000000000000000000..ea58bb8afc70e253c9948af1d1c6b9a06be02768 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-pedantic" } +// -*- C++ -*- + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include <ext/type_traits.h> + +using __gnu_cxx::__numeric_traits; +template struct __numeric_traits<short>; +template struct __numeric_traits<unsigned short>; +template struct __numeric_traits<double>;