Author: elemings
Date: Thu Jun 19 15:09:13 2008
New Revision: 669723
URL: http://svn.apache.org/viewvc?rev=669723&view=rev
Log:
2008-06-19 Eric Lemings <[EMAIL PROTECTED]>
STDCXX-958
* include/rw/_meta_cv.h: Include <rw/_meta_comp.h> to define
__rw_is_reference trait.
* include/rw/_tuple.h (__get): Add new accessors to allow access
to head element value. Accessors are public but intended (and
undocumented) for internal use only.
* include/tuple (tuple_element): Added internal get() helpers.
(get): Implemented and documented.
* tests/utilities/20.tuple.elem.cpp: Added framework for new
(and incomplete) test for tuple element accessors.
Added:
stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp
Modified:
stdcxx/branches/4.3.x/include/rw/_meta_cv.h
stdcxx/branches/4.3.x/include/rw/_tuple.h
stdcxx/branches/4.3.x/include/tuple
Modified: stdcxx/branches/4.3.x/include/rw/_meta_cv.h
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/rw/_meta_cv.h?rev=669723&r1=669722&r2=669723&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_meta_cv.h (original)
+++ stdcxx/branches/4.3.x/include/rw/_meta_cv.h Thu Jun 19 15:09:13 2008
@@ -32,6 +32,7 @@
#include <rw/_defs.h>
#include <rw/_meta_cat.h>
+#include <rw/_meta_comp.h>
_RWSTD_NAMESPACE (__rw) {
Modified: stdcxx/branches/4.3.x/include/rw/_tuple.h
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/rw/_tuple.h?rev=669723&r1=669722&r2=669723&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_tuple.h (original)
+++ stdcxx/branches/4.3.x/include/rw/_tuple.h Thu Jun 19 15:09:13 2008
@@ -103,6 +103,9 @@
public:
+ _HeadT& __get () { return _C_head; }
+ const _HeadT& __get () const { return _C_head; }
+
/**
* Construct tuple with default values.
*/
Modified: stdcxx/branches/4.3.x/include/tuple
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/tuple?rev=669723&r1=669722&r2=669723&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/tuple (original)
+++ stdcxx/branches/4.3.x/include/tuple Thu Jun 19 15:09:13 2008
@@ -36,7 +36,10 @@
# error _RWSTD_NO_EXT_CXX_0X defined and C++0x header included
# endif // defined _RWSTD_NO_EXT_CXX_0X
+# include <rw/_meta_cv.h> // for __rw_add_const
# include <rw/_meta_help.h> // for __rw_integral_constant
+# include <rw/_meta_ref.h> // for __rw_add_lvalue_reference
+
# include <rw/_tuple.h>
# include <rw/_tuple_traits.h>
@@ -129,7 +132,7 @@
* <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 Index An integer constant indicating the Nth element type.
* @tparam Types List of element types in the tuple.
*/
@@ -141,6 +144,27 @@
{
/** The Nth element type of the tuple. */
typedef _Head type;
+
+
+ typedef tuple<_Head, _Tail...> _Tuple;
+
+# define _RWSTD_ADD_CONST(T) \
+ _TYPENAME _RW::__rw_add_const<T>::type
+# define _RWSTD_ADD_LVAL_REF(T) \
+ _TYPENAME _RW::__rw_add_lvalue_reference<T>::type
+
+ typedef _RWSTD_ADD_CONST (_Head) _Const;
+ typedef _RWSTD_ADD_LVAL_REF (_Head) _Ref;
+ typedef _RWSTD_ADD_LVAL_REF (_Const) _ConstRef;
+
+# undef _RWSTD_ADD_CONST
+# undef _RWSTD_ADD_LVAL_REF
+
+ static _Ref
+ __get (_Tuple& __tuple) { return __tuple.__get (); }
+
+ static _ConstRef
+ __get (const _Tuple& __tuple) { return __tuple.__get (); }
};
template <int _Index, class _Head, class... _Tail>
@@ -153,13 +177,35 @@
// 20.3.1.5, element access:
-template <int _Index, class... _Types>
-_TYPENAME tuple_element<_Index, tuple<_Types...> >::type&
-get (tuple<_Types...>&);
-
-template <int _Index, class ... _Types>
-_TYPENAME tuple_element<_Index, tuple<_Types...> >::type const&
-get (const tuple<_Types...>&);
+/**
+ * @function get
+ *
+ * Access Nth element value of a tuple. This function returns a
+ * cv-qualified value reference to the Nth element in a tuple \c T
+ * where 0 <= N < <code>tuple_size<T>::value</code>. If N is
+ * not in this range, the program is ill-formed.
+ *
+ * @tparam Index An integer constant indicating the Nth element type.
+ * @tparam Types List of element types in the tuple.
+ * @param tuple A tuple value.
+ * @return CV-qualified reference to the Nth element value of tuple.
+ */
+
+template <int _Index, class _Head, class... _Tail>
+_TYPENAME tuple_element<_Index, tuple<_Head, _Tail...> >::_Ref
+get (tuple<_Head, _Tail...>& __tuple)
+{
+ typedef tuple_element<_Index, tuple<_Head, _Tail...> > _Tuple;
+ return _Tuple::__get (__tuple);
+}
+
+template <int _Index, class _Head, class... _Tail>
+_TYPENAME tuple_element<_Index, tuple<_Head, _Tail...> >::_ConstRef
+get (const tuple<_Head, _Tail...>& __tuple)
+{
+ typedef tuple_element<_Index, tuple<_Head, _Tail...> > _Tuple;
+ return _Tuple::__get (__tuple);
+}
// 20.3.1.6, relational operators:
Added: stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp?rev=669723&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp (added)
+++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.elem.cpp Thu Jun 19 15:09:13
2008
@@ -0,0 +1,75 @@
+/***************************************************************************
+ *
+ * 20.tuple.elem.cpp - tests exercising tuple element accessors
+ *
+ * $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_get ()
+{
+ rw_info (0, __FILE__, __LINE__, "get");
+
+ IntTuple it (4);
+ rw_assert (std::get<0> (it) == 4, __FILE__, __LINE__,
+ "get<0> (it), got %d, expected 4", std::get<0> (it));
+}
+
+/**************************************************************************/
+
+static void
+test_const_get ()
+{
+ rw_info (0, __FILE__, __LINE__, "get (const)");
+
+}
+
+/**************************************************************************/
+
+static int
+run_test (int /*unused*/, char* /*unused*/ [])
+{
+ test_get ();
+ test_const_get ();
+
+ return 0;
+}
+
+/*extern*/ int
+main (int argc, char* argv [])
+{
+ return rw_test (argc, argv, __FILE__,
+ "[tuple.elem]",
+ "20.3.1.5 Element access",
+ run_test, "", 0);
+}
+