summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-21 20:07:10 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-21 20:07:10 +0000
commit7bf3699135ea3e604ebf25174ba53d72a5d2d421 (patch)
tree5d4d313659bcf0fdb7debf4f41a5916874386daa
parentf5b76e275ca0c4480cbfff365e43f771f48128b0 (diff)
downloadgcc-7bf3699135ea3e604ebf25174ba53d72a5d2d421.tar.gz
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
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/ext/type_traits.h36
-rw-r--r--libstdc++-v3/testsuite/ext/type_traits.cc28
3 files changed, 58 insertions, 13 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index e85e75a6131..353b2b6f7ba 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 34e5ebd1cde..da71e986f75 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 00000000000..ea58bb8afc7
--- /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>;