Author: elemings
Date: Thu Jun 19 11:11:05 2008
New Revision: 669608
URL: http://svn.apache.org/viewvc?rev=669608&view=rev
Log:
2008-06-19 Eric Lemings <[EMAIL PROTECTED]>
STDCXX-958
* include/tuple: Implement and document tuple_element. Minor
doc changes for tuple_size.
* tests/utilities/20.tuple.h: Fix copyright date. Remove
(currently) unnecessary includes. Add macro for size of BigList.
* tests/utilities/20.tuple.helpers.cpp: Added new (complete and
working!) test for tuple helpers.
Added:
stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp
Modified:
stdcxx/branches/4.3.x/include/tuple
stdcxx/branches/4.3.x/tests/utilities/20.tuple.h
Modified: stdcxx/branches/4.3.x/include/tuple
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/tuple?rev=669608&r1=669607&r2=669608&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/tuple (original)
+++ stdcxx/branches/4.3.x/include/tuple Thu Jun 19 11:11:05 2008
@@ -98,29 +98,57 @@
// 20.3.1.4, tuple helper classes:
-template <class>
-class tuple_size; // undefined
-
/**
+ * @class tuple_size
+ *
* Determine number of element types in tuple. This compile-time
* integral constant wrapper determines the number of element types in
* a tuple. The class template is ill-formed for any non-tuple typle.
*
- * @tparam _Types List of element types in tuple.
+ * @tparam Types List of element types in tuple.
*/
+
+template <class Types>
+class tuple_size;
+
template <class... _Types>
class tuple_size< tuple<_Types...> >
- : _RW::__rw_integral_constant< _RWSTD_SIZE_T, sizeof... (_Types) >
+ : public _RW::__rw_integral_constant< _RWSTD_SIZE_T,
+ sizeof... (_Types) >
{
// empty
};
-template <int, class>
-class tuple_element; // undefined
+/**
+ * @class tuple_element
+ *
+ * Determine the Nth element type of a tuple. Instances of this class
+ * class template provide a type member that identifies the Nth element
+ * type of a tuple \c T where 0 <= N <
+ * <code>tuple_size<T>::value</code>. If N is not in this range
+ * or for any other arbitrary type, the program is ill-formed.
+ *
+ * @tparam Index An integer constant.
+ * @tparam Types List of element types in the tuple.
+ */
+
+template <int Index, class... Types>
+struct tuple_element;
+
+template <class _Head, class... _Tail>
+struct tuple_element<0, tuple<_Head, _Tail...> >
+{
+ /** The Nth element type of the tuple. */
+ typedef _Head type;
+};
-template <int _Index, class... _Types>
-class tuple_element<_Index, tuple<_Types...> >;
+template <int _Index, class _Head, class... _Tail>
+struct tuple_element<_Index, tuple<_Head, _Tail...> >
+ : tuple_element<_Index - 1, tuple<_Tail...> >
+{
+ // empty
+};
// 20.3.1.5, element access:
Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.h
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.h?rev=669608&r1=669607&r2=669608&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.tuple.h (original)
+++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.h Thu Jun 19 11:11:05 2008
@@ -1,6 +1,6 @@
/***************************************************************************
*
- * 20.tuple.h - common support for all tuple tests
+ * 20.tuple.h - framework for tuple tests
*
* $Id$
*
@@ -22,7 +22,7 @@
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
- * Copyright 1994-2008 Rogue Wave Software.
+ * Copyright 2008 Rogue Wave Software.
*
**************************************************************************/
@@ -31,10 +31,7 @@
#include <tuple>
-#include <rw/_meta_prop.h>
-
-#include <rw_driver.h>
-#include <rw_value.h>
+#include <rw_value.h> // for UserClass
// various tuple types for test purposes
@@ -47,6 +44,7 @@
typedef std::tuple < std::tuple < int > > NestedTuple;
#define BigList bool, char, int, double, void*, UserClass
+#define BigListSize 6
typedef std::tuple < BigList > BigTuple;
Added: stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp?rev=669608&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp (added)
+++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.helpers.cpp Thu Jun 19
11:11:05 2008
@@ -0,0 +1,155 @@
+/***************************************************************************
+ *
+ * 20.tuple.helpers.cpp - tests exercising tuple helpers
+ *
+ * $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.
+ *
+ **************************************************************************/
+
+#include <tuple>
+
+#include "20.tuple.h"
+
+/**************************************************************************/
+
+#include <rw_driver.h>
+
+static void
+test_tuple_size ()
+{
+ rw_info (0, __FILE__, __LINE__, "tuple_size");
+
+ using std::tuple_size;
+
+ rw_assert (tuple_size<EmptyTuple>::value == 0, __FILE__, __LINE__,
+ "tuple_size<EmptyTuple>::value != 0");
+
+ rw_assert (tuple_size<IntTuple>::value == 1, __FILE__, __LINE__,
+ "tuple_size<IntTuple>::value != 1");
+ rw_assert (tuple_size<ConstIntTuple>::value == 1, __FILE__, __LINE__,
+ "tuple_size<ConstIntTuple>::value != 1");
+ rw_assert (tuple_size<UserTuple>::value == 1, __FILE__, __LINE__,
+ "tuple_size<UserTuple>::value != 1");
+ rw_assert (tuple_size<NestedTuple>::value == 1, __FILE__, __LINE__,
+ "tuple_size<NestedTuple>::value != 1");
+
+ rw_assert (tuple_size<PairTuple>::value == 2, __FILE__, __LINE__,
+ "tuple_size<Tuple>::value == 2");
+
+ rw_assert (tuple_size<BigTuple>::value == BigListSize,
+ __FILE__, __LINE__, "tuple_size<>::value == 0");
+}
+
+/**************************************************************************/
+
+#include <type_traits> // for is_same
+
+#include <rw_any.h>
+
+class any_t : public rw_any_t
+{
+private:
+ enum {
+ inherited,
+ const_int,
+ user_class,
+ int_tuple
+ } type_id;
+
+public:
+
+ template <class Type>
+ any_t (Type)
+ : rw_any_t (Type ()), type_id (inherited) { }
+
+ any_t (const int)
+ : rw_any_t (char ()), type_id (const_int) { }
+
+ any_t (UserClass)
+ : rw_any_t (char ()), type_id (user_class) { }
+
+ any_t (std::tuple< int >)
+ : rw_any_t (char ()), type_id (int_tuple) { }
+
+ const char* type_name () const
+ {
+ return type_id == const_int? "const int":
+ type_id == user_class? "UserClass":
+ type_id == int_tuple? "std::tuple<int>":
+ rw_any_t::type_name ();
+ }
+};
+
+static void
+test_tuple_element ()
+{
+ rw_info (0, __FILE__, __LINE__, "tuple_element");
+
+ using std::is_same;
+ using std::tuple_element;
+
+#define TYPE_NAME(T) \
+ (any_t (T ())).type_name ()
+
+#define TEST(N, T, E) \
+ typedef tuple_element<N, T>::type T ## N; \
+ rw_assert (is_same<T ## N, E>::value, __FILE__, __LINE__, \
+ "tuple_element<0, " #T ">::type, got type \"%s\", " \
+ "expected type \"" #E "\"", TYPE_NAME (T##N))
+
+ TEST (0, IntTuple, int);
+ TEST (0, ConstIntTuple, const int);
+ TEST (0, NestedTuple, std::tuple<int>);
+ TEST (0, UserTuple, UserClass);
+
+ TEST (0, PairTuple, long);
+ TEST (1, PairTuple, const char*);
+
+ TEST (0, BigTuple, bool);
+ TEST (1, BigTuple, char);
+ TEST (2, BigTuple, int);
+ TEST (3, BigTuple, double);
+ TEST (4, BigTuple, void*);
+ TEST (5, BigTuple, UserClass);
+}
+
+/**************************************************************************/
+
+static int
+run_test (int /*argc*/, char* /*argv*/ [])
+{
+ test_tuple_size ();
+ test_tuple_element ();
+
+ return 0;
+}
+
+/*extern*/ int
+main (int argc, char* argv [])
+{
+ return rw_test (argc, argv, __FILE__,
+ "[tuple.helper]",
+ "20.3.1.4 Tuple helper classes",
+ run_test, "", 0);
+}
+