Re: [v3] constexpr tuple

2011-09-08 Thread Christopher Jefferson

On 8 Sep 2011, at 18:34, Paolo Carlini wrote:

 On 09/07/2011 07:44 AM, Daniel Krügler wrote:
 Is tuple_cat now considered conforming?
 No, see:
 
 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50159
 By the way, Daniel, I was considering giving that issue a try, if you have 
 tips (or even more ;) about the implementation of the C++11 conforming 
 tuple_cat, I'm all ears…

This might be totally insane, but I believe that:

tuple_cat(tuple_cat(A,B), C) always equivalent to tuple_cat(A,B,C);

Therefore, how close would something like (warning, not even compiled)

templateclass _Tuple1, class _Tuple2, class… _Tuples
auto 
tuple_cat(_Tuple1 __t1, _Tuple2 __t2, _Tuples… __tuples)
- tuple_cat(tuple_cat(std::forward_Tuple1(__t1), 
std::forward_Tuple2(__t2)), 
std::forward_Tuples(__tuples)…)
{ tuple_cat(tuple_cat(std::forward_Tuple1(__t1), 
std::forward_Tuple2(__t2)), 
std::forward_Tuples(__tuples)…); }

I imagine that first return type unfortunately isn't valid, but it shouldn't be 
hard to glue together the list of template arguments.

Chris


Re: [v3] constexpr tuple

2011-09-08 Thread Marc Glisse

On Thu, 8 Sep 2011, Christopher Jefferson wrote:


This might be totally insane, but I believe that:

tuple_cat(tuple_cat(A,B), C) always equivalent to tuple_cat(A,B,C);


That's a fine way to find the return type, but for code, doesn't it 
generate many copies? I think I'd forward_as_tuple and use some magic 
indices to extract everything at once.


--
Marc Glisse


[v3] constexpr tuple

2011-09-06 Thread Benjamin Kosnik

Here's the tuple additions for constexpr now that it's ok to return
this. 

I'm not quite sure what to do with the get, tie, tuple_cat functions
given the current signatures. Is tuple_cat now considered conforming?
If so, certain signatures can be constexpr. 

tested x86/linux

benjamin2011-09-06  Benjamin Kosnik  b...@redhat.com

	* include/std/tuple (_Tuple_impl::_M_head, _M_tail): Mark constexpr.
	(tuple(tuple)): Same.
	(tuple(const tuple_UElements... __in)): Same.
	(tuple(tuple_UElements... __in)): Same.
	(tuple_cat(const tuple_TElements..., const tuple_UElements...)):
	Same.
	(get): Same.
	* include/std/array: Consolidate array::data usage.
	* testsuite/23_containers/array/requirements/constexpr_functions.cc: 
	Remove extra include.
	* testsuite/20_util/tuple/creation_functions/constexpr.cc: New.
	* testsuite/20_util/tuple/cons/constexpr-2.cc: Add tests.
	* testsuite/20_util/tuple/cons/constexpr-3.cc: Same.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust line numbers.

Index: include/std/tuple
===
--- include/std/tuple	(revision 178557)
+++ include/std/tuple	(working copy)
@@ -143,7 +143,7 @@
   _Head   
   _M_head() noexcept { return *this; }
 
-  const _Head 
+  constexpr const _Head 
   _M_head() const noexcept { return *this; }
 };
 
@@ -189,7 +189,7 @@
   _Head   
   _M_head() noexcept { return _M_head_impl; }
 
-  const _Head 
+  constexpr const _Head 
   _M_head() const noexcept { return _M_head_impl; }
 
   _Head _M_head_impl; 
@@ -248,13 +248,13 @@
   _Head
   _M_head() noexcept { return _Base::_M_head(); }
 
-  const _Head  
+  constexpr const _Head  
   _M_head() const noexcept { return _Base::_M_head(); }
 
   _Inherited   
   _M_tail() noexcept { return *this; }
 
-  const _Inherited 
+  constexpr const _Inherited 
   _M_tail() const noexcept { return *this; }
 
   constexpr _Tuple_impl()
@@ -280,7 +280,7 @@
 	_Base(std::forward_Head(__in._M_head())) { }
 
   templatetypename... _UElements
-_Tuple_impl(const _Tuple_impl_Idx, _UElements... __in)
+constexpr _Tuple_impl(const _Tuple_impl_Idx, _UElements... __in)
 	: _Inherited(__in._M_tail()), _Base(__in._M_head()) { }
 
   templatetypename _UHead, typename... _UTails
@@ -409,7 +409,7 @@
 
   constexpr tuple(const tuple) = default;
 
-  tuple(tuple) = default;
+  constexpr tuple(tuple) = default; 
 
   templatetypename... _UElements, typename = typename
 	enable_if__and_integral_constantbool, sizeof...(_UElements)
@@ -417,7 +417,7 @@
 			 __all_convertible__conv_typesconst _UElements...,
 	   __conv_types_Elements...
  ::value::type
-tuple(const tuple_UElements... __in)
+constexpr tuple(const tuple_UElements... __in)
 : _Inherited(static_castconst _Tuple_impl0, _UElements...(__in))
 { }
 
@@ -427,7 +427,7 @@
 			 __all_convertible__conv_types_UElements...,
 	   __conv_types_Elements...
 			 ::value::type
-tuple(tuple_UElements... __in)
+constexpr tuple(tuple_UElements... __in)
 : _Inherited(static_cast_Tuple_impl0, _UElements...(__in)) { }
 
   // Allocator-extended constructors.
@@ -548,18 +548,18 @@
 
   constexpr tuple(const tuple) = default;
 
-  tuple(tuple) = default;
+  constexpr tuple(tuple) = default;
 
   templatetypename _U1, typename _U2, typename = typename
 	enable_if__and_is_convertibleconst _U1, _T1,
 			 is_convertibleconst _U2, _T2::value::type
-tuple(const tuple_U1, _U2 __in)
+constexpr tuple(const tuple_U1, _U2 __in)
 	: _Inherited(static_castconst _Tuple_impl0, _U1, _U2(__in)) { }
 
   templatetypename _U1, typename _U2, typename = typename
 	   enable_if__and_is_convertible_U1, _T1,
 is_convertible_U2, _T2::value::type
-tuple(tuple_U1, _U2 __in)
+constexpr tuple(tuple_U1, _U2 __in)
 	: _Inherited(static_cast_Tuple_impl0, _U1, _U2(__in)) { }
 
   templatetypename _U1, typename _U2, typename = typename
@@ -571,7 +571,7 @@
   templatetypename _U1, typename _U2, typename = typename
 	   enable_if__and_is_convertible_U1, _T1,
 is_convertible_U2, _T2::value::type
- tuple(pair_U1, _U2 __in)
+ constexpr tuple(pair_U1, _U2 __in)
 	: _Inherited(std::forward_U1(__in.first),
 		 std::forward_U2(__in.second)) { }
 
@@ -752,7 +752,7 @@
 { return __t._M_head(); }
 
   templatestd::size_t __i, typename _Head, typename... _Tail
-inline typename __add_c_ref_Head::type
+inline constexpr typename __add_c_ref_Head::type
 __get_helper(const _Tuple_impl__i, _Head, _Tail... __t) noexcept
 { return __t._M_head(); }
 
@@ -767,7 +767,7 @@
 { return __get_helper__i(__t); }
 
   templatestd::size_t __i, typename... _Elements
-inline typename __add_c_ref
+inline constexpr typename 

Re: [v3] constexpr tuple

2011-09-06 Thread Daniel Krügler
2011/9/7 Benjamin Kosnik b...@redhat.com:

 Here's the tuple additions for constexpr now that it's ok to return
 this.

Btw.: I would have expected that you can make
__tuple_compare::__eq/__less also constexpr.

These are static functions, thus __tuple_compare
itself need not to be a literal type (Disclaimer: I did
not check all __tuple_compare specializations).

 Is tuple_cat now considered conforming?

No, see:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50159

 If so, certain signatures can be constexpr.

Yes.

- Daniel