Author: elemings
Date: Tue Jun 17 14:03:43 2008
New Revision: 668829
URL: http://svn.apache.org/viewvc?rev=668829&view=rev
Log:
2008-06-17 Eric Lemings <[EMAIL PROTECTED]>
STDCXX-958
* include/tuple (tuple_size): Implemented and documented.
* include/rw/_tuple_traits.h: Corrected documentation for
grouping and template parameters.
* include/rw/_forward.h: Likewise.
* include/rw/_tuple.h: Likewise. Also, corrected/implemented,
documented more constructors and operators.
* tests/utilities/20.tuple.h: Added missing header.
* tests/utilities/20.tuple.cnstr.cpp: Added more constructor,
operator tests.
Added:
stdcxx/branches/4.3.x/tests/utilities/20.tuple.h
Modified:
stdcxx/branches/4.3.x/include/rw/_forward.h
stdcxx/branches/4.3.x/include/rw/_tuple.h
stdcxx/branches/4.3.x/include/rw/_tuple_traits.h
stdcxx/branches/4.3.x/include/tuple
stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp
Modified: stdcxx/branches/4.3.x/include/rw/_forward.h
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/rw/_forward.h?rev=668829&r1=668828&r2=668829&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_forward.h (original)
+++ stdcxx/branches/4.3.x/include/rw/_forward.h Tue Jun 17 14:03:43 2008
@@ -49,7 +49,7 @@
* correct move/forwarding semantics, usually in the \c std::forward()
* function.
*
- * @param _Type Any type. No restrictions or requirements.
+ * @tparam _Type Any type. No restrictions or requirements.
* @see std::forward
*/
template <class _Type>
@@ -78,7 +78,7 @@
* is used to ensure that the appropriate reference type is used in move
* semantics.
*
- * @param _Type An lvalue or rvalue reference type.
+ * @tparam _Type An lvalue or rvalue reference type.
* @param __x An lvalue reference or rvalue reference.
* @returns An lvalue if __x is an lvalue reference; otherwise, an rvalue.
*/
@@ -95,6 +95,7 @@
* explicitly bind constructors and other functions with rvalue
* references that employ move semantics.
*
+ * @tparam _Type Any type. No requirements or restrictions.
* @param __x An lvalue or rvalue.
* @returns Same value as parameter with rvalue reference type.
*/
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=668829&r1=668828&r2=668829&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_tuple.h (original)
+++ stdcxx/branches/4.3.x/include/rw/_tuple.h Tue Jun 17 14:03:43 2008
@@ -42,29 +42,37 @@
# if !defined _RWSTD_NO_VARIADIC_TEMPLATES
+/// @defgroup tuple Tuples [tuple]
+/// @{
+
_RWSTD_NAMESPACE (std) {
// 20.3.1, class template tuple:
/**
- * @defgroup tuple Tuples [tuple]
- *
* A fixed-size collection of values with variable, heterogenous types.
* This class template is used to instantatiate tuple types. A tuple
* type specifies zero or more element types for defining tuple values.
* A tuple value can be constructed from a tuple type that holds one
* value for each element type in the tuple.
*
- * @param Types A list of zero or more types. No applicable type
- * requirements or restrictions.
+ * By definition, a homogenous tuple is a tuple that has the exact same
+ * number and type of elements as another tuple type. A heterogenous
+ * tuple is just the opposite: a tuple type that has either a different
+ * number of element types or one or more different element types.
+ *
+ * @tparam Types A list of zero or more types. No applicable type
+ * requirements or restrictions.
*/
template < class... Types >
class tuple;
/**
* @internal
- * The template specialization for empty tuples.
+ * The template specialization for empty tuples. This specialization
+ * also serves as the terminating instantiation of a recursive tuple
+ * with one or more element types.
*/
_RWSTD_SPECIALIZED_CLASS
class tuple< >
@@ -78,8 +86,8 @@
* template is used to instantiate all tuple types except for empty
* tuples and tuples with exactly two element types.
*
- * @param _HeadT First element type (required).
- * @param _TailT Template parameter pack for remaining element types.
+ * @tparam _HeadT First element type (required).
+ * @tparam _TailT Zero or more additional element types.
*/
template < class _HeadT, class... _TailT >
class tuple< _HeadT, _TailT... >
@@ -97,38 +105,61 @@
* Construct tuple with default values.
*/
tuple ()
- : _C_head (), _Base () { /* empty */ }
+ : _Base (), _C_head () { /* empty */ }
/**
* Copy construct tuple from a different tuple value.
* @param __tuple Another tuple value with same type.
*/
tuple (const tuple& __tuple)
- : _C_head (__tuple._C_head), _Base (__tuple) { /* empty */ }
+ : _Base (__tuple), _C_head (__tuple._C_head) { /* empty */ }
/**
* Copy assign tuple from a different tuple value.
+ * @param __tuple Some other tuple value.
* @param __tuple Another tuple value with same type.
+ * @return This tuple value.
*/
tuple& operator= (const tuple& __tuple) {
- _C_head = __tuple._C_head;
_Base::operator= (__tuple);
+ _C_head = __tuple._C_head;
return *this;
}
+ /**
+ * Copy construct tuple from element values. This explicit
+ * constructor creates a tuple value from element values.
+ *
+ * @param __head A value corresponding to first tuple element type.
+ * @param __tail List of corresponding values of remaining tuple
+ * element types.
+ */
_EXPLICIT
tuple (const _HeadT& __head, const _TailT&... __tail)
- : _C_head (__head), _Base (__tail...) { /* empty */ }
+ : _Base (__tail...), _C_head (__head) { /* empty */ }
# if !defined _RWSTD_NO_RVALUE_REFERENCES
+ /**
+ * Construct tuple by moving a value from some other tuple value.
+ * This move constructor moves the value from the given tuple value
+ * into this tuple.
+ * @param __tuple Some other homogenous tuple value.
+ */
tuple (tuple&& __tuple)
- : _C_head (std::move (__tuple._C_head))
- , _Base (std::forward<_Base> (__tuple)) { /* empty */ }
+ : _Base (std::forward<_Base> (__tuple))
+ , _C_head (_RWSTD_MOVE (__tuple._C_head)) { /* empty */ }
+ /**
+ * Assign tuple by moving a value from some other tuple value.
+ * This assignment operator moves the value from the given tuple
+ * value into this tuple.
+ * @param __tuple Some other homogenous tuple value.
+ * @returns Lvalue reference to this tuple value.
+ */
tuple& operator= (tuple&& __tuple) {
- _C_head = std::move (__tuple._C_head);
_Base::operator= (__tuple);
+ _C_head = _RWSTD_MOVE (__tuple._C_head);
return *this;
}
@@ -136,11 +167,33 @@
# if !defined _RWSTD_NO_MEMBER_TEMPLATES
+ /**
+ * Construct tuple by copying a heterogenous tuple value. This copy
+ * constructor copies the value from a compatible, heterogenous
+ * tuple.
+ * @tparam _HeadU First element type in tuple.
+ * @tparam _TailU Remaining element types in tuple.
+ * @param __tuple A compatible, heterogenous tuple value.
+ */
template <class _HeadU, class... _TailU>
- tuple (const tuple<_HeadU, _TailU...>& __tuple);
+ tuple (const tuple<_HeadU, _TailU...>& __tuple)
+ : _Base (__tuple), _C_head (__tuple._C_head) { /* empty */ }
+ /**
+ * Assign tuple by copying a heterogenous tuple value. This
+ * assignment operator copies the value from a compatible,
+ * heterogenous tuple.
+ * @tparam _HeadU First element type in tuple.
+ * @tparam _TailU Remaining element types in tuple.
+ * @param __tuple A compatible, heterogenous tuple value.
+ * @returns Lvalue reference to this tuple value.
+ */
template <class _HeadU, class... _TailU>
- tuple& operator= (const tuple<_HeadU, _TailU...>& __tuple);
+ tuple& operator= (const tuple<_HeadU, _TailU...>& __tuple) {
+ _Base::operator= (__tuple);
+ _C_head = __tuple._C_head;
+ return *this;
+ }
# endif // !defined _RWSTD_NO_MEMBER_TEMPLATES
@@ -163,33 +216,61 @@
# if !defined _RWSTD_NO_MEMBER_TEMPLATES
-template <class _TypeT1, class _TypeT2>
-class tuple<_TypeT1, _TypeT2>
- : pair<_TypeT1, _TypeT2>
+/**
+ * @internal
+ * Template specialization for tuples with exactly two element types.
+ * This specialization provides additional constructors and operators for
+ * making class template \c std::pair implicitly compatible with tuples.
+ * @tparam _TypeT1 First element type.
+ * @tparam _TypeT2 Second element type.
+ */
+template < class _TypeT1, class _TypeT2 >
+class tuple< _TypeT1, _TypeT2 >
{
- typedef pair< _TypeT1, _TypeT2 > _Base;
+ _TypeT1 _C_first;
+ _TypeT2 _C_second;
public:
- tuple (): _Base () { /* empty */ }
- tuple (const tuple& __tuple): _Base (__tuple) { /* empty */ }
- tuple& operator= (const tuple& __tuple);
+ tuple (): _C_first (), _C_second () { /* empty */ }
+
+ tuple (const tuple& __tuple)
+ : _C_first (__tuple._C_first)
+ , _C_second (__tuple._C_second) { /* empty */ }
+
+ tuple& operator= (const tuple& __tuple) {
+ _C_first = __tuple._C_first;
+ _C_second = __tuple._C_second;
+ return *this;
+ }
- _EXPLICIT tuple (const _TypeT1& __t1, const _TypeT2& __t2);
+ _EXPLICIT tuple (const _TypeT1& __t1, const _TypeT2& __t2)
+ : _C_first (__t1), _C_second (__t2) { /* empty */ }
template <class _TypeU1, class _TypeU2>
- tuple (const pair<_TypeU1, _TypeU2>& __pair);
+ tuple (const pair<_TypeU1, _TypeU2>& __pair)
+ : _C_first (__pair.first), _C_second (__pair.second) { /* empty */ }
template <class _TypeU1, class _TypeU2>
- tuple& operator= (const pair<_TypeU1, _TypeU2>& __pair);
+ tuple& operator= (const pair<_TypeU1, _TypeU2>& __pair) {
+ _C_first = __pair.first;
+ _C_second = __pair.second;
+ return *this;
+ }
# if !defined _RWSTD_NO_RVALUE_REFERENCES
template <class _TypeU1, class _TypeU2>
- tuple (pair<_TypeU1, _TypeU2>&& __pair);
+ tuple (pair<_TypeU1, _TypeU2>&& __pair)
+ : _C_first (_RWSTD_MOVE (__pair.first))
+ , _C_second (_RWSTD_MOVE (__pair.second)) { /* empty */ }
template <class _TypeU1, class _TypeU2>
- tuple& operator= (pair<_TypeU1, _TypeU2>&& __pair);
+ tuple& operator= (pair<_TypeU1, _TypeU2>&& __pair) {
+ _C_first = _RWSTD_MOVE (__pair.first);
+ _C_second = _RWSTD_MOVE (__pair.second);
+ return *this;
+ }
# endif // !defined _RWSTD_NO_RVALUE_REFERENCES
@@ -198,6 +279,8 @@
# endif // !defined _RWSTD_NO_MEMBER_TEMPLATES
+/// @}
+
} // namespace std
Modified: stdcxx/branches/4.3.x/include/rw/_tuple_traits.h
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/rw/_tuple_traits.h?rev=668829&r1=668828&r2=668829&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_tuple_traits.h (original)
+++ stdcxx/branches/4.3.x/include/rw/_tuple_traits.h Tue Jun 17 14:03:43 2008
@@ -37,6 +37,9 @@
# include <rw/_meta_help.h> // for __rw_true_type
+/// @ingroup tuple
+/// @{
+
_RWSTD_NAMESPACE (std) {
@@ -50,8 +53,8 @@
* other library components that tuple can be constructed with an
* allocator even though it does not have a nested allocator_type.
*
- * @param _Types Type list of tuple.
- * @param _Alloc Must conform to Allocator requirements (20.1.2).
+ * @tparam _Types List of element types in tuple.
+ * @tparam _Alloc Must conform to Allocator requirements (20.1.2).
*/
template <class... _Types, class _Alloc>
struct uses_allocator<tuple<_Types...>, _Alloc>
@@ -69,7 +72,7 @@
* trait informs other library components that tuple can be constructed
* with an allocator preï¬x argument.
*
- * @param _Types Type list of tuple.
+ * @tparam _Types List of element types in tuple.
*/
template <class... _Types>
struct constructible_with_allocator_prefix<tuple<_Types...> >
@@ -79,6 +82,8 @@
};
+/// @}
+
} // namespace std
Modified: stdcxx/branches/4.3.x/include/tuple
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/tuple?rev=668829&r1=668828&r2=668829&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/tuple (original)
+++ stdcxx/branches/4.3.x/include/tuple Tue Jun 17 14:03:43 2008
@@ -34,6 +34,8 @@
#ifndef _RWSTD_TUPLE_INCLUDED
# define _RWSTD_TUPLE_INCLUDED
+# include <rw/_defs.h>
+# include <rw/_meta_help.h> // for __rw_integral_constant
# include <rw/_tuple.h>
# include <rw/_tuple_traits.h>
@@ -98,8 +100,20 @@
template <class>
class tuple_size; // undefined
+/**
+ * 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.
+ */
template <class... _Types>
-class tuple_size<tuple<_Types...> >;
+class tuple_size< tuple<_Types...> >
+ : _RW::__rw_integral_constant< _RWSTD_SIZE_T, sizeof... (_Types) >
+{
+ // empty
+};
+
template <int, class>
class tuple_element; // undefined
Modified: stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp?rev=668829&r1=668828&r2=668829&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp (original)
+++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp Tue Jun 17
14:03:43 2008
@@ -39,52 +39,91 @@
{
rw_info (0, __FILE__, __LINE__, "default constructor");
- NullTuple null_tuple;
- _RWSTD_UNUSED (null_tuple);
-
- IntTuple int_tuple;
- _RWSTD_UNUSED (int_tuple);
+ EmptyTuple et; _RWSTD_UNUSED (et);
+ IntTuple it; _RWSTD_UNUSED (it);
+ ConstIntTuple ct; _RWSTD_UNUSED (ct);
+ PairTuple pt; _RWSTD_UNUSED (pt);
+ NestedTuple nt; _RWSTD_UNUSED (nt);
+ BigTuple bt; _RWSTD_UNUSED (bt);
UserClass::reset_totals ();
- UserTuple user_tuple;
- _RWSTD_UNUSED (user_tuple);
+ UserTuple ut; _RWSTD_UNUSED (ut);
+
rw_assert (UserClass::n_total_def_ctor_ == 1, __FILE__, __LINE__,
"tuple<UserClass>::tuple() called %d default ctors, "
"expected 1", UserClass::n_total_def_ctor_);
+}
+
+/**************************************************************************/
+
+static void
+test_value_copy_ctor ()
+{
+ rw_info (0, __FILE__, __LINE__, "value copy constructor");
+
+ const int i = 1;
+ const IntTuple it (i);
+ ConstIntTuple ct (i); _RWSTD_UNUSED (ct);
+ NestedTuple nt (it);
+
+ const long l = 1;
+ const char* s = "string";
+ PairTuple pt (l, s);
+
+ UserClass::reset_totals ();
+ const UserClass uc;
+ UserTuple ut (uc); _RWSTD_UNUSED (ut);
+
+ rw_assert (1 == UserClass::n_total_def_ctor_, __FILE__, __LINE__,
+ "tuple<UserClass>::tuple() called %d default ctors, "
+ "expected 1", UserClass::n_total_def_ctor_);
+
+ const bool b = true; const char c = 'a';
+ const double d = 1.2; void* const p = 0;
+ BigTuple bt (b, c, i, d, p, uc); _RWSTD_UNUSED (bt);
+}
+
+/**************************************************************************/
- BigTuple big_tuple;
- _RWSTD_UNUSED (big_tuple);
+static void
+test_value_move_ctor ()
+{
+ rw_info (0, __FILE__, __LINE__, "value move constructor");
- NestedTuple nested_tuple;
- _RWSTD_UNUSED (nested_tuple);
}
/**************************************************************************/
static void
-test_value_ctor ()
+test_homo_copy_ctor ()
{
- rw_info (0, __FILE__, __LINE__, "value constructor");
-/*
- // stored values are verified by get() tests in 20.tuple.elem
- IntTuple it1 (1);
- _RWSTD_UNUSED (it1);
- int i1 = 1;
- IntTuple it2 (i1);
- _RWSTD_UNUSED (it2);
+ rw_info (0, __FILE__, __LINE__, "copy constructor (homogenous tuples)");
+
+ EmptyTuple et1, et2 (et1);
+ _RWSTD_UNUSED (et2);
+
+ const IntTuple it1;
+ IntTuple it2 (it1); _RWSTD_UNUSED (it2);
+
+ const ConstIntTuple ct1;
+ ConstIntTuple ct2 (ct1); _RWSTD_UNUSED (ct2);
+
+ PairTuple pt1;
+ PairTuple pt2 (pt1); _RWSTD_UNUSED (pt2);
+
+ const NestedTuple nt1;
+ NestedTuple nt2 (nt1); _RWSTD_UNUSED (nt2);
UserClass::reset_totals ();
- UserTuple ut1 (UserClass ());
+ const UserTuple ut1; UserTuple ut2 (ut1);
+ _RWSTD_UNUSED (ut1);
+
rw_assert (UserClass::n_total_def_ctor_ == 1, __FILE__, __LINE__,
"tuple<UserClass>::tuple() called %d default ctors, "
"expected 1", UserClass::n_total_def_ctor_);
- UserTuple ut1 (UserClass ());
- _RWSTD_UNUSED (ut1);
-
- // test constructor signature for reference and non-reference types
- // test return type for reference and non-reference types
-*/
+ const BigTuple bt1; //BigTuple bt2 (bt1);
+ _RWSTD_UNUSED (bt1); //_RWSTD_UNUSED (bt2);
}
/**************************************************************************/
@@ -93,14 +132,19 @@
run_test (int /*unused*/, char* /*unused*/ [])
{
test_default_ctor ();
- test_value_ctor ();
- //test_homogenous_copy_ctor ();
- //test_heterogenous_copy_ctor ();
- //test_pair_copy_ctor ();
+ test_value_copy_ctor ();
+ test_value_move_ctor ();
- //test_homogenous_copy_assignment ();
- //test_heterogenous_copy_assignment ();
+ test_homo_copy_ctor ();
+ //test_homo_move_ctor ();
+ //test_homo_copy_assign ();
+ //test_homo_move_assign ();
+
+ //test_hetero_copy_ctor ();
+ //test_hetero_move_ctor ();
+ //test_hetero_copy_assign ();
+ //test_hetero_move_assign ();
//test_pair_copy_ctor ();
//test_pair_move_ctor ();
Added: 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=668829&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.tuple.h (added)
+++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.h Tue Jun 17 14:03:43 2008
@@ -0,0 +1,54 @@
+/***************************************************************************
+ *
+ * 20.tuple.h - common support for all tuple tests
+ *
+ * $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 1994-2008 Rogue Wave Software.
+ *
+ **************************************************************************/
+
+#ifndef RW_20_TUPLE_H_INCLUDED
+#define RW_20_TUPLE_H_INCLUDED
+
+#include <tuple>
+
+#include <rw/_meta_prop.h>
+
+#include <rw_driver.h>
+#include <rw_value.h>
+
+
+// various tuple types for test purposes
+
+typedef std::tuple < > EmptyTuple;
+typedef std::tuple < int > IntTuple;
+typedef std::tuple < const int > ConstIntTuple;
+typedef std::tuple < long, const char* > PairTuple;
+typedef std::tuple < UserClass > UserTuple;
+typedef std::tuple < std::tuple < int > > NestedTuple;
+
+#define BigList bool, char, int, double, void*, UserClass
+
+typedef std::tuple < BigList > BigTuple;
+
+
+#endif // define RW_20_TUPLE_H_INCLUDED