Author: elemings
Date: Mon Jun 16 14:16:48 2008
New Revision: 668318
URL: http://svn.apache.org/viewvc?rev=668318&view=rev
Log:
2008-06-16 Eric Lemings <[EMAIL PROTECTED]>
STDCXX-958
* include/tuple, include/rw/_tuple.h, include/rw/_tuple_traits.h:
Add initial version of headers defining tuple interface and
implementation. (Only tested on Linux/gcc-4.3 platforms so far.)
* tests/utilities/20.tuple.cnstr.cpp: Rough outline of first
tuple test program.
Added:
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
Added: 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=668318&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_tuple.h (added)
+++ stdcxx/branches/4.3.x/include/rw/_tuple.h Mon Jun 16 14:16:48 2008
@@ -0,0 +1,209 @@
+// -*- C++ -*-
+/***************************************************************************
+ *
+ * _tuple.h - tuple class template and specializations
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $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.
+ *
+ **************************************************************************/
+
+#ifndef _RWSTD_RW_TUPLE_H_INCLUDED
+# define _RWSTD_RW_TUPLE_H_INCLUDED
+
+# if !defined _RWSTD_NO_EXT_CXX_0X
+
+# include <rw/_defs.h>
+# include <rw/_forward.h>
+# include <rw/_pair.h>
+
+# if !defined _RWSTD_NO_VARIADIC_TEMPLATES
+
+
+_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.
+ */
+template < class... Types >
+class tuple;
+
+/**
+ * @internal
+ * The template specialization for empty tuples.
+ */
+_RWSTD_SPECIALIZED_CLASS
+class tuple< >
+{
+ // empty
+};
+
+/**
+ * @internal
+ * The basic template specialization for most tuples. This class
+ * 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.
+ */
+template < class _HeadT, class... _TailT >
+class tuple< _HeadT, _TailT... >
+ : tuple< _TailT... >
+{
+ typedef tuple< _TailT... > _Base;
+
+protected:
+
+ _HeadT _C_head;
+
+public:
+
+ /**
+ * Construct tuple with default values.
+ */
+ tuple ()
+ : _C_head (), _Base () { /* 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 */ }
+
+ /**
+ * Copy assign tuple from a different tuple value.
+ * @param __tuple Another tuple value with same type.
+ */
+ tuple& operator= (const tuple& __tuple) {
+ _C_head = __tuple._C_head;
+ _Base::operator= (__tuple);
+ return *this;
+ }
+
+ _EXPLICIT
+ tuple (const _HeadT& __head, const _TailT&... __tail)
+ : _C_head (__head), _Base (__tail...) { /* empty */ }
+
+# if !defined _RWSTD_NO_RVALUE_REFERENCES
+
+ tuple (tuple&& __tuple)
+ : _C_head (std::move (__tuple._C_head))
+ , _Base (std::forward<_Base> (__tuple)) { /* empty */ }
+
+ tuple& operator= (tuple&& __tuple) {
+ _C_head = std::move (__tuple._C_head);
+ _Base::operator= (__tuple);
+ return *this;
+ }
+
+# endif // !defined _RWSTD_NO_RVALUE_REFERENCES
+
+# if !defined _RWSTD_NO_MEMBER_TEMPLATES
+
+ template <class _HeadU, class... _TailU>
+ tuple (const tuple<_HeadU, _TailU...>& __tuple);
+
+ template <class _HeadU, class... _TailU>
+ tuple& operator= (const tuple<_HeadU, _TailU...>& __tuple);
+
+# endif // !defined _RWSTD_NO_MEMBER_TEMPLATES
+
+# if !defined _RWSTD_NO_RVALUE_REFERENCES \
+ && !defined _RWSTD_NO_MEMBER_TEMPLATES
+
+ template <class _HeadU, class... _TailU>
+ _EXPLICIT tuple (_HeadU&& __head, _TailU&&... __tail);
+
+ template <class _HeadU, class... _TailU>
+ tuple (tuple<_HeadU, _TailU...>&& __tuple);
+
+ template <class _HeadU, class... _TailU>
+ tuple& operator= (tuple<_HeadU, _TailU...>&& __tuple);
+
+# endif // !defined _RWSTD_NO_RVALUE_REFERENCES
+ // && !defined _RWSTD_NO_MEMBER_TEMPLATES
+};
+
+
+# if !defined _RWSTD_NO_MEMBER_TEMPLATES
+
+template <class _TypeT1, class _TypeT2>
+class tuple<_TypeT1, _TypeT2>
+ : pair<_TypeT1, _TypeT2>
+{
+ typedef pair< _TypeT1, _TypeT2 > _Base;
+
+public:
+
+ tuple (): _Base () { /* empty */ }
+ tuple (const tuple& __tuple): _Base (__tuple) { /* empty */ }
+ tuple& operator= (const tuple& __tuple);
+
+ _EXPLICIT tuple (const _TypeT1& __t1, const _TypeT2& __t2);
+
+ template <class _TypeU1, class _TypeU2>
+ tuple (const pair<_TypeU1, _TypeU2>& __pair);
+
+ template <class _TypeU1, class _TypeU2>
+ tuple& operator= (const pair<_TypeU1, _TypeU2>& __pair);
+
+# if !defined _RWSTD_NO_RVALUE_REFERENCES
+
+ template <class _TypeU1, class _TypeU2>
+ tuple (pair<_TypeU1, _TypeU2>&& __pair);
+
+ template <class _TypeU1, class _TypeU2>
+ tuple& operator= (pair<_TypeU1, _TypeU2>&& __pair);
+
+# endif // !defined _RWSTD_NO_RVALUE_REFERENCES
+
+};
+
+# endif // !defined _RWSTD_NO_MEMBER_TEMPLATES
+
+
+} // namespace std
+
+
+# endif // !defined _RWSTD_NO_VARIADIC_TEMPLATES
+
+# endif // !defined _RWSTD_NO_EXT_CXX_0X
+
+#endif // _RWSTD_TUPLE_INCLUDED
+
Added: 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=668318&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/include/rw/_tuple_traits.h (added)
+++ stdcxx/branches/4.3.x/include/rw/_tuple_traits.h Mon Jun 16 14:16:48 2008
@@ -0,0 +1,88 @@
+// -*- C++ -*-
+/***************************************************************************
+ *
+ * _tuple_traits.h - allocator traits for <tuple> header
+ *
+ * $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.
+ *
+ **************************************************************************/
+
+#ifndef _RWSTD_RW_TUPLE_TRAITS_INCLUDED
+# define _RWSTD_RW_TUPLE_TRAITS_INCLUDED
+
+# if !defined _RWSTD_NO_EXT_CXX_0X \
+ && !defined _RWSTD_NO_VARIADIC_TEMPLATES
+
+# include <rw/_defs.h>
+# include <rw/_meta_help.h> // for __rw_true_type
+
+
+_RWSTD_NAMESPACE (std) {
+
+
+// [20.3.1.1] tuple traits
+
+template <class _Type, class _Alloc>
+struct uses_allocator;
+
+/**
+ * Allows tuple construction with an allocator. This trait informs
+ * 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).
+ */
+template <class... _Types, class _Alloc>
+struct uses_allocator<tuple<_Types...>, _Alloc>
+ : _RW::__rw_true_type
+{
+ // empty
+};
+
+
+template <class _Type>
+struct constructible_with_allocator_prefix;
+
+/**
+ * Allows tuple construction with an allocator prefix argument. This
+ * trait informs other library components that tuple can be constructed
+ * with an allocator preï¬x argument.
+ *
+ * @param _Types Type list of tuple.
+ */
+template <class... _Types>
+struct constructible_with_allocator_prefix<tuple<_Types...> >
+ : _RW::__rw_true_type
+{
+ // empty
+};
+
+
+} // namespace std
+
+
+# endif // !defined _RWSTD_NO_EXT_CXX_0X
+ // && !defined _RWSTD_NO_VARIADIC_TEMPLATES
+
+#endif // _RWSTD_RW_TUPLE_TRAITS_INCLUDED
Added: stdcxx/branches/4.3.x/include/tuple
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/tuple?rev=668318&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/include/tuple (added)
+++ stdcxx/branches/4.3.x/include/tuple Mon Jun 16 14:16:48 2008
@@ -0,0 +1,186 @@
+// -*- C++ -*-
+/***************************************************************************
+ *
+ * tuple - fixed-size collection of values with variable, heterogenous 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.
+ *
+ **************************************************************************/
+
+#if defined _RWSTD_NO_EXT_CXX_0X
+# error _RWSTD_NO_EXT_CXX_0X defined and C++0x header included
+#endif // defined _RWSTD_NO_EXT_CXX_0X
+
+#ifndef _RWSTD_TUPLE_INCLUDED
+# define _RWSTD_TUPLE_INCLUDED
+
+# include <rw/_tuple.h>
+# include <rw/_tuple_traits.h>
+
+
+_RWSTD_NAMESPACE (__rw) {
+
+struct __rw_ignore { /* empty */ };
+
+/// Transforms _Type into a suitable make_tuple() return type.
+template <class _Type>
+struct __rw_make_tuple {
+ /// @todo Deduce correct return type.
+ typedef _Type type;
+};
+
+} // namespace __rw
+
+
+_RWSTD_NAMESPACE (std) {
+
+
+// 20.3.3, tuple creation functions:
+
+const _RW::__rw_ignore ignore = _RW::__rw_ignore ();
+
+# if !defined _RWSTD_NO_VARIADIC_TEMPLATES
+
+# if !defined _RWSTD_NO_RVALUE_REFERNCES
+
+template <class... _Types>
+tuple<_TYPENAME _RW::__rw_make_tuple<_Types>::type...>
+make_tuple (_Types&&... __values);
+
+template <class... _TypesT, class... _TypesU>
+tuple<_TypesT..., _TypesU...>
+tuple_cat (tuple<_TypesT...>&& __x,
+ const tuple<_TypesU...>& __y);
+
+template <class... _TypesT, class... _TypesU>
+tuple<_TypesT..., _TypesU...>
+tuple_cat (const tuple<_TypesT...>& __x,
+ tuple<_TypesU...>&& __y);
+
+template <class... _TypesT, class... _TypesU>
+tuple<_TypesT..., _TypesU...>
+tuple_cat (tuple<_TypesT...>&& __x,
+ tuple<_TypesU...>&& __y);
+
+# endif // !defined _RWSTD_NO_RVALUE_REFERNCES
+
+template <class... _Types>
+tuple<_Types&...> tie (_Types&...);
+
+template <class... _TypesT, class... _TypesU>
+tuple<_TypesT..., _TypesU...>
+tuple_cat (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y);
+
+
+// 20.3.1.4, tuple helper classes:
+
+template <class>
+class tuple_size; // undefined
+
+template <class... _Types>
+class tuple_size<tuple<_Types...> >;
+
+template <int, class>
+class tuple_element; // undefined
+
+template <int _Index, class... _Types>
+class tuple_element<_Index, tuple<_Types...> >;
+
+
+// 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...>&);
+
+
+// 20.3.1.6, relational operators:
+
+template <class... _TypesT, class... _TypesU>
+bool operator== (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y);
+
+template <class... _TypesT, class... _TypesU>
+bool operator< (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y);
+
+/**
+ * @param __x Tuple value on LHS of operator.
+ * @param __y Tuple value on RHS of operator.
+ * @return !(__x == __y)
+ */
+template <class... _TypesT, class... _TypesU>
+bool operator!= (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y)
+{
+ return !(__x == __y);
+}
+
+/**
+ * @param __x Tuple value on LHS of operator.
+ * @param __y Tuple value on RHS of operator.
+ * @return __y < __x
+ */
+template <class... _TypesT, class... _TypesU>
+bool operator> (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y)
+{
+ return __y < __x;
+}
+
+
+/**
+ * @param __x Tuple value on LHS of operator.
+ * @param __y Tuple value on RHS of operator.
+ * @return !(__y < __x)
+ */
+template <class... _TypesT, class... _TypesU>
+bool operator<= (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y)
+{
+ return !(__y < __x);
+}
+
+/**
+ * @param __x Tuple value on LHS of operator.
+ * @param __y Tuple value on RHS of operator.
+ * @return !(__x < __y)
+ */
+template <class... _TypesT, class... _TypesU>
+bool operator>= (const tuple<_TypesT...>& __x,
+ const tuple<_TypesU...>& __y)
+{
+ return !(__x < __y);
+}
+
+
+# endif // !defined _RWSTD_NO_VARIADIC_TEMPLATES
+
+} // namespace std
+
+#endif // _RWSTD_TUPLE_INCLUDED
Added: 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=668318&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp (added)
+++ stdcxx/branches/4.3.x/tests/utilities/20.tuple.cnstr.cpp Mon Jun 16
14:16:48 2008
@@ -0,0 +1,122 @@
+/***************************************************************************
+ *
+ * 20.tuple.cnstr.cpp - tests exercising tuple constructors and other members
+ *
+ * $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.
+ *
+ **************************************************************************/
+
+#include <tuple>
+
+#include "20.tuple.h"
+
+/**************************************************************************/
+
+#include <rw_driver.h>
+
+static void
+test_default_ctor ()
+{
+ rw_info (0, __FILE__, __LINE__, "default constructor");
+
+ NullTuple null_tuple;
+ _RWSTD_UNUSED (null_tuple);
+
+ IntTuple int_tuple;
+ _RWSTD_UNUSED (int_tuple);
+
+ UserClass::reset_totals ();
+ UserTuple user_tuple;
+ _RWSTD_UNUSED (user_tuple);
+ rw_assert (UserClass::n_total_def_ctor_ == 1, __FILE__, __LINE__,
+ "tuple<UserClass>::tuple() called %d default ctors, "
+ "expected 1", UserClass::n_total_def_ctor_);
+
+ BigTuple big_tuple;
+ _RWSTD_UNUSED (big_tuple);
+
+ NestedTuple nested_tuple;
+ _RWSTD_UNUSED (nested_tuple);
+}
+
+/**************************************************************************/
+
+static void
+test_value_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);
+
+ UserClass::reset_totals ();
+ UserTuple ut1 (UserClass ());
+ 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
+*/
+}
+
+/**************************************************************************/
+
+static int
+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_homogenous_copy_assignment ();
+ //test_heterogenous_copy_assignment ();
+
+ //test_pair_copy_ctor ();
+ //test_pair_move_ctor ();
+ //test_pair_copy_assign ();
+ //test_pair_move_assign ();
+
+ //test_alloc_ctors ();
+
+ return 0;
+}
+
+/*extern*/ int
+main (int argc, char* argv [])
+{
+ return rw_test (argc, argv, __FILE__,
+ "[tuple.cnstr]", "20.3.1.2 Construction",
+ run_test, "", 0);
+}
+