Author: vitek
Date: Fri Jun 6 14:44:17 2008
New Revision: 664141
URL: http://svn.apache.org/viewvc?rev=664141&view=rev
Log:
2008-06-06 Travis Vitek <[EMAIL PROTECTED]>
STDCXX-917
* include/type_traits: Add type_traits header that
includes integral_contstant<> implementation.
* tests/utilities/20.meta.help.cpp: Add new test.
Added:
stdcxx/branches/4.3.x/include/type_traits (with props)
stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp (with props)
Added: stdcxx/branches/4.3.x/include/type_traits
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/type_traits?rev=664141&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/include/type_traits (added)
+++ stdcxx/branches/4.3.x/include/type_traits Fri Jun 6 14:44:17 2008
@@ -0,0 +1,86 @@
+ // -*- C++ -*-
+/***************************************************************************
+ *
+ * type_traits - definition of type_traits types
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 2008 Rogue Wave Software, Inc.
+ *
+ **************************************************************************/
+
+#ifndef _RWSTD_TYPE_TRAITS_INCLUDED
+#define _RWSTD_TYPE_TRAITS_INCLUDED
+
+#include <rw/_defs.h>
+
+#ifndef _RWSTD_NO_EXT_CXX_0X
+
+_RWSTD_NAMESPACE (std) {
+
+/**
+ * The class template integral_constant and its associated typedefs
+ * true_type and false_type are used as base classes to define the
+ * interface for various type traits.
+ */
+template <class _TypeT, _TypeT _Value>
+struct integral_constant
+{
+ /**
+ * Describes the type of this integral_constant.
+ */
+ typedef integral_constant<_TypeT,_Value> type;
+
+ /**
+ * Describes the type of the value defined by this integral_constant.
+ */
+ typedef _TypeT value_type;
+
+ /**
+ * The actual integral constant value.
+ */
+ static const _TypeT value = _Value;
+};
+
+#ifndef _RWSTD_NO_STATIC_CONST_MEMBER_DEFINITION
+
+template<class _TypeT, _TypeT _Value>
+const _TypeT integral_constant<_TypeT, _Value>::value;
+
+#endif // _RWSTD_NO_STATIC_CONST_MEMBER_DEFINITION
+
+/**
+ * Convenience typedef that is intended to be used as a base class
+ * for boolean type traits that are true.
+ */
+typedef integral_constant<bool, true> true_type;
+
+/**
+ * Convenience typedef that is intended to be used as a base class
+ * for boolean type traits that are false.
+ */
+typedef integral_constant<bool, false> false_type;
+
+} // namespace std
+
+#endif // _RWSTD_NO_EXT_CXX_0X
+
+#endif // _RWSTD_TYPE_TRAITS_INCLUDED
Propchange: stdcxx/branches/4.3.x/include/type_traits
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: stdcxx/branches/4.3.x/include/type_traits
------------------------------------------------------------------------------
svn:keywords = Id
Added: stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp?rev=664141&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp (added)
+++ stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp Fri Jun 6 14:44:17
2008
@@ -0,0 +1,256 @@
+// -*- C++ -*-
+/***************************************************************************
+ *
+ * 20.meta.help.cpp - test exercising tr.meta.help
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1999-2008 Rogue Wave Software, Inc.
+ *
+ **************************************************************************/
+
+#include <type_traits>
+
+#include <driver.h>
+
+// compile out all test code if extensions disabled
+#ifndef _RWSTD_NO_EXT_CXX_0X
+
+/**************************************************************************/
+
+template <class T, class U>
+bool test_is_same_type (T, U)
+{
+ return 0;
+}
+
+template <class T>
+bool test_is_same_type (T, T)
+{
+ return 1;
+}
+
+template <class T>
+bool test_is_const (T&)
+{
+ return 0;
+}
+
+template <class T>
+bool test_is_const (const T&)
+{
+ return 1;
+}
+
+template <class T, class U>
+struct test_is_same
+{
+ enum { value = 0 };
+};
+
+template <class T>
+struct test_is_same<T,T>
+{
+ enum { value = 1 };
+};
+
+enum enum_t {
+ E_a, E_b, E_c
+};
+
+/**************************************************************************/
+
+template <typename Type, Type Value>
+void test_integral_constant(const char* name, const char* value)
+{
+ typedef std::integral_constant<Type, Value>
+ integral_constant_type;
+
+ // verify the type of value is the same as Type
+ const bool a =
+ test_is_same_type (integral_constant_type::value, Type ());
+ rw_assert (a, 0, __LINE__,
+ "integral_constant<%s, %s>::value is%{?}n't%{;} "
+ "of type %s", name, value, !a, name);
+
+ // verify the value is as expected
+ const bool b =
+ integral_constant_type::value == Value;
+ rw_assert (b, 0, __LINE__,
+ "integral_constant<%s, %s>::value is%{?}n't%{;} "
+ "equal to %s", name, value, !b, value);
+
+ // verify that the value is const
+ const bool d =
+ test_is_const (std::integral_constant<Type,Value>::value);
+ rw_assert (d, 0, __LINE__,
+ "integral_constant<%s, %s>::value is%{?}n't%{;} "
+ "a constant", name, value, !d);
+
+ // verify that the type typedef is correct
+ const bool e =
+ test_is_same<_TYPENAME integral_constant_type::type,
+ integral_constant_type>::value;
+ rw_assert (e, 0, __LINE__,
+ "integral_constant<%s, %s>::type is%{?}n't%{;} "
+ "same as integral_constant<%s, %s>",
+ name, value, !e, name, value);
+
+ // note: compiler should never allow an instantiation of
+ // integral_constant<T, V> if T is not an integral type.
+}
+
+template <typename Type, bool Value>
+void test_required_type (const char* name, const char* value)
+{
+ typedef Type integral_constant_type;
+
+ // verify the type of the type typedef
+ const bool a =
+ test_is_same<_TYPENAME integral_constant_type::value_type,
bool>::value;
+ rw_assert (a, 0, __LINE__,
+ "%s::value_type is%{?}n't%{;} same as bool",
+ name, !a);
+
+ // verify the value is as expected
+ const bool b =
+ integral_constant_type::value == Value;
+ rw_assert (b, 0, __LINE__,
+ "%s::value is%{?}n't%{;} equal to %s",
+ name, !b, value);
+
+ // verify that Type is same as integral_constant<bool, Value>
+ const bool c =
+ test_is_same<std::integral_constant<bool, Value>, Type>::value;
+ rw_assert (c, 0, __LINE__,
+ "%s is%{?}n't%{;} of type integral_constant<bool, %s>",
+ name, !c, value);
+
+ test_integral_constant<_TYPENAME integral_constant_type::value_type,
+ Value>("bool", value);
+}
+
+/**************************************************************************/
+
+static int run_test (int, char*[])
+{
+#define TEST_INTEGRAL_CONSTANT(Type,Value) \
+ test_integral_constant<Type, Value>(#Type,#Value)
+
+ TEST_INTEGRAL_CONSTANT (bool, true);
+ TEST_INTEGRAL_CONSTANT (bool, false);
+
+ TEST_INTEGRAL_CONSTANT (char, '\0');
+ TEST_INTEGRAL_CONSTANT (char, _RWSTD_CHAR_MIN);
+ TEST_INTEGRAL_CONSTANT (char, _RWSTD_CHAR_MAX);
+
+#ifndef _RWSTD_NO_WCHAR_T
+ TEST_INTEGRAL_CONSTANT (wchar_t, L'\0');
+ TEST_INTEGRAL_CONSTANT (wchar_t, _RWSTD_WCHAR_MIN);
+ TEST_INTEGRAL_CONSTANT (wchar_t, _RWSTD_WCHAR_MAX);
+#endif // _RWSTD_NO_WCHAR_T
+
+ TEST_INTEGRAL_CONSTANT (signed char, 0);
+ TEST_INTEGRAL_CONSTANT (signed char, _RWSTD_SCHAR_MIN);
+ TEST_INTEGRAL_CONSTANT (signed char, _RWSTD_SCHAR_MAX);
+
+ TEST_INTEGRAL_CONSTANT (signed short, 0);
+ TEST_INTEGRAL_CONSTANT (signed short, _RWSTD_SHRT_MIN);
+ TEST_INTEGRAL_CONSTANT (signed short, _RWSTD_SHRT_MAX);
+
+ TEST_INTEGRAL_CONSTANT (signed int, 0);
+ TEST_INTEGRAL_CONSTANT (signed int, _RWSTD_INT_MIN);
+ TEST_INTEGRAL_CONSTANT (signed int, _RWSTD_INT_MAX);
+
+ TEST_INTEGRAL_CONSTANT (signed long, 0);
+ TEST_INTEGRAL_CONSTANT (signed long, _RWSTD_LONG_MIN);
+ TEST_INTEGRAL_CONSTANT (signed long, _RWSTD_LONG_MAX);
+
+#ifndef _RWSTD_NO_LONG_LONG
+ TEST_INTEGRAL_CONSTANT (signed long long, 0);
+ TEST_INTEGRAL_CONSTANT (signed long long, _RWSTD_LLONG_MIN);
+ TEST_INTEGRAL_CONSTANT (signed long long, _RWSTD_LLONG_MAX);
+#endif // _RWSTD_NO_LONG_LONG
+
+ TEST_INTEGRAL_CONSTANT (unsigned char, 1);
+ TEST_INTEGRAL_CONSTANT (unsigned char, _RWSTD_UCHAR_MIN);
+ TEST_INTEGRAL_CONSTANT (unsigned char, _RWSTD_UCHAR_MAX);
+
+ TEST_INTEGRAL_CONSTANT (unsigned short, 1);
+ TEST_INTEGRAL_CONSTANT (unsigned short, _RWSTD_USHRT_MIN);
+ TEST_INTEGRAL_CONSTANT (unsigned short, _RWSTD_USHRT_MAX);
+
+ TEST_INTEGRAL_CONSTANT (unsigned int, 1);
+ TEST_INTEGRAL_CONSTANT (unsigned int, _RWSTD_UINT_MIN);
+ TEST_INTEGRAL_CONSTANT (unsigned int, _RWSTD_UINT_MAX);
+
+ TEST_INTEGRAL_CONSTANT (unsigned long, 1);
+ TEST_INTEGRAL_CONSTANT (unsigned long, _RWSTD_UINT_MIN);
+ TEST_INTEGRAL_CONSTANT (unsigned long, _RWSTD_UINT_MAX);
+
+#ifndef _RWSTD_NO_LONG_LONG
+ TEST_INTEGRAL_CONSTANT (unsigned long long, 1);
+ TEST_INTEGRAL_CONSTANT (unsigned long long, _RWSTD_ULLONG_MIN);
+ TEST_INTEGRAL_CONSTANT (unsigned long long, _RWSTD_ULLONG_MAX);
+#endif // _RWSTD_NO_LONG_LONG
+
+ TEST_INTEGRAL_CONSTANT (enum_t, E_a);
+ TEST_INTEGRAL_CONSTANT (enum_t, E_b);
+ TEST_INTEGRAL_CONSTANT (enum_t, E_c);
+
+#ifdef _ILL_FORMED
+ TEST_INTEGRAL_CONSTANT (float, 1.f);
+#endif // _ILL_FORMED
+
+#define TEST_REQUIRED_TYPE(Type,Value) \
+ test_required_type<Type, Value>(#Type, #Value);
+
+ TEST_REQUIRED_TYPE (std::true_type , true);
+ TEST_REQUIRED_TYPE (std::false_type, false);
+
+ return 0;
+}
+
+/**************************************************************************/
+
+#else // _RWSTD_NO_EXT_CXX_0X
+
+/**************************************************************************/
+
+static int run_test (int, char*[])
+{
+ rw_warn (0, 0, __LINE__,
+ "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
+ return 0;
+}
+
+#endif // !_RWSTD_NO_EXT_CXX_0X
+
+/**************************************************************************/
+
+int main (int argc, char *argv[])
+{
+ return rw_test (argc, argv, __FILE__,
+ "tr.meta.help",
+ 0 /* no comment */,
+ run_test,
+ 0);
+}
Propchange: stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: stdcxx/branches/4.3.x/tests/utilities/20.meta.help.cpp
------------------------------------------------------------------------------
svn:keywords = Id