Commit 9480716c by Daniel Krugler Committed by Paolo Carlini

tuple (_Head_base<>::_M_head, [...]): Change to static constexpr functions; adjust everywhere.

2011-09-12  Daniel Krugler  <daniel.kruegler@googlemail.com>
	    Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/tuple (_Head_base<>::_M_head, _Head_base<>::_M_tail,
	_Tuple_impl<>::_M_head, _Tuple_impl<>::_M_tail): Change to static
	constexpr functions; adjust everywhere.
	(__get_helper, get): Declare constexpr all three overloads.
	(tuple_cat): Declare constexpr; use late return type to improve
	error messages.
	* include/std/utility (__pair_get<>::__get, __pair_get<>::__move_get,
	__pair_get<>::__const_get, get): Declare all constexpr.
	* include/std/array (get): Likewise.
	* testsuite/20_util/tuple/creation_functions/constexpr.cc: Re-enable
	tuple_cat test.
	* testsuite/23_containers/array/constexpr_get.cc: New.
	* testsuite/20_util/tuple/element_access/constexpr_get.cc: Likewise.
	* testsuite/20_util/pair/constexpr_get.cc: Likewise.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
	line number.

Co-Authored-By: Paolo Carlini <paolo.carlini@oracle.com>

From-SVN: r178799
parent e7397618
2011-09-12 Daniel Krugler <daniel.kruegler@googlemail.com>
Paolo Carlini <paolo.carlini@oracle.com>
* include/std/tuple (_Head_base<>::_M_head, _Head_base<>::_M_tail,
_Tuple_impl<>::_M_head, _Tuple_impl<>::_M_tail): Change to static
constexpr functions; adjust everywhere.
(__get_helper, get): Declare constexpr all three overloads.
(tuple_cat): Declare constexpr; use late return type to improve
error messages.
* include/std/utility (__pair_get<>::__get, __pair_get<>::__move_get,
__pair_get<>::__const_get, get): Declare all constexpr.
* include/std/array (get): Likewise.
* testsuite/20_util/tuple/creation_functions/constexpr.cc: Re-enable
tuple_cat test.
* testsuite/23_containers/array/constexpr_get.cc: New.
* testsuite/20_util/tuple/element_access/constexpr_get.cc: Likewise.
* testsuite/20_util/pair/constexpr_get.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
line number.
2011-09-12 Jason Merrill <jason@redhat.com> 2011-09-12 Jason Merrill <jason@redhat.com>
* testsuite/20_util/is_constructible/value-2.cc: Adjust * testsuite/20_util/is_constructible/value-2.cc: Adjust
......
...@@ -264,19 +264,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -264,19 +264,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ typedef _Tp type; }; { typedef _Tp type; };
template<std::size_t _Int, typename _Tp, std::size_t _Nm> template<std::size_t _Int, typename _Tp, std::size_t _Nm>
inline _Tp& constexpr _Tp&
get(array<_Tp, _Nm>& __arr) noexcept get(array<_Tp, _Nm>& __arr) noexcept
{ return __arr[_Int]; } { return __arr._M_instance[_Int]; }
template<std::size_t _Int, typename _Tp, std::size_t _Nm> template<std::size_t _Int, typename _Tp, std::size_t _Nm>
inline _Tp&& constexpr _Tp&&
get(array<_Tp, _Nm>&& __arr) noexcept get(array<_Tp, _Nm>&& __arr) noexcept
{ return std::move(get<_Int>(__arr)); } { return std::move(get<_Int>(__arr)); }
template<std::size_t _Int, typename _Tp, std::size_t _Nm> template<std::size_t _Int, typename _Tp, std::size_t _Nm>
inline const _Tp& constexpr const _Tp&
get(const array<_Tp, _Nm>& __arr) noexcept get(const array<_Tp, _Nm>& __arr) noexcept
{ return __arr[_Int]; } { return __arr._M_instance[_Int]; }
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace } // namespace
......
...@@ -105,17 +105,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -105,17 +105,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __pair_get<0> struct __pair_get<0>
{ {
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static _Tp1& static constexpr _Tp1&
__get(std::pair<_Tp1, _Tp2>& __pair) noexcept __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
{ return __pair.first; } { return __pair.first; }
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static _Tp1&& static constexpr _Tp1&&
__move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
{ return std::forward<_Tp1>(__pair.first); } { return std::forward<_Tp1>(__pair.first); }
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static const _Tp1& static constexpr const _Tp1&
__const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
{ return __pair.first; } { return __pair.first; }
}; };
...@@ -124,33 +124,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -124,33 +124,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __pair_get<1> struct __pair_get<1>
{ {
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static _Tp2& static constexpr _Tp2&
__get(std::pair<_Tp1, _Tp2>& __pair) noexcept __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
{ return __pair.second; } { return __pair.second; }
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static _Tp2&& static constexpr _Tp2&&
__move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
{ return std::forward<_Tp2>(__pair.second); } { return std::forward<_Tp2>(__pair.second); }
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static const _Tp2& static constexpr const _Tp2&
__const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
{ return __pair.second; } { return __pair.second; }
}; };
template<std::size_t _Int, class _Tp1, class _Tp2> template<std::size_t _Int, class _Tp1, class _Tp2>
inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type& constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
get(std::pair<_Tp1, _Tp2>& __in) noexcept get(std::pair<_Tp1, _Tp2>& __in) noexcept
{ return __pair_get<_Int>::__get(__in); } { return __pair_get<_Int>::__get(__in); }
template<std::size_t _Int, class _Tp1, class _Tp2> template<std::size_t _Int, class _Tp1, class _Tp2>
inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&& constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&&
get(std::pair<_Tp1, _Tp2>&& __in) noexcept get(std::pair<_Tp1, _Tp2>&& __in) noexcept
{ return __pair_get<_Int>::__move_get(std::move(__in)); } { return __pair_get<_Int>::__move_get(std::move(__in)); }
template<std::size_t _Int, class _Tp1, class _Tp2> template<std::size_t _Int, class _Tp1, class _Tp2>
inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type& constexpr const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
get(const std::pair<_Tp1, _Tp2>& __in) noexcept get(const std::pair<_Tp1, _Tp2>& __in) noexcept
{ return __pair_get<_Int>::__const_get(__in); } { return __pair_get<_Int>::__const_get(__in); }
......
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2011 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <utility>
std::pair<int, int> pi;
const std::pair<int, int> cpi;
constexpr const int& cri = std::get<0>(cpi);
constexpr int& ri = std::get<0>(pi);
constexpr int&& rri = std::get<0>(std::move(pi));
...@@ -63,7 +63,6 @@ test_get() ...@@ -63,7 +63,6 @@ test_get()
} }
// tuple_cat // tuple_cat
#if 0
void void
test_tuple_cat() test_tuple_cat()
{ {
...@@ -74,7 +73,6 @@ test_tuple_cat() ...@@ -74,7 +73,6 @@ test_tuple_cat()
constexpr tuple_type2 t2 { 55, 99, 77.77 }; constexpr tuple_type2 t2 { 55, 99, 77.77 };
constexpr auto cat1 = std::tuple_cat(t1, t2); constexpr auto cat1 = std::tuple_cat(t1, t2);
} }
#endif
int int
main() main()
...@@ -84,10 +82,7 @@ main() ...@@ -84,10 +82,7 @@ main()
#endif #endif
test_get(); test_get();
#if 0
test_tuple_cat(); test_tuple_cat();
#endif
return 0; return 0;
} }
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2011 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// Tuple
#include <tuple>
std::tuple<int> ti;
const std::tuple<int> cti;
constexpr const int& cri = std::get<0>(cti);
constexpr int& ri = std::get<0>(ti);
constexpr int&& rri = std::get<0>(std::move(ti));
...@@ -51,7 +51,7 @@ main() ...@@ -51,7 +51,7 @@ main()
// { dg-warning "note" "" { target *-*-* } 485 } // { dg-warning "note" "" { target *-*-* } 485 }
// { dg-warning "note" "" { target *-*-* } 479 } // { dg-warning "note" "" { target *-*-* } 479 }
// { dg-warning "note" "" { target *-*-* } 468 } // { dg-warning "note" "" { target *-*-* } 468 }
// { dg-warning "note" "" { target *-*-* } 831 } // { dg-warning "note" "" { target *-*-* } 840 }
// { dg-warning "note" "" { target *-*-* } 1056 } // { dg-warning "note" "" { target *-*-* } 1056 }
// { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 1050 }
// { dg-warning "note" "" { target *-*-* } 342 } // { dg-warning "note" "" { target *-*-* } 342 }
......
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2011 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// Tuple
#include <array>
std::array<int, 5> ai;
const std::array<int, 5> cai(ai);
constexpr const int& cri = std::get<0>(cai);
constexpr int& ri = std::get<0>(ai);
constexpr int&& rri = std::get<0>(std::move(ai));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment