+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
#include <utility>
#include <limits>
#include <iosfwd> // std::streamsize
+#include <bits/cpp_type_traits.h>
_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
--- /dev/null
+// { 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>;