diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e85e75a61310..353b2b6f7ba6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2006-09-21 Benjamin Kosnik + + * 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 * 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 34e5ebd1cde7..da71e986f753 100644 --- a/libstdc++-v3/include/ext/type_traits.h +++ b/libstdc++-v3/include/ext/type_traits.h @@ -37,6 +37,7 @@ #include #include #include // std::streamsize +#include _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 - 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 - const _Value __numeric_traits<_Value>::__min; + const _Value __numeric_traits_integer<_Value>::__min; template - const _Value __numeric_traits<_Value>::__max; + const _Value __numeric_traits_integer<_Value>::__max; template - 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 + const std::streamsize __numeric_traits_floating<_Value>::__max_digits10; + + template + struct __numeric_traits + : public __conditional_type::__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 000000000000..ea58bb8afc70 --- /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 + +using __gnu_cxx::__numeric_traits; +template struct __numeric_traits; +template struct __numeric_traits; +template struct __numeric_traits;