Commit 06db9920 by Jonathan Wakely Committed by Jonathan Wakely

Add constexpr to <iterator> and <array> for C++17

	* include/bits/c++config (_GLIBCXX17_CONSTEXPR): Define.
	* include/bits/range_access.h (begin, end, rbegin, rend, crbegin)
	(crend): Add _GLIBCXX17_CONSTEXPR as per P0031R0.
	* include/bits/stl_iterator.h (reverse_iterator, move_iterator)
	(__make_reverse_iterator, make_reverse_iterator, make_move_iterator):
	Likewise.
	* include/bits/stl_iterator_base_funcs.h (__distance, __advance): Add
	_GLIBCXX14_CONSTEXPR.
	(distance, advance, next, prev): Add _GLIBCXX17_CONSTEXPR.
	* include/std/array (array::begin, array::end, array::rbegin)
	(array::rend, array::cbegin, array:cend, array::crbegin)
	(array::crend, array::operator[], array::at, array::front)
	(array::back, array::data): Likewise.
	* testsuite/24_iterators/headers/iterator/range_access.cc: Replace
	with separate tests for C++11, C++14, and C++17.
	* testsuite/24_iterators/headers/iterator/range_access_c++11.cc: New.
	* testsuite/24_iterators/headers/iterator/range_access_c++14.cc: New.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc: New.

From-SVN: r239690
parent 1135a133
2016-08-23 Jonathan Wakely <jwakely@redhat.com>
* include/bits/c++config (_GLIBCXX17_CONSTEXPR): Define.
* include/bits/range_access.h (begin, end, rbegin, rend, crbegin)
(crend): Add _GLIBCXX17_CONSTEXPR as per P0031R0.
* include/bits/stl_iterator.h (reverse_iterator, move_iterator)
(__make_reverse_iterator, make_reverse_iterator, make_move_iterator):
Likewise.
* include/bits/stl_iterator_base_funcs.h (__distance, __advance): Add
_GLIBCXX14_CONSTEXPR.
(distance, advance, next, prev): Add _GLIBCXX17_CONSTEXPR.
* include/std/array (array::begin, array::end, array::rbegin)
(array::rend, array::cbegin, array:cend, array::crbegin)
(array::crend, array::operator[], array::at, array::front)
(array::back, array::data): Likewise.
* testsuite/24_iterators/headers/iterator/range_access.cc: Replace
with separate tests for C++11, C++14, and C++17.
* testsuite/24_iterators/headers/iterator/range_access_c++11.cc: New.
* testsuite/24_iterators/headers/iterator/range_access_c++14.cc: New.
* testsuite/24_iterators/headers/iterator/range_access_c++17.cc: New.
2016-08-22 Tim Shen <timshen@google.com>
Split _M_dfs() into smaller functions.
......
......@@ -111,6 +111,14 @@
# endif
#endif
#ifndef _GLIBCXX17_CONSTEXPR
# if __cplusplus > 201402L
# define _GLIBCXX17_CONSTEXPR constexpr
# else
# define _GLIBCXX17_CONSTEXPR
# endif
#endif
// Macro for noexcept, to support in mixed 03/0x mode.
#ifndef _GLIBCXX_NOEXCEPT
# if __cplusplus >= 201103L
......
......@@ -48,7 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
begin(_Container& __cont) -> decltype(__cont.begin())
{ return __cont.begin(); }
......@@ -58,7 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
begin(const _Container& __cont) -> decltype(__cont.begin())
{ return __cont.begin(); }
......@@ -68,7 +68,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
end(_Container& __cont) -> decltype(__cont.end())
{ return __cont.end(); }
......@@ -78,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
end(const _Container& __cont) -> decltype(__cont.end())
{ return __cont.end(); }
......@@ -138,7 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
rbegin(_Container& __cont) -> decltype(__cont.rbegin())
{ return __cont.rbegin(); }
......@@ -148,7 +148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
rbegin(const _Container& __cont) -> decltype(__cont.rbegin())
{ return __cont.rbegin(); }
......@@ -158,7 +158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
rend(_Container& __cont) -> decltype(__cont.rend())
{ return __cont.rend(); }
......@@ -168,7 +168,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
rend(const _Container& __cont) -> decltype(__cont.rend())
{ return __cont.rend(); }
......@@ -178,7 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __arr Array.
*/
template<typename _Tp, size_t _Nm>
inline reverse_iterator<_Tp*>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*>
rbegin(_Tp (&__arr)[_Nm])
{ return reverse_iterator<_Tp*>(__arr + _Nm); }
......@@ -188,7 +188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __arr Array.
*/
template<typename _Tp, size_t _Nm>
inline reverse_iterator<_Tp*>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*>
rend(_Tp (&__arr)[_Nm])
{ return reverse_iterator<_Tp*>(__arr); }
......@@ -198,7 +198,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __il initializer_list.
*/
template<typename _Tp>
inline reverse_iterator<const _Tp*>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*>
rbegin(initializer_list<_Tp> __il)
{ return reverse_iterator<const _Tp*>(__il.end()); }
......@@ -208,7 +208,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __il initializer_list.
*/
template<typename _Tp>
inline reverse_iterator<const _Tp*>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*>
rend(initializer_list<_Tp> __il)
{ return reverse_iterator<const _Tp*>(__il.begin()); }
......@@ -218,7 +218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont))
{ return std::rbegin(__cont); }
......@@ -228,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __cont Container.
*/
template<typename _Container>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
crend(const _Container& __cont) -> decltype(std::rend(__cont))
{ return std::rend(__cont); }
......
......@@ -65,6 +65,10 @@
#include <bits/move.h>
#include <bits/ptr_traits.h>
#if __cplusplus > 201402L
# define __cpp_lib_array_constexpr 201603
#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
......@@ -118,17 +122,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 235 No specification of default ctor for reverse_iterator
_GLIBCXX17_CONSTEXPR
reverse_iterator() : current() { }
/**
* This %iterator will move in the opposite direction that @p x does.
*/
explicit
explicit _GLIBCXX17_CONSTEXPR
reverse_iterator(iterator_type __x) : current(__x) { }
/**
* The copy constructor is normal.
*/
_GLIBCXX17_CONSTEXPR
reverse_iterator(const reverse_iterator& __x)
: current(__x.current) { }
......@@ -137,13 +143,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* underlying %iterator can be converted to the type of @c current.
*/
template<typename _Iter>
_GLIBCXX17_CONSTEXPR
reverse_iterator(const reverse_iterator<_Iter>& __x)
: current(__x.base()) { }
/**
* @return @c current, the %iterator used for underlying work.
*/
iterator_type
_GLIBCXX17_CONSTEXPR iterator_type
base() const
{ return current; }
......@@ -157,7 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @c *x remains valid after @c x has been modified or
* destroyed. This is a bug: http://gcc.gnu.org/PR51823
*/
reference
_GLIBCXX17_CONSTEXPR reference
operator*() const
{
_Iterator __tmp = current;
......@@ -169,7 +176,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* This requires that @c --current is dereferenceable.
*/
pointer
_GLIBCXX17_CONSTEXPR pointer
operator->() const
{ return &(operator*()); }
......@@ -178,7 +185,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* Decrements the underlying iterator.
*/
reverse_iterator&
_GLIBCXX17_CONSTEXPR reverse_iterator&
operator++()
{
--current;
......@@ -190,7 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* Decrements the underlying iterator.
*/
reverse_iterator
_GLIBCXX17_CONSTEXPR reverse_iterator
operator++(int)
{
reverse_iterator __tmp = *this;
......@@ -203,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* Increments the underlying iterator.
*/
reverse_iterator&
_GLIBCXX17_CONSTEXPR reverse_iterator&
operator--()
{
++current;
......@@ -215,7 +222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* Increments the underlying iterator.
*/
reverse_iterator
_GLIBCXX17_CONSTEXPR reverse_iterator
operator--(int)
{
reverse_iterator __tmp = *this;
......@@ -228,7 +235,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* The underlying iterator must be a Random Access Iterator.
*/
reverse_iterator
_GLIBCXX17_CONSTEXPR reverse_iterator
operator+(difference_type __n) const
{ return reverse_iterator(current - __n); }
......@@ -238,7 +245,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Moves the underlying iterator backwards @a __n steps.
* The underlying iterator must be a Random Access Iterator.
*/
reverse_iterator&
_GLIBCXX17_CONSTEXPR reverse_iterator&
operator+=(difference_type __n)
{
current -= __n;
......@@ -250,7 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* The underlying iterator must be a Random Access Iterator.
*/
reverse_iterator
_GLIBCXX17_CONSTEXPR reverse_iterator
operator-(difference_type __n) const
{ return reverse_iterator(current + __n); }
......@@ -260,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Moves the underlying iterator forwards @a __n steps.
* The underlying iterator must be a Random Access Iterator.
*/
reverse_iterator&
_GLIBCXX17_CONSTEXPR reverse_iterator&
operator-=(difference_type __n)
{
current += __n;
......@@ -272,7 +279,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* The underlying iterator must be a Random Access Iterator.
*/
reference
_GLIBCXX17_CONSTEXPR reference
operator[](difference_type __n) const
{ return *(*this + __n); }
};
......@@ -288,49 +295,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
*/
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator==(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return __x.base() == __y.base(); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return __y.base() < __x.base(); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator!=(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return !(__x == __y); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return __y < __x; }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<=(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return !(__y < __x); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>=(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return !(__x < __y); }
template<typename _Iterator>
inline typename reverse_iterator<_Iterator>::difference_type
inline _GLIBCXX17_CONSTEXPR
typename reverse_iterator<_Iterator>::difference_type
operator-(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y)
{ return __y.base() - __x.base(); }
template<typename _Iterator>
inline reverse_iterator<_Iterator>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
operator+(typename reverse_iterator<_Iterator>::difference_type __n,
const reverse_iterator<_Iterator>& __x)
{ return reverse_iterator<_Iterator>(__x.base() - __n); }
......@@ -338,37 +346,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 280. Comparison of reverse_iterator to const reverse_iterator.
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator==(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
{ return __x.base() == __y.base(); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
{ return __y.base() < __x.base(); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator!=(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
{ return !(__x == __y); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
{ return __y < __x; }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<=(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
{ return !(__y < __x); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>=(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
{ return !(__x < __y); }
......@@ -376,7 +384,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _IteratorL, typename _IteratorR>
#if __cplusplus >= 201103L
// DR 685.
inline auto
inline _GLIBCXX17_CONSTEXPR auto
operator-(const reverse_iterator<_IteratorL>& __x,
const reverse_iterator<_IteratorR>& __y)
-> decltype(__y.base() - __x.base())
......@@ -391,7 +399,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
// Same as C++14 make_reverse_iterator but used in C++03 mode too.
template<typename _Iterator>
inline reverse_iterator<_Iterator>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
__make_reverse_iterator(_Iterator __i)
{ return reverse_iterator<_Iterator>(__i); }
......@@ -402,7 +410,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// DR 2285. make_reverse_iterator
/// Generator function for reverse_iterator.
template<typename _Iterator>
inline reverse_iterator<_Iterator>
inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
make_reverse_iterator(_Iterator __i)
{ return reverse_iterator<_Iterator>(__i); }
# endif
......@@ -1018,37 +1026,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typename remove_reference<__base_ref>::type&&,
__base_ref>::type reference;
_GLIBCXX17_CONSTEXPR
move_iterator()
: _M_current() { }
explicit
explicit _GLIBCXX17_CONSTEXPR
move_iterator(iterator_type __i)
: _M_current(__i) { }
template<typename _Iter>
_GLIBCXX17_CONSTEXPR
move_iterator(const move_iterator<_Iter>& __i)
: _M_current(__i.base()) { }
iterator_type
_GLIBCXX17_CONSTEXPR iterator_type
base() const
{ return _M_current; }
reference
_GLIBCXX17_CONSTEXPR reference
operator*() const
{ return static_cast<reference>(*_M_current); }
pointer
_GLIBCXX17_CONSTEXPR pointer
operator->() const
{ return _M_current; }
move_iterator&
_GLIBCXX17_CONSTEXPR move_iterator&
operator++()
{
++_M_current;
return *this;
}
move_iterator
_GLIBCXX17_CONSTEXPR move_iterator
operator++(int)
{
move_iterator __tmp = *this;
......@@ -1056,14 +1066,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __tmp;
}
move_iterator&
_GLIBCXX17_CONSTEXPR move_iterator&
operator--()
{
--_M_current;
return *this;
}
move_iterator
_GLIBCXX17_CONSTEXPR move_iterator
operator--(int)
{
move_iterator __tmp = *this;
......@@ -1071,29 +1081,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __tmp;
}
move_iterator
_GLIBCXX17_CONSTEXPR move_iterator
operator+(difference_type __n) const
{ return move_iterator(_M_current + __n); }
move_iterator&
_GLIBCXX17_CONSTEXPR move_iterator&
operator+=(difference_type __n)
{
_M_current += __n;
return *this;
}
move_iterator
_GLIBCXX17_CONSTEXPR move_iterator
operator-(difference_type __n) const
{ return move_iterator(_M_current - __n); }
move_iterator&
_GLIBCXX17_CONSTEXPR move_iterator&
operator-=(difference_type __n)
{
_M_current -= __n;
return *this;
}
reference
_GLIBCXX17_CONSTEXPR reference
operator[](difference_type __n) const
{ return std::move(_M_current[__n]); }
};
......@@ -1102,100 +1112,100 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// why there are always 2 versions for most of the move_iterator
// operators.
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator==(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
{ return __x.base() == __y.base(); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator==(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
{ return __x.base() == __y.base(); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator!=(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
{ return !(__x == __y); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator!=(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
{ return !(__x == __y); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
{ return __x.base() < __y.base(); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
{ return __x.base() < __y.base(); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<=(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
{ return !(__y < __x); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator<=(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
{ return !(__y < __x); }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
{ return __y < __x; }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
{ return __y < __x; }
template<typename _IteratorL, typename _IteratorR>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>=(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
{ return !(__x < __y); }
template<typename _Iterator>
inline bool
inline _GLIBCXX17_CONSTEXPR bool
operator>=(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
{ return !(__x < __y); }
// DR 685.
template<typename _IteratorL, typename _IteratorR>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
operator-(const move_iterator<_IteratorL>& __x,
const move_iterator<_IteratorR>& __y)
-> decltype(__x.base() - __y.base())
{ return __x.base() - __y.base(); }
template<typename _Iterator>
inline auto
inline _GLIBCXX17_CONSTEXPR auto
operator-(const move_iterator<_Iterator>& __x,
const move_iterator<_Iterator>& __y)
-> decltype(__x.base() - __y.base())
{ return __x.base() - __y.base(); }
template<typename _Iterator>
inline move_iterator<_Iterator>
inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
operator+(typename move_iterator<_Iterator>::difference_type __n,
const move_iterator<_Iterator>& __x)
{ return __x + __n; }
template<typename _Iterator>
inline move_iterator<_Iterator>
inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
make_move_iterator(_Iterator __i)
{ return move_iterator<_Iterator>(__i); }
......@@ -1203,7 +1213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
= typename conditional<__move_if_noexcept_cond
<typename iterator_traits<_Iterator>::value_type>::value,
_Iterator, move_iterator<_Iterator>>::type>
inline _ReturnType
inline _GLIBCXX17_CONSTEXPR _ReturnType
__make_move_if_noexcept_iterator(_Iterator __i)
{ return _ReturnType(__i); }
......@@ -1212,7 +1222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, typename _ReturnType
= typename conditional<__move_if_noexcept_cond<_Tp>::value,
const _Tp*, move_iterator<_Tp*>>::type>
inline _ReturnType
inline _GLIBCXX17_CONSTEXPR _ReturnType
__make_move_if_noexcept_iterator(_Tp* __i)
{ return _ReturnType(__i); }
......
......@@ -75,7 +75,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _InputIterator>
inline typename iterator_traits<_InputIterator>::difference_type
inline _GLIBCXX14_CONSTEXPR
typename iterator_traits<_InputIterator>::difference_type
__distance(_InputIterator __first, _InputIterator __last,
input_iterator_tag)
{
......@@ -92,7 +93,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _RandomAccessIterator>
inline typename iterator_traits<_RandomAccessIterator>::difference_type
inline _GLIBCXX14_CONSTEXPR
typename iterator_traits<_RandomAccessIterator>::difference_type
__distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
random_access_iterator_tag)
{
......@@ -131,7 +133,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* and are constant time. For other %iterator classes they are linear time.
*/
template<typename _InputIterator>
inline typename iterator_traits<_InputIterator>::difference_type
inline _GLIBCXX17_CONSTEXPR
typename iterator_traits<_InputIterator>::difference_type
distance(_InputIterator __first, _InputIterator __last)
{
// concept requirements -- taken care of in __distance
......@@ -140,7 +143,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _InputIterator, typename _Distance>
inline void
inline _GLIBCXX14_CONSTEXPR void
__advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
{
// concept requirements
......@@ -151,7 +154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _BidirectionalIterator, typename _Distance>
inline void
inline _GLIBCXX14_CONSTEXPR void
__advance(_BidirectionalIterator& __i, _Distance __n,
bidirectional_iterator_tag)
{
......@@ -167,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _RandomAccessIterator, typename _Distance>
inline void
inline _GLIBCXX14_CONSTEXPR void
__advance(_RandomAccessIterator& __i, _Distance __n,
random_access_iterator_tag)
{
......@@ -190,7 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* and are constant time. For other %iterator classes they are linear time.
*/
template<typename _InputIterator, typename _Distance>
inline void
inline _GLIBCXX17_CONSTEXPR void
advance(_InputIterator& __i, _Distance __n)
{
// concept requirements -- taken care of in __advance
......@@ -201,7 +204,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
template<typename _ForwardIterator>
inline _ForwardIterator
inline _GLIBCXX17_CONSTEXPR _ForwardIterator
next(_ForwardIterator __x, typename
iterator_traits<_ForwardIterator>::difference_type __n = 1)
{
......@@ -213,7 +216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _BidirectionalIterator>
inline _BidirectionalIterator
inline _GLIBCXX17_CONSTEXPR _BidirectionalIterator
prev(_BidirectionalIterator __x, typename
iterator_traits<_BidirectionalIterator>::difference_type __n = 1)
{
......
......@@ -122,51 +122,51 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ std::swap_ranges(begin(), end(), __other.begin()); }
// Iterators.
iterator
_GLIBCXX17_CONSTEXPR iterator
begin() noexcept
{ return iterator(data()); }
const_iterator
_GLIBCXX17_CONSTEXPR const_iterator
begin() const noexcept
{ return const_iterator(data()); }
iterator
_GLIBCXX17_CONSTEXPR iterator
end() noexcept
{ return iterator(data() + _Nm); }
const_iterator
_GLIBCXX17_CONSTEXPR const_iterator
end() const noexcept
{ return const_iterator(data() + _Nm); }
reverse_iterator
_GLIBCXX17_CONSTEXPR reverse_iterator
rbegin() noexcept
{ return reverse_iterator(end()); }
const_reverse_iterator
_GLIBCXX17_CONSTEXPR const_reverse_iterator
rbegin() const noexcept
{ return const_reverse_iterator(end()); }
reverse_iterator
_GLIBCXX17_CONSTEXPR reverse_iterator
rend() noexcept
{ return reverse_iterator(begin()); }
const_reverse_iterator
_GLIBCXX17_CONSTEXPR const_reverse_iterator
rend() const noexcept
{ return const_reverse_iterator(begin()); }
const_iterator
_GLIBCXX17_CONSTEXPR const_iterator
cbegin() const noexcept
{ return const_iterator(data()); }
const_iterator
_GLIBCXX17_CONSTEXPR const_iterator
cend() const noexcept
{ return const_iterator(data() + _Nm); }
const_reverse_iterator
_GLIBCXX17_CONSTEXPR const_reverse_iterator
crbegin() const noexcept
{ return const_reverse_iterator(end()); }
const_reverse_iterator
_GLIBCXX17_CONSTEXPR const_reverse_iterator
crend() const noexcept
{ return const_reverse_iterator(begin()); }
......@@ -181,7 +181,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
empty() const noexcept { return size() == 0; }
// Element access.
reference
_GLIBCXX17_CONSTEXPR reference
operator[](size_type __n) noexcept
{ return _AT_Type::_S_ref(_M_elems, __n); }
......@@ -189,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
operator[](size_type __n) const noexcept
{ return _AT_Type::_S_ref(_M_elems, __n); }
reference
_GLIBCXX17_CONSTEXPR reference
at(size_type __n)
{
if (__n >= _Nm)
......@@ -211,7 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_AT_Type::_S_ref(_M_elems, 0));
}
reference
_GLIBCXX17_CONSTEXPR reference
front() noexcept
{ return *begin(); }
......@@ -219,7 +219,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
front() const noexcept
{ return _AT_Type::_S_ref(_M_elems, 0); }
reference
_GLIBCXX17_CONSTEXPR reference
back() noexcept
{ return _Nm ? *(end() - 1) : *end(); }
......@@ -230,11 +230,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
: _AT_Type::_S_ref(_M_elems, 0);
}
pointer
_GLIBCXX17_CONSTEXPR pointer
data() noexcept
{ return _AT_Type::_S_ptr(_M_elems); }
const_pointer
_GLIBCXX17_CONSTEXPR const_pointer
data() const noexcept
{ return _AT_Type::_S_ptr(_M_elems); }
};
......
// { dg-do compile { target c++11 } }
// { dg-options "-std=gnu++11" }
// { dg-do compile }
// Copyright (C) 2010-2016 Free Software Foundation, Inc.
//
......@@ -27,11 +28,6 @@ namespace std
template<class C> auto end(C& c) -> decltype(c.end());
template<class C> auto end(const C& c) -> decltype(c.end());
#if __cplusplus >= 201402L
template<class T, size_t N> constexpr T* begin(T (&array)[N]);
template<class T, size_t N> constexpr T* end(T (&array)[N]);
#else
template<class T, size_t N> T* begin(T (&array)[N]);
template<class T, size_t N> T* end(T (&array)[N]);
#endif
}
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2016 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 <iterator>
namespace std
{
template<class C> auto begin(C& c) -> decltype(c.begin());
template<class C> auto begin(const C& c) -> decltype(c.begin());
template<class C> auto end(C& c) -> decltype(c.end());
template<class C> auto end(const C& c) -> decltype(c.end());
template<class T, size_t N> constexpr T* begin(T (&array)[N]);
template<class T, size_t N> constexpr T* end(T (&array)[N]);
template<class C> auto cbegin(const C& c) -> decltype(c.begin());
template<class C> auto cend(const C& c) -> decltype(c.end());
template<class C> auto rbegin(C& c) -> decltype(c.rbegin());
template<class C> auto rbegin(const C& c) -> decltype(c.rbegin());
template<class C> auto rend(C& c) -> decltype(c.rend());
template<class C> auto rend(const C& c) -> decltype(c.rend());
template<class T, size_t N>
reverse_iterator<T*> rbegin(T (&array)[N]);
template<class T, size_t N>
reverse_iterator<T*> rend(T (&array)[N]);
template<class E>
reverse_iterator<const E*> rbegin(initializer_list<E>);
template<class E>
reverse_iterator<const E*> rend(initializer_list<E>);
template<class C>
auto crbegin(const C& c) -> decltype(std::rbegin(c));
template<class C>
auto cend(const C& c) -> decltype(std::rend(c));
}
// { dg-options "-std=gnu++17" }
// { dg-do compile }
// Copyright (C) 2016 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 <iterator>
namespace std
{
template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
template<class C> constexpr auto end(C& c) -> decltype(c.end());
template<class C> constexpr auto end(const C& c) -> decltype(c.end());
template<class T, size_t N> constexpr T* begin(T (&array)[N]);
template<class T, size_t N> constexpr T* end(T (&array)[N]);
template<class C> constexpr auto cbegin(const C& c) -> decltype(c.begin());
template<class C> constexpr auto cend(const C& c) -> decltype(c.end());
template<class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin());
template<class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin());
template<class C> constexpr auto rend(C& c) -> decltype(c.rend());
template<class C> constexpr auto rend(const C& c) -> decltype(c.rend());
template<class T, size_t N>
constexpr reverse_iterator<T*> rbegin(T (&array)[N]);
template<class T, size_t N>
constexpr reverse_iterator<T*> rend(T (&array)[N]);
template<class E>
constexpr reverse_iterator<const E*> rbegin(initializer_list<E>);
template<class E>
constexpr reverse_iterator<const E*> rend(initializer_list<E>);
template<class C>
constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));
template<class C>
constexpr auto cend(const C& c) -> decltype(std::rend(c));
}
......@@ -25,7 +25,7 @@
#include <vector>
// { dg-error "multiple inlined namespaces" "" { target *-*-* } 324 }
// { dg-error "multiple inlined namespaces" "" { target *-*-* } 332 }
// "template argument 1 is invalid"
// { dg-prune-output "tuple:993" }
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