From 7bf3699135ea3e604ebf25174ba53d72a5d2d421 Mon Sep 17 00:00:00 2001 From: bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Thu, 21 Sep 2006 20:07:10 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117119 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 7 +++++ libstdc++-v3/include/ext/type_traits.h | 36 +++++++++++++++-------- libstdc++-v3/testsuite/ext/type_traits.cc | 28 ++++++++++++++++++ 3 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 libstdc++-v3/testsuite/ext/type_traits.cc 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 <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 34e5ebd1cde7..da71e986f753 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 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 <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>; -- GitLab